github.com/shuguocloud/go-zero@v1.3.0/core/proc/shutdown_test.go (about)

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