e2e/shutdown_test.go

v1.9.0
gitbay/e2e/shutdown_test.go history · blame · raw

34 lines · 975 bytes

 1package e2e
 2
 3import (
 4	"net/http"
 5	"syscall"
 6	"testing"
 7	"time"
 8)
 9
10// SIGTERM is how a deploy restarts the daemon. It used to be a plain
11// kill: no listener closed, no request or push allowed to finish. The
12// daemon now stops its listeners, drains, and exits 0 (#105).
13func TestServeStopsOnSIGTERM(t *testing.T) {
14	inst := startInstance(t)
15	if resp, err := http.Get(inst.base() + "/healthz"); err != nil || resp.StatusCode != 200 {
16		t.Fatalf("healthz before shutdown: %v", err)
17	}
18	if err := inst.proc.Process.Signal(syscall.SIGTERM); err != nil {
19		t.Fatal(err)
20	}
21	done := make(chan error, 1)
22	go func() { done <- inst.proc.Wait() }()
23	select {
24	case err := <-done:
25		if err != nil {
26			t.Fatalf("daemon did not exit cleanly on SIGTERM: %v", err)
27		}
28	case <-time.After(15 * time.Second):
29		t.Fatal("daemon still running 15s after SIGTERM")
30	}
31	if _, err := http.Get(inst.base() + "/healthz"); err == nil {
32		t.Fatal("http listener still answering after shutdown")
33	}
34}