diff options
author | Valery Piashchynski <[email protected]> | 2020-11-13 16:29:08 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-11-13 16:29:08 +0300 |
commit | 6eefd067f4c08ed51834926abd1a4c60ec55b56d (patch) | |
tree | 5c4e3d3d930243f0c19083eff8bd5719ec266500 /plugins/metrics/tests/metrics_test.go | |
parent | 002eb4bb1981558fa5e614aed22d322f0f45d7ea (diff) |
Update tests
Diffstat (limited to 'plugins/metrics/tests/metrics_test.go')
-rw-r--r-- | plugins/metrics/tests/metrics_test.go | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/plugins/metrics/tests/metrics_test.go b/plugins/metrics/tests/metrics_test.go index d04c75d3..f21016d4 100644 --- a/plugins/metrics/tests/metrics_test.go +++ b/plugins/metrics/tests/metrics_test.go @@ -1,13 +1,18 @@ package tests import ( - "fmt" + "os" + "os/signal" + "syscall" "testing" + "time" "github.com/spiral/endure" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/logger" "github.com/spiral/roadrunner/v2/plugins/metrics" + "github.com/spiral/roadrunner/v2/plugins/rpc" + "github.com/stretchr/testify/assert" ) func TestMetricsInit(t *testing.T) { @@ -30,22 +35,54 @@ func TestMetricsInit(t *testing.T) { t.Fatal(err) } + err = cont.Register(&rpc.Plugin{}) + if err != nil { + t.Fatal(err) + } + err = cont.Register(&logger.ZapLogger{}) if err != nil { t.Fatal(err) } + err = cont.Register(&Plugin1{}) + if err != nil { + t.Fatal(err) + } err = cont.Init() if err != nil { t.Fatal(err) } - errCh, err := cont.Serve() + ch, err := cont.Serve() + assert.NoError(t, err) + + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + + tt := time.NewTimer(time.Second * 5) for { select { - case e := <-errCh: - fmt.Println(e) + case e := <-ch: + assert.Fail(t, "error", e.Error.Error()) + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + case <-sig: + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + case <-tt.C: + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return } } } |