github.com/sunvim/utils@v0.1.0/grace/service_test.go (about)

     1  package grace
     2  
     3  import (
     4  	"context"
     5  	"log"
     6  	"syscall"
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  func TestWait(t *testing.T) {
    12  	_, service := New(context.Background())
    13  	service.Register(func() error {
    14  		log.Println("exit 1")
    15  		return nil
    16  	})
    17  	service.Register(func() error {
    18  		log.Println("exit 2")
    19  		return nil
    20  	})
    21  	go func() {
    22  		time.Sleep(10 * time.Second)
    23  		syscall.Kill(syscall.Getpid(), syscall.SIGINT)
    24  	}()
    25  	service.Wait()
    26  }