diff options
Diffstat (limited to 'tests/plugins')
-rw-r--r-- | tests/plugins/http/configs/.rr-fcgi-reqUri.yaml | 2 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-fcgi.yaml | 2 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-http-supervised-pool.yaml | 33 | ||||
-rw-r--r-- | tests/plugins/http/configs/.rr-init.yaml | 2 | ||||
-rw-r--r-- | tests/plugins/http/handler_test.go | 2 | ||||
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 119 | ||||
-rw-r--r-- | tests/plugins/informer/test_plugin.go | 8 | ||||
-rw-r--r-- | tests/plugins/resetter/test_plugin.go | 8 | ||||
-rw-r--r-- | tests/plugins/server/plugin_pipes.go | 8 |
9 files changed, 168 insertions, 16 deletions
diff --git a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml index 55b2857d..ab42f4fc 100644 --- a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml +++ b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml @@ -26,7 +26,7 @@ http: redirect: false cert: fixtures/server.crt key: fixtures/server.key - # rootCa: root.crt + # root_ca: root.crt fcgi: address: tcp://127.0.0.1:6921 http2: diff --git a/tests/plugins/http/configs/.rr-fcgi.yaml b/tests/plugins/http/configs/.rr-fcgi.yaml index 483da057..bd5d01bd 100644 --- a/tests/plugins/http/configs/.rr-fcgi.yaml +++ b/tests/plugins/http/configs/.rr-fcgi.yaml @@ -26,7 +26,7 @@ http: redirect: false cert: fixtures/server.crt key: fixtures/server.key - # rootCa: root.crt + # root_ca: root.crt fcgi: address: tcp://0.0.0.0:6920 http2: diff --git a/tests/plugins/http/configs/.rr-http-supervised-pool.yaml b/tests/plugins/http/configs/.rr-http-supervised-pool.yaml new file mode 100644 index 00000000..3e392577 --- /dev/null +++ b/tests/plugins/http/configs/.rr-http-supervised-pool.yaml @@ -0,0 +1,33 @@ +rpc: + listen: tcp://127.0.0.1:15432 +server: + command: "php ../../http/client.php echo pipes" + user: "" + group: "" + env: + "RR_HTTP": "true" + relay: "pipes" + relay_timeout: "20s" + +http: + debug: true + address: 127.0.0.1:18888 + 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 + supervisor: + watch_tick: 1s + ttl: 0 + idle_ttl: 5s + exec_ttl: 10s + max_worker_memory: 100 +logs: + mode: development + level: error
\ No newline at end of file diff --git a/tests/plugins/http/configs/.rr-init.yaml b/tests/plugins/http/configs/.rr-init.yaml index 9b7d65c3..77132b43 100644 --- a/tests/plugins/http/configs/.rr-init.yaml +++ b/tests/plugins/http/configs/.rr-init.yaml @@ -29,7 +29,7 @@ http: redirect: false cert: fixtures/server.crt key: fixtures/server.key - # rootCa: root.crt + # root_ca: root.crt fcgi: address: tcp://0.0.0.0:7921 http2: diff --git a/tests/plugins/http/handler_test.go b/tests/plugins/http/handler_test.go index 45931a49..e47dbd44 100644 --- a/tests/plugins/http/handler_test.go +++ b/tests/plugins/http/handler_test.go @@ -1800,7 +1800,7 @@ func BenchmarkHandler_Listen_Echo(b *testing.B) { func() *exec.Cmd { return exec.Command("php", "../../http/client.php", "echo", "pipes") }, pipe.NewPipeFactory(), pool.Config{ - NumWorkers: int64(runtime.NumCPU()), + NumWorkers: uint64(runtime.NumCPU()), AllocateTimeout: time.Second * 1000, DestroyTimeout: time.Second * 1000, }) diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index 26b28165..4f99dbbb 100644 --- a/tests/plugins/http/http_plugin_test.go +++ b/tests/plugins/http/http_plugin_test.go @@ -1221,6 +1221,125 @@ func TestHttpBrokenPipes(t *testing.T) { assert.Error(t, err) } +func TestHTTPSupervisedPool(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-http-supervised-pool.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &server.Plugin{}, + &httpPlugin.Plugin{}, + &informer.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 * 1) + t.Run("HTTPEchoTest", echoHTTP2) + // worker should be destructed (idle_ttl) + t.Run("HTTPInformerCompareWorkersTest", informerTest2) + + stopCh <- struct{}{} + wg.Wait() +} + +func echoHTTP2(t *testing.T) { + req, err := http.NewRequest("GET", "http://localhost:18888?hello=world", 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, 201, r.StatusCode) + assert.Equal(t, "WORLD", string(b)) + + err = r.Body.Close() + assert.NoError(t, err) +} + +// get worker +// sleep +// supervisor destroy worker +// compare pid's +func informerTest2(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. + Workers []tools.ProcessState `json:"workers"` + }{} + + err = client.Call("informer.Workers", "http", &list) + assert.NoError(t, err) + assert.Len(t, list.Workers, 1) + // save the pid + pid = list.Workers[0].Pid + time.Sleep(time.Second * 10) + + list = struct { + // Workers is list of workers. + Workers []tools.ProcessState `json:"workers"` + }{} + + 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) +} + func get(url string) (string, *http.Response, error) { r, err := http.Get(url) //nolint:gosec if err != nil { diff --git a/tests/plugins/informer/test_plugin.go b/tests/plugins/informer/test_plugin.go index 7436a7fb..2300de89 100644 --- a/tests/plugins/informer/test_plugin.go +++ b/tests/plugins/informer/test_plugin.go @@ -16,10 +16,10 @@ var testPoolConfig = pool.Config{ AllocateTimeout: time.Second * 10, DestroyTimeout: time.Second * 10, Supervisor: &pool.SupervisorConfig{ - WatchTick: 60, - TTL: 1000, - IdleTTL: 10, - ExecTTL: 10, + WatchTick: 60 * time.Second, + TTL: 1000 * time.Second, + IdleTTL: 10 * time.Second, + ExecTTL: 10 * time.Second, MaxWorkerMemory: 1000, }, } diff --git a/tests/plugins/resetter/test_plugin.go b/tests/plugins/resetter/test_plugin.go index 7d53bca0..61942516 100644 --- a/tests/plugins/resetter/test_plugin.go +++ b/tests/plugins/resetter/test_plugin.go @@ -15,10 +15,10 @@ var testPoolConfig = poolImpl.Config{ AllocateTimeout: time.Second * 10, DestroyTimeout: time.Second * 10, Supervisor: &poolImpl.SupervisorConfig{ - WatchTick: 60, - TTL: 1000, - IdleTTL: 10, - ExecTTL: 10, + WatchTick: 60 * time.Second, + TTL: 1000 * time.Second, + IdleTTL: 10 * time.Second, + ExecTTL: 10 * time.Second, MaxWorkerMemory: 1000, }, } diff --git a/tests/plugins/server/plugin_pipes.go b/tests/plugins/server/plugin_pipes.go index 5b2cdd96..af34b4d3 100644 --- a/tests/plugins/server/plugin_pipes.go +++ b/tests/plugins/server/plugin_pipes.go @@ -21,10 +21,10 @@ var testPoolConfig = pool.Config{ AllocateTimeout: time.Second * 10, DestroyTimeout: time.Second * 10, Supervisor: &pool.SupervisorConfig{ - WatchTick: 60, - TTL: 1000, - IdleTTL: 10, - ExecTTL: 10, + WatchTick: 60 * time.Second, + TTL: 1000 * time.Second, + IdleTTL: 10 * time.Second, + ExecTTL: 10 * time.Second, MaxWorkerMemory: 1000, }, } |