test for main terminated with signal

This commit is contained in:
Umputun
2018-05-22 23:16:17 -05:00
parent f1b22465b0
commit b0e2ff22c3
+13
View File
@@ -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{}