diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/exec_ttl.php | 15 | ||||
-rw-r--r-- | tests/idle.php | 15 | ||||
-rw-r--r-- | tests/memleak.php | 2 | ||||
-rwxr-xr-x | tests/plugins/checker/configs/.rr-checker-init.yaml | 3 | ||||
-rw-r--r-- | tests/plugins/checker/plugin_test.go | 10 | ||||
-rw-r--r-- | tests/plugins/gzip/plugin_test.go | 4 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-http-supervised-pool.yaml | 2 | ||||
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 30 | ||||
-rw-r--r-- | tests/plugins/static/static_plugin_test.go | 71 | ||||
-rw-r--r-- | tests/sleep.php | 2 |
10 files changed, 71 insertions, 83 deletions
diff --git a/tests/exec_ttl.php b/tests/exec_ttl.php new file mode 100644 index 00000000..fb5c9df2 --- /dev/null +++ b/tests/exec_ttl.php @@ -0,0 +1,15 @@ +<?php + +declare(strict_types=1); + +use Spiral\Goridge\StreamRelay; +use Spiral\RoadRunner\Worker as RoadRunner; + +require __DIR__ . "/vendor/autoload.php"; + +$rr = new RoadRunner(new StreamRelay(\STDIN, \STDOUT)); + +while($rr->waitPayload()){ + sleep(3); + $rr->respond(new \Spiral\RoadRunner\Payload("")); +} diff --git a/tests/idle.php b/tests/idle.php new file mode 100644 index 00000000..fb5c9df2 --- /dev/null +++ b/tests/idle.php @@ -0,0 +1,15 @@ +<?php + +declare(strict_types=1); + +use Spiral\Goridge\StreamRelay; +use Spiral\RoadRunner\Worker as RoadRunner; + +require __DIR__ . "/vendor/autoload.php"; + +$rr = new RoadRunner(new StreamRelay(\STDIN, \STDOUT)); + +while($rr->waitPayload()){ + sleep(3); + $rr->respond(new \Spiral\RoadRunner\Payload("")); +} diff --git a/tests/memleak.php b/tests/memleak.php index f2879e18..96ed5006 100644 --- a/tests/memleak.php +++ b/tests/memleak.php @@ -10,6 +10,6 @@ require __DIR__ . "/vendor/autoload.php"; $rr = new RoadRunner(new StreamRelay(\STDIN, \STDOUT)); $mem = ''; while($rr->waitPayload()){ - $mem .= str_repeat("a", 1024*1024); + $mem .= str_repeat("a", 1024*1024*10); $rr->respond(new \Spiral\RoadRunner\Payload("")); } diff --git a/tests/plugins/checker/configs/.rr-checker-init.yaml b/tests/plugins/checker/configs/.rr-checker-init.yaml index 11804a21..dca86efe 100755 --- a/tests/plugins/checker/configs/.rr-checker-init.yaml +++ b/tests/plugins/checker/configs/.rr-checker-init.yaml @@ -5,13 +5,12 @@ server: command: "php ../../http/client.php echo pipes" user: "" group: "" - env: - "RR_HTTP": "true" relay: "pipes" relay_timeout: "20s" status: address: "127.0.0.1:34333" + logs: mode: development level: error diff --git a/tests/plugins/checker/plugin_test.go b/tests/plugins/checker/plugin_test.go index 5e391158..569e73a1 100644 --- a/tests/plugins/checker/plugin_test.go +++ b/tests/plugins/checker/plugin_test.go @@ -14,12 +14,12 @@ import ( endure "github.com/spiral/endure/pkg/container" goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc" - "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/spiral/roadrunner/v2/plugins/status" "github.com/stretchr/testify/assert" ) @@ -37,7 +37,7 @@ func TestStatusHttp(t *testing.T) { &logger.ZapLogger{}, &server.Plugin{}, &httpPlugin.Plugin{}, - &checker.Plugin{}, + &status.Plugin{}, ) assert.NoError(t, err) @@ -95,7 +95,7 @@ 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) + 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) @@ -124,7 +124,7 @@ func TestStatusRPC(t *testing.T) { &logger.ZapLogger{}, &server.Plugin{}, &httpPlugin.Plugin{}, - &checker.Plugin{}, + &status.Plugin{}, ) assert.NoError(t, err) @@ -182,7 +182,7 @@ func checkRPCStatus(t *testing.T) { assert.NoError(t, err) client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)) - st := &checker.Status{} + st := &status.Status{} err = client.Call("status.Status", "http", &st) assert.NoError(t, err) diff --git a/tests/plugins/gzip/plugin_test.go b/tests/plugins/gzip/plugin_test.go index 3e3db0f8..9a9c760b 100644 --- a/tests/plugins/gzip/plugin_test.go +++ b/tests/plugins/gzip/plugin_test.go @@ -34,7 +34,7 @@ func TestGzipPlugin(t *testing.T) { &logger.ZapLogger{}, &server.Plugin{}, &httpPlugin.Plugin{}, - &gzip.Gzip{}, + &gzip.Plugin{}, ) assert.NoError(t, err) @@ -126,7 +126,7 @@ func TestMiddlewareNotExist(t *testing.T) { mockLogger, &server.Plugin{}, &httpPlugin.Plugin{}, - &gzip.Gzip{}, + &gzip.Plugin{}, ) assert.NoError(t, err) diff --git a/tests/plugins/http/configs/.rr-http-supervised-pool.yaml b/tests/plugins/http/configs/.rr-http-supervised-pool.yaml index 3e392577..e92ce051 100644 --- a/tests/plugins/http/configs/.rr-http-supervised-pool.yaml +++ b/tests/plugins/http/configs/.rr-http-supervised-pool.yaml @@ -25,7 +25,7 @@ http: supervisor: watch_tick: 1s ttl: 0 - idle_ttl: 5s + idle_ttl: 1s exec_ttl: 10s max_worker_memory: 100 logs: diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index bca8a2f1..d55491ea 100644 --- a/tests/plugins/http/http_plugin_test.go +++ b/tests/plugins/http/http_plugin_test.go @@ -1028,7 +1028,7 @@ logs: mockLogger.EXPECT().Debug(gomock.Any()).AnyTimes() mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).MinTimes(1) - mockLogger.EXPECT().Debug("", "remote", gomock.Any(), "ts", gomock.Any(), "resp.status", gomock.Any(), "method", gomock.Any(), "uri", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Debug("201 GET http://localhost:34999/?hello=world", "remote", "127.0.0.1", "elapsed", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Debug("WORLD", "pid", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Debug("worker event received", "event", events.EventWorkerLog, "worker state", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Error(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() // placeholder for the workerlogerror @@ -1287,9 +1287,13 @@ func TestHTTPSupervisedPool(t *testing.T) { }() time.Sleep(time.Second * 1) - t.Run("HTTPEchoTest", echoHTTP2) + t.Run("HTTPEchoRunActivateWorker", echoHTTP2) + // bigger timeout to handle idle_ttl on slow systems + time.Sleep(time.Second * 10) + t.Run("HTTPInformerCompareWorkersTestBefore", informerTestBefore) + t.Run("HTTPEchoShouldBeNewWorker", echoHTTP2) // worker should be destructed (idle_ttl) - t.Run("HTTPInformerCompareWorkersTest", informerTest2) + t.Run("HTTPInformerCompareWorkersTestAfter", informerTestAfter) stopCh <- struct{}{} wg.Wait() @@ -1314,11 +1318,12 @@ func echoHTTP2(t *testing.T) { // sleep // supervisor destroy worker // compare pid's -func informerTest2(t *testing.T) { +var workerPid int = 0 + +func informerTestBefore(t *testing.T) { conn, err := net.Dial("tcp", "127.0.0.1:15432") assert.NoError(t, err) client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)) - pid := 0 // WorkerList contains list of workers. list := struct { // Workers is list of workers. @@ -1329,18 +1334,25 @@ func informerTest2(t *testing.T) { assert.NoError(t, err) assert.Len(t, list.Workers, 1) // save the pid - pid = list.Workers[0].Pid - time.Sleep(time.Second * 10) + workerPid = list.Workers[0].Pid +} - list = struct { +func informerTestAfter(t *testing.T) { + conn, err := net.Dial("tcp", "127.0.0.1:15432") + assert.NoError(t, err) + client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)) + // WorkerList contains list of workers. + list := struct { // Workers is list of workers. Workers []tools.ProcessState `json:"workers"` }{} + assert.NotZero(t, workerPid) + err = client.Call("informer.Workers", "http", &list) assert.NoError(t, err) assert.Len(t, list.Workers, 1) - assert.NotEqual(t, list.Workers[0].Pid, pid) + assert.NotEqual(t, workerPid, list.Workers[0].Pid) } func get(url string) (string, *http.Response, error) { diff --git a/tests/plugins/static/static_plugin_test.go b/tests/plugins/static/static_plugin_test.go index d43ef765..38562537 100644 --- a/tests/plugins/static/static_plugin_test.go +++ b/tests/plugins/static/static_plugin_test.go @@ -38,7 +38,7 @@ func TestStaticPlugin(t *testing.T) { &logger.ZapLogger{}, &server.Plugin{}, &httpPlugin.Plugin{}, - &gzip.Gzip{}, + &gzip.Plugin{}, &static.Plugin{}, ) assert.NoError(t, err) @@ -138,7 +138,7 @@ func serveStaticSample(t *testing.T) { _ = r.Body.Close() } -func TestStaticDisabled(t *testing.T) { +func TestStaticDisabled_Error(t *testing.T) { cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) assert.NoError(t, err) @@ -152,66 +152,11 @@ func TestStaticDisabled(t *testing.T) { &logger.ZapLogger{}, &server.Plugin{}, &httpPlugin.Plugin{}, - &gzip.Gzip{}, + &gzip.Plugin{}, &static.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("StaticDisabled", staticDisabled) - - stopCh <- struct{}{} - wg.Wait() -} - -func staticDisabled(t *testing.T) { - _, r, err := get("http://localhost:21234/sample.txt") //nolint:bodyclose - assert.NoError(t, err) - assert.NotNil(t, r) - assert.Empty(t, r.Header.Get("X-Powered-By")) + assert.Error(t, cont.Init()) } func TestStaticFilesDisabled(t *testing.T) { @@ -228,7 +173,7 @@ func TestStaticFilesDisabled(t *testing.T) { &logger.ZapLogger{}, &server.Plugin{}, &httpPlugin.Plugin{}, - &gzip.Gzip{}, + &gzip.Plugin{}, &static.Plugin{}, ) assert.NoError(t, err) @@ -306,7 +251,9 @@ func TestStaticFilesForbid(t *testing.T) { mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).AnyTimes() mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).AnyTimes() - mockLogger.EXPECT().Debug("", "remote", gomock.Any(), "ts", gomock.Any(), "resp.status", gomock.Any(), "method", gomock.Any(), "uri", gomock.Any()).AnyTimes() + mockLogger.EXPECT().Debug("201 GET http://localhost:34653/http?hello=world", "remote", "127.0.0.1", "elapsed", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Debug("201 GET http://localhost:34653/client.XXX?hello=world", "remote", "127.0.0.1", "elapsed", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Debug("201 GET http://localhost:34653/client.php?hello=world", "remote", "127.0.0.1", "elapsed", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Error("file open error", "error", gomock.Any()).AnyTimes() mockLogger.EXPECT().Error(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() // placeholder for the workerlogerror @@ -315,7 +262,7 @@ func TestStaticFilesForbid(t *testing.T) { mockLogger, &server.Plugin{}, &httpPlugin.Plugin{}, - &gzip.Gzip{}, + &gzip.Plugin{}, &static.Plugin{}, ) assert.NoError(t, err) diff --git a/tests/sleep.php b/tests/sleep.php index fb5c9df2..d36ae3e3 100644 --- a/tests/sleep.php +++ b/tests/sleep.php @@ -10,6 +10,6 @@ require __DIR__ . "/vendor/autoload.php"; $rr = new RoadRunner(new StreamRelay(\STDIN, \STDOUT)); while($rr->waitPayload()){ - sleep(3); + sleep(300); $rr->respond(new \Spiral\RoadRunner\Payload("")); } |