mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
common/daemon: test if sending SIGINT terminates the component
This commit is contained in:
@@ -5,8 +5,10 @@ package daemon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/synctest"
|
"testing/synctest"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/tomb.v2"
|
"gopkg.in/tomb.v2"
|
||||||
|
|
||||||
@@ -43,6 +45,23 @@ func TestTerminate(t *testing.T) {
|
|||||||
c.Terminate() // Can be called several times.
|
c.Terminate() // Can be called several times.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTerminateWithSignal(t *testing.T) {
|
||||||
|
r := reporter.NewMock(t)
|
||||||
|
c, err := New(r)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("New() error:\n%+v", err)
|
||||||
|
}
|
||||||
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
|
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
||||||
|
select {
|
||||||
|
case <-c.Terminated():
|
||||||
|
// OK
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Fatalf("Terminated() wasn't closed while we requested it to be")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStop(t *testing.T) {
|
func TestStop(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
r := reporter.NewMock(t)
|
||||||
c, err := New(r)
|
c, err := New(r)
|
||||||
|
|||||||
Reference in New Issue
Block a user