server_unix_test.go 656 B

1234567891011121314151617181920212223242526272829
  1. //go:build !windows && !plan9 && !js
  2. package daemon
  3. import (
  4. "os"
  5. "syscall"
  6. "testing"
  7. )
  8. func TestProgram_QuitsOnSystemSignal_SIGINT(t *testing.T) {
  9. testProgram_QuitsOnSystemSignal(t, syscall.SIGINT)
  10. }
  11. func TestProgram_QuitsOnSystemSignal_SIGTERM(t *testing.T) {
  12. testProgram_QuitsOnSystemSignal(t, syscall.SIGTERM)
  13. }
  14. func testProgram_QuitsOnSystemSignal(t *testing.T, sig os.Signal) {
  15. t.Helper()
  16. setup(t)
  17. startServerOpts(t, cli("sock", "db"), ServeOpts{Signals: nil})
  18. p, err := os.FindProcess(os.Getpid())
  19. if err != nil {
  20. t.Fatalf("FindProcess: %v", err)
  21. }
  22. p.Signal(sig)
  23. // startServerOpts will wait for server to terminate at cleanup
  24. }