github.com/lingyao2333/mo-zero@v1.4.1/core/proc/shutdown_test.go (about)

     1  //go:build linux || darwin
     2  // +build linux darwin
     3  
     4  package proc
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestShutdown(t *testing.T) {
    14  	SetTimeToForceQuit(time.Hour)
    15  	assert.Equal(t, time.Hour, delayTimeBeforeForceQuit)
    16  
    17  	var val int
    18  	called := AddWrapUpListener(func() {
    19  		val++
    20  	})
    21  	wrapUpListeners.notifyListeners()
    22  	called()
    23  	assert.Equal(t, 1, val)
    24  
    25  	called = AddShutdownListener(func() {
    26  		val += 2
    27  	})
    28  	shutdownListeners.notifyListeners()
    29  	called()
    30  	assert.Equal(t, 3, val)
    31  }