2022-02-05 00:06:23 +08:00
|
|
|
//go:build linux || darwin
|
|
|
|
|
2021-02-05 15:11:27 +08:00
|
|
|
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++
|
|
|
|
})
|
2023-01-24 13:43:13 +08:00
|
|
|
WrapUp()
|
2021-02-05 15:11:27 +08:00
|
|
|
called()
|
|
|
|
assert.Equal(t, 1, val)
|
|
|
|
|
|
|
|
called = AddShutdownListener(func() {
|
|
|
|
val += 2
|
|
|
|
})
|
2023-01-24 13:43:13 +08:00
|
|
|
Shutdown()
|
2021-02-05 15:11:27 +08:00
|
|
|
called()
|
|
|
|
assert.Equal(t, 3, val)
|
|
|
|
}
|