summaryrefslogtreecommitdiff
path: root/tests/plugins/http
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-25 14:50:21 +0300
committerValery Piashchynski <[email protected]>2021-01-25 14:50:21 +0300
commitbb9e34db0f96295c5c2104262f43a3ab0edbc060 (patch)
treea9b0b99a36b796fdeaac130c9330de10aa4d5c0e /tests/plugins/http
parent709f7223fca5e60793ad9b3192f92a554854d6ee (diff)
Add new Supervisor test in the http plugin
Uniform supervisor config keys to use same notation as pool (10s, 10h not just 10)
Diffstat (limited to 'tests/plugins/http')
-rw-r--r--tests/plugins/http/configs/.rr-fcgi-reqUri.yaml2
-rw-r--r--tests/plugins/http/configs/.rr-fcgi.yaml2
-rw-r--r--tests/plugins/http/configs/.rr-http-supervised-pool.yaml33
-rw-r--r--tests/plugins/http/configs/.rr-init.yaml2
-rw-r--r--tests/plugins/http/handler_test.go2
-rw-r--r--tests/plugins/http/http_plugin_test.go119
6 files changed, 156 insertions, 4 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 {