summaryrefslogtreecommitdiff
path: root/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins')
-rw-r--r--tests/plugins/http/configs/.rr-issue659.yaml22
-rw-r--r--tests/plugins/http/handler_test.go7
-rw-r--r--tests/plugins/http/http_plugin_test.go86
3 files changed, 111 insertions, 4 deletions
diff --git a/tests/plugins/http/configs/.rr-issue659.yaml b/tests/plugins/http/configs/.rr-issue659.yaml
new file mode 100644
index 00000000..6e0584a5
--- /dev/null
+++ b/tests/plugins/http/configs/.rr-issue659.yaml
@@ -0,0 +1,22 @@
+rpc:
+ listen: tcp://127.0.0.1:6001
+
+server:
+ command: "php ../../issue659.php"
+ relay: "pipes"
+ relay_timeout: "20s"
+
+http:
+ address: 127.0.0.1:32552
+ 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
+
+logs:
+ mode: development
+ level: debug
+
diff --git a/tests/plugins/http/handler_test.go b/tests/plugins/http/handler_test.go
index f6533dc4..1b7f5bac 100644
--- a/tests/plugins/http/handler_test.go
+++ b/tests/plugins/http/handler_test.go
@@ -1357,7 +1357,7 @@ func TestHandler_Error3(t *testing.T) {
}()
assert.NoError(t, err)
- assert.Equal(t, 500, r.StatusCode)
+ assert.Equal(t, 400, r.StatusCode)
}
func TestHandler_ResponseDuration(t *testing.T) {
@@ -1519,12 +1519,12 @@ func TestHandler_ErrorDuration(t *testing.T) {
}()
time.Sleep(time.Millisecond * 10)
- goterr := make(chan interface{})
+ goterr := make(chan struct{}, 10)
h.AddListener(func(event interface{}) {
switch tp := event.(type) {
case handler.ErrorEvent:
if tp.Elapsed() > 0 {
- close(goterr)
+ goterr <- struct{}{}
}
default:
}
@@ -1537,6 +1537,7 @@ func TestHandler_ErrorDuration(t *testing.T) {
}()
<-goterr
+ <-goterr
assert.Equal(t, 500, r.StatusCode)
}
diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go
index 128eec26..f8044c97 100644
--- a/tests/plugins/http/http_plugin_test.go
+++ b/tests/plugins/http/http_plugin_test.go
@@ -1557,7 +1557,7 @@ func bigEchoHTTP(t *testing.T) {
assert.NoError(t, err)
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
- assert.Equal(t, 500, r.StatusCode)
+ assert.Equal(t, 400, r.StatusCode)
assert.Equal(t, "http_handler_max_size: request body max size is exceeded\n", string(b))
err = r.Body.Close()
@@ -2130,6 +2130,90 @@ func staticFilesForbid(t *testing.T) {
_ = r.Body.Close()
}
+func TestHTTPIssue659(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-issue659.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.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("HTTPIssue659", echoIssue659)
+
+ stopCh <- struct{}{}
+
+ wg.Wait()
+}
+
+func echoIssue659(t *testing.T) {
+ req, err := http.NewRequest(http.MethodGet, "http://localhost:32552", 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.Empty(t, b)
+ assert.Equal(t, 500, r.StatusCode)
+
+ err = r.Body.Close()
+ assert.NoError(t, err)
+}
+
// HELPERS
func get(url string) (string, *http.Response, error) {
r, err := http.Get(url) //nolint:gosec