From b0e2ff22c340e92b5657eb9270ee4aaed3d4c311 Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 22 May 2018 23:16:17 -0500 Subject: [PATCH] test for main terminated with signal --- app/main_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/main_test.go b/app/main_test.go index 85615b0e..75d3e6a9 100644 --- a/app/main_test.go +++ b/app/main_test.go @@ -6,6 +6,8 @@ import ( "io/ioutil" "log" "net/http" + "os" + "syscall" "testing" "time" @@ -38,6 +40,17 @@ func TestApplicationShutdown(t *testing.T) { app.Wait() } +func TestApplicationMainSignal(t *testing.T) { + os.Args = []string{"test", "--secret=123456", "--bolt=/tmp/xyz", "--backup=/tmp", "--avatars=/tmp", "--port=18100"} + go func() { + time.Sleep(100 * time.Millisecond) + syscall.Kill(syscall.Getpid(), syscall.SIGTERM) + }() + st := time.Now() + main() + assert.True(t, time.Since(st).Seconds() < 1, "should take about 500msec") +} + func prepApp(t *testing.T, port int, duration time.Duration) (*Application, context.Context) { // prepare options opts := Opts{}