diff options
author | Valery Piashchynski <[email protected]> | 2020-12-03 14:18:18 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-03 14:18:18 +0300 |
commit | da583d684498f66944bd0ceaf96f5e96d965022b (patch) | |
tree | 5dca95ff156dedc9bc8bd327d6ebff1a68e3dbae /plugins | |
parent | c5aa774e5ad961929b4dfbe16f48a3747e2190a6 (diff) |
Apply linters fixes, add RPC status check test
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/checker/tests/configs/.rr-checker-init.yaml | 2 | ||||
-rw-r--r-- | plugins/checker/tests/plugin_test.go | 90 |
2 files changed, 88 insertions, 4 deletions
diff --git a/plugins/checker/tests/configs/.rr-checker-init.yaml b/plugins/checker/tests/configs/.rr-checker-init.yaml index 87e639ef..5943551b 100755 --- a/plugins/checker/tests/configs/.rr-checker-init.yaml +++ b/plugins/checker/tests/configs/.rr-checker-init.yaml @@ -1,5 +1,5 @@ rpc: - listen: tcp://127.0.0.1:6001 + listen: tcp://127.0.0.1:6005 disabled: false server: diff --git a/plugins/checker/tests/plugin_test.go b/plugins/checker/tests/plugin_test.go index 1cc1af47..c93b68af 100644 --- a/plugins/checker/tests/plugin_test.go +++ b/plugins/checker/tests/plugin_test.go @@ -2,7 +2,9 @@ package tests import ( "io/ioutil" + "net" "net/http" + "net/rpc" "os" "os/signal" "sync" @@ -11,15 +13,18 @@ import ( "time" "github.com/spiral/endure" + "github.com/spiral/goridge/v2" + "github.com/spiral/roadrunner/v2/interfaces/status" "github.com/spiral/roadrunner/v2/plugins/checker" "github.com/spiral/roadrunner/v2/plugins/config" httpPlugin "github.com/spiral/roadrunner/v2/plugins/http" "github.com/spiral/roadrunner/v2/plugins/logger" + rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc" "github.com/spiral/roadrunner/v2/plugins/server" "github.com/stretchr/testify/assert" ) -func TestStatusInit(t *testing.T) { +func TestStatusHttp(t *testing.T) { cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel)) assert.NoError(t, err) @@ -81,14 +86,14 @@ func TestStatusInit(t *testing.T) { }() time.Sleep(time.Second) - t.Run("CheckerGetStatus", checkHttpStatus) + t.Run("CheckerGetStatus", checkHTTPStatus) wg.Wait() } const resp = `Service: http: Status: 200 Service: rpc not found` -func checkHttpStatus(t *testing.T) { +func checkHTTPStatus(t *testing.T) { req, err := http.NewRequest("GET", "http://127.0.0.1:34333/v1/health?plugin=http&plugin=rpc", nil) assert.NoError(t, err) @@ -102,3 +107,82 @@ func checkHttpStatus(t *testing.T) { err = r.Body.Close() assert.NoError(t, err) } + +func TestStatusRPC(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-checker-init.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &server.Plugin{}, + &httpPlugin.Plugin{}, + &checker.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + assert.NoError(t, err) + + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + + wg := &sync.WaitGroup{} + wg.Add(1) + + tt := time.NewTimer(time.Second * 10) + + go func() { + defer wg.Done() + for { + select { + 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 + } + } + }() + + time.Sleep(time.Second) + t.Run("CheckerGetStatusRpc", checkRPCStatus) + wg.Wait() +} + +func checkRPCStatus(t *testing.T) { + conn, err := net.Dial("tcp", "127.0.0.1:6005") + assert.NoError(t, err) + client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn)) + + st := &status.Status{} + + err = client.Call("status.Status", "http", &st) + assert.NoError(t, err) + assert.Equal(t, st.Code, 200) +} |