From d04b54243d19d48be4c9a47b8b1fad8a6b8d100c Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Fri, 5 Feb 2021 15:11:27 +0800 Subject: [PATCH] add more tests for proc (#439) --- core/proc/shutdown_test.go | 28 ++++++++++++++++++++++++++++ core/proc/stopper_test.go | 8 ++++++++ 2 files changed, 36 insertions(+) create mode 100644 core/proc/shutdown_test.go create mode 100644 core/proc/stopper_test.go diff --git a/core/proc/shutdown_test.go b/core/proc/shutdown_test.go new file mode 100644 index 00000000..3a0abcfd --- /dev/null +++ b/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) +} diff --git a/core/proc/stopper_test.go b/core/proc/stopper_test.go new file mode 100644 index 00000000..6b168efc --- /dev/null +++ b/core/proc/stopper_test.go @@ -0,0 +1,8 @@ +package proc + +import "testing" + +func TestNopStopper(t *testing.T) { + // no panic + noopStopper.Stop() +}