summaryrefslogtreecommitdiff
path: root/tests/plugins/status
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-09-16 21:46:50 +0300
committerGitHub <[email protected]>2021-09-16 21:46:50 +0300
commit3581b45f237a3f7aa29591ceb2bf6f4a4642a2f5 (patch)
treee723b19ec1ac16b7ccc7b3c2da69d4a416d63d81 /tests/plugins/status
parent337d292dd2d6ff0a555098b1970d8194d8df8bc2 (diff)
parent823d831b57b75f70c7c3bbbee355f2016633bb3b (diff)
[#803]: feat(plugins): move plugins to a separate repositoryv2.5.0-alpha.2
[#803]: feat(plugins): move plugins to a separate repository
Diffstat (limited to 'tests/plugins/status')
-rwxr-xr-xtests/plugins/status/configs/.rr-ready-init.yaml28
-rwxr-xr-xtests/plugins/status/configs/.rr-status-init.yaml28
-rw-r--r--tests/plugins/status/plugin_test.go388
3 files changed, 0 insertions, 444 deletions
diff --git a/tests/plugins/status/configs/.rr-ready-init.yaml b/tests/plugins/status/configs/.rr-ready-init.yaml
deleted file mode 100755
index da9e84c3..00000000
--- a/tests/plugins/status/configs/.rr-ready-init.yaml
+++ /dev/null
@@ -1,28 +0,0 @@
-rpc:
- listen: tcp://127.0.0.1:6007
-
-server:
- command: "php ../../sleep.php"
- user: ""
- group: ""
- relay: "pipes"
- relay_timeout: "20s"
-
-status:
- address: "127.0.0.1:34334"
-
-logs:
- mode: development
- level: error
-http:
- address: 127.0.0.1:11933
- max_request_size: 1024
- middleware: [ "" ]
- uploads:
- forbid: [ ".php", ".exe", ".bat" ]
- trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
- pool:
- num_workers: 1
- max_jobs: 0
- allocate_timeout: 60s
- destroy_timeout: 60s
diff --git a/tests/plugins/status/configs/.rr-status-init.yaml b/tests/plugins/status/configs/.rr-status-init.yaml
deleted file mode 100755
index c791c10f..00000000
--- a/tests/plugins/status/configs/.rr-status-init.yaml
+++ /dev/null
@@ -1,28 +0,0 @@
-rpc:
- listen: tcp://127.0.0.1:6005
-
-server:
- command: "php ../../http/client.php echo pipes"
- user: ""
- group: ""
- relay: "pipes"
- relay_timeout: "20s"
-
-status:
- address: "127.0.0.1:34333"
-
-logs:
- mode: development
- level: error
-http:
- address: 127.0.0.1:11933
- max_request_size: 1024
- middleware: [ "" ]
- uploads:
- forbid: [ ".php", ".exe", ".bat" ]
- trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
- pool:
- num_workers: 2
- max_jobs: 0
- allocate_timeout: 60s
- destroy_timeout: 60s \ No newline at end of file
diff --git a/tests/plugins/status/plugin_test.go b/tests/plugins/status/plugin_test.go
deleted file mode 100644
index 227cfd46..00000000
--- a/tests/plugins/status/plugin_test.go
+++ /dev/null
@@ -1,388 +0,0 @@
-package status
-
-import (
- "io/ioutil"
- "net"
- "net/http"
- "net/rpc"
- "os"
- "os/signal"
- "sync"
- "syscall"
- "testing"
- "time"
-
- endure "github.com/spiral/endure/pkg/container"
- goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
- "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/spiral/roadrunner/v2/plugins/status"
- "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-status-init.yaml",
- Prefix: "rr",
- }
-
- err = cont.RegisterAll(
- cfg,
- &logger.ZapLogger{},
- &server.Plugin{},
- &httpPlugin.Plugin{},
- &status.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)
-
- stopCh := make(chan struct{}, 1)
-
- 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 <-stopCh:
- // timeout
- err = cont.Stop()
- if err != nil {
- assert.FailNow(t, "error", err.Error())
- }
- return
- }
- }
- }()
-
- time.Sleep(time.Second)
- t.Run("CheckerGetStatus", checkHTTPStatus)
-
- stopCh <- struct{}{}
- 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/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-status-init.yaml",
- Prefix: "rr",
- }
-
- err = cont.RegisterAll(
- cfg,
- &rpcPlugin.Plugin{},
- &logger.ZapLogger{},
- &server.Plugin{},
- &httpPlugin.Plugin{},
- &status.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)
-
- stopCh := make(chan struct{}, 1)
-
- 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 <-stopCh:
- // timeout
- err = cont.Stop()
- if err != nil {
- assert.FailNow(t, "error", err.Error())
- }
- return
- }
- }
- }()
-
- time.Sleep(time.Second)
- t.Run("CheckerGetStatusRpc", checkRPCStatus)
- stopCh <- struct{}{}
- 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)
-}
-
-func TestReadyHttp(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
- assert.NoError(t, err)
-
- cfg := &config.Viper{
- Path: "configs/.rr-status-init.yaml",
- Prefix: "rr",
- }
-
- err = cont.RegisterAll(
- cfg,
- &logger.ZapLogger{},
- &server.Plugin{},
- &httpPlugin.Plugin{},
- &status.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)
-
- stopCh := make(chan struct{}, 1)
-
- 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 <-stopCh:
- // timeout
- err = cont.Stop()
- if err != nil {
- assert.FailNow(t, "error", err.Error())
- }
- return
- }
- }
- }()
-
- time.Sleep(time.Second)
- t.Run("CheckerGetReadiness", checkHTTPReadiness)
-
- stopCh <- struct{}{}
- wg.Wait()
-}
-
-const resp2 = `Service: http: Status: 204
-Service: rpc not found`
-
-func checkHTTPReadiness(t *testing.T) {
- req, err := http.NewRequest("GET", "http://127.0.0.1:34333/ready?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 TestReadinessRPCWorkerNotReady(t *testing.T) {
- cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel), endure.GracefulShutdownTimeout(time.Second*2))
- assert.NoError(t, err)
-
- cfg := &config.Viper{
- Path: "configs/.rr-ready-init.yaml",
- Prefix: "rr",
- }
-
- err = cont.RegisterAll(
- cfg,
- &rpcPlugin.Plugin{},
- &logger.ZapLogger{},
- &server.Plugin{},
- &httpPlugin.Plugin{},
- &status.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)
-
- stopCh := make(chan struct{}, 1)
-
- 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 <-stopCh:
- // timeout, error here is OK, because in the PHP we are sleeping for the 300s
- _ = cont.Stop()
- return
- }
- }
- }()
-
- time.Sleep(time.Second)
- t.Run("DoHttpReq", doHTTPReq)
- time.Sleep(time.Second * 5)
- t.Run("CheckerGetReadiness2", checkHTTPReadiness2)
- t.Run("CheckerGetRpcReadiness", checkRPCReadiness)
- stopCh <- struct{}{}
- wg.Wait()
-}
-
-func doHTTPReq(t *testing.T) {
- go func() {
- req, err := http.NewRequest("GET", "http://127.0.0.1:11933", 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, resp2, string(b))
-
- err = r.Body.Close()
- assert.NoError(t, err)
- }()
-}
-
-func checkHTTPReadiness2(t *testing.T) {
- req, err := http.NewRequest("GET", "http://127.0.0.1:34334/ready?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, 503, r.StatusCode)
- assert.Equal(t, "", string(b))
-
- err = r.Body.Close()
- assert.NoError(t, err)
-}
-
-func checkRPCReadiness(t *testing.T) {
- conn, err := net.Dial("tcp", "127.0.0.1:6007")
- assert.NoError(t, err)
- client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
-
- st := &status.Status{}
-
- err = client.Call("status.Ready", "http", &st)
- assert.NoError(t, err)
- assert.Equal(t, st.Code, 503)
-}