summaryrefslogtreecommitdiff
path: root/plugins/checker/tests/plugin_test.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-21 19:42:23 +0300
committerValery Piashchynski <[email protected]>2020-12-21 19:42:23 +0300
commitee8b4075c0f836d698d1ae505c87c17147de447a (patch)
tree531d980e5bfb94ee39b03952a97e0445f7955409 /plugins/checker/tests/plugin_test.go
parent0ad45031047bb479e06ce0a0f496c6db9b2641c9 (diff)
Move plugins to the roadrunner-plugins repository
Diffstat (limited to 'plugins/checker/tests/plugin_test.go')
-rw-r--r--plugins/checker/tests/plugin_test.go188
1 files changed, 0 insertions, 188 deletions
diff --git a/plugins/checker/tests/plugin_test.go b/plugins/checker/tests/plugin_test.go
deleted file mode 100644
index 38b751ff..00000000
--- a/plugins/checker/tests/plugin_test.go
+++ /dev/null
@@ -1,188 +0,0 @@
-package tests
-
-import (
- "io/ioutil"
- "net"
- "net/http"
- "net/rpc"
- "os"
- "os/signal"
- "sync"
- "syscall"
- "testing"
- "time"
-
- "github.com/spiral/endure"
- goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
- "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 TestStatusHttp(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
- assert.NoError(t, err)
-
- cfg := &config.Viper{
- Path: "configs/.rr-checker-init.yaml",
- Prefix: "rr",
- }
-
- err = cont.RegisterAll(
- cfg,
- &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("CheckerGetStatus", checkHTTPStatus)
- wg.Wait()
-}
-
-const resp = `Service: http: Status: 200
-Service: rpc not found`
-
-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)
-
- r, err := http.DefaultClient.Do(req)
- assert.NoError(t, err)
- b, err := ioutil.ReadAll(r.Body)
- assert.NoError(t, err)
- assert.Equal(t, 200, r.StatusCode)
- assert.Equal(t, resp, string(b))
-
- err = r.Body.Close()
- assert.NoError(t, err)
-}
-
-func TestStatusRPC(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
- 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(goridgeRpc.NewClientCodec(conn))
-
- st := &status.Status{}
-
- err = client.Call("status.Status", "http", &st)
- assert.NoError(t, err)
- assert.Equal(t, st.Code, 200)
-}