Browse Source

add more tests for proc (#439)

Kevin Wan 4 years ago
parent
commit
d04b54243d
2 changed files with 36 additions and 0 deletions
  1. 28 0
      core/proc/shutdown_test.go
  2. 8 0
      core/proc/stopper_test.go

+ 28 - 0
core/proc/shutdown_test.go

@@ -0,0 +1,28 @@
+package proc
+
+import (
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestShutdown(t *testing.T) {
+	SetTimeToForceQuit(time.Hour)
+	assert.Equal(t, time.Hour, delayTimeBeforeForceQuit)
+
+	var val int
+	called := AddWrapUpListener(func() {
+		val++
+	})
+	wrapUpListeners.notifyListeners()
+	called()
+	assert.Equal(t, 1, val)
+
+	called = AddShutdownListener(func() {
+		val += 2
+	})
+	shutdownListeners.notifyListeners()
+	called()
+	assert.Equal(t, 3, val)
+}

+ 8 - 0
core/proc/stopper_test.go

@@ -0,0 +1,8 @@
+package proc
+
+import "testing"
+
+func TestNopStopper(t *testing.T) {
+	// no panic
+	noopStopper.Stop()
+}