buger / goreplay

GoReplay is an open-source tool for capturing and replaying live HTTP traffic into a test environment in order to continuously test your system with real data. It can be used to increase confidence in code deployments, configuration changes and infrastructure changes.
https://goreplay.org
Other
18.55k stars 13 forks source link

Misbehaving tests #62

Closed dcarley closed 10 years ago

dcarley commented 10 years ago

I don't think the output_http test, and possibly others that use test_input, are behaving correctly. It seems that most of the time only a single POST request is received. But the number of GET requests pads out to match the WaitGroup.

This can be easily observed with the following diff:

diff --git a/output_http_test.go b/output_http_test.go
index 7c9d977..d7581d3 100644
--- a/output_http_test.go
+++ b/output_http_test.go
@@ -24,11 +24,13 @@ func TestHTTPOutput(t *testing.T) {
        headers := HTTPHeaders{HTTPHeader{"User-Agent", "Gor"}}
        output := NewHTTPOutput("127.0.0.1:50003", headers, "")

+       Settings.verbose = true
        startHTTP("127.0.0.1:50003", func(req *http.Request) {
                if req.Header.Get("User-Agent") != "Gor" {
                        t.Error("Wrong header")
                }

+               t.Log(req)
                wg.Done()
        })

@@ -37,7 +39,7 @@ func TestHTTPOutput(t *testing.T) {

        go Start(quit)

-       for i := 0; i < 100; i++ {
+       for i := 0; i < 3; i++ {
                wg.Add(2)
                input.EmitGET()
                input.EmitPOST()

Which shows 3x POST requests going in, but only one coming out:

➜  gor git:(master) ✗ go test -run TestHTTPOutput -v
warning: building out-of-date packages:
        github.com/mattbaird/elastigo/api
        github.com/araddon/gou
        github.com/mattbaird/elastigo/core
        github.com/buger/gor/elasticsearch
        github.com/buger/gor/raw_socket_listener
installing these packages with 'go test -i' will speed future tests.

=== RUN TestHTTPOutput
2013/11/26 13:19:54 Sending Test Input :  GET / HTTP/1.1

2013/11/26 13:19:54 Sending Test Input :  POST /pub/WWW/ HTTP/1.1
Host: www.w3.org

a=1&b=2

2013/11/26 13:19:54 Sending Test Input :  GET / HTTP/1.1

2013/11/26 13:19:54 Sending Test Input :  POST /pub/WWW/ HTTP/1.1
Host: www.w3.org

a=1&b=2

2013/11/26 13:19:54 Sending Test Input :  GET / HTTP/1.1

2013/11/26 13:19:54 Sending Test Input :  POST /pub/WWW/ HTTP/1.1
Host: www.w3.org

a=1&b=2

--- PASS: TestHTTPOutput (0.00 seconds)
        output_http_test.go:34: &{GET / HTTP/1.1 1 1 map[User-Agent:[Gor] Accept-Encoding:[gzip]] 0xc200120240 0 [] false 127.0.0.1:50003 map[] map[] <nil> map[] 127.0.0.1:55277 / <nil>}
        output_http_test.go:34: &{GET / HTTP/1.1 1 1 map[User-Agent:[Gor] Accept-Encoding:[gzip]] 0xc200120380 0 [] false 127.0.0.1:50003 map[] map[] <nil> map[] 127.0.0.1:55278 / <nil>}
        output_http_test.go:34: &{GET / HTTP/1.1 1 1 map[User-Agent:[Gor] Accept-Encoding:[gzip]] 0xc200120600 0 [] false 127.0.0.1:50003 map[] map[] <nil> map[] 127.0.0.1:55279 / <nil>}
        output_http_test.go:34: &{GET / HTTP/1.1 1 1 map[User-Agent:[Gor] Accept-Encoding:[gzip]] 0xc2001206c0 0 [] false 127.0.0.1:50003 map[] map[] <nil> map[] 127.0.0.1:55280 / <nil>}
        output_http_test.go:34: &{GET / HTTP/1.1 1 1 map[User-Agent:[Gor] Accept-Encoding:[gzip]] 0xc200120780 0 [] false 127.0.0.1:50003 map[] map[] <nil> map[] 127.0.0.1:55281 / <nil>}
        output_http_test.go:34: &{POST /pub/WWW/ HTTP/1.1 1 1 map[User-Agent:[Gor] Content-Length:[0] Accept-Encoding:[gzip]] 0xc200120840 0 [] false www.w3.org map[] map[] <nil> map[] 127.0.0.1:55282 /pub/WWW/ <nil>}
PASS
ok      _/Users/dcarley/projects/govuk/gor      0.036s

Occasionally it also appears to truncate the POST request. Which can be easily observed by switching the order:

diff --git a/output_http_test.go b/output_http_test.go
index 7c9d977..0169321 100644
--- a/output_http_test.go
+++ b/output_http_test.go
@@ -37,10 +37,10 @@ func TestHTTPOutput(t *testing.T) {

        go Start(quit)

-       for i := 0; i < 100; i++ {
+       for i := 0; i < 3; i++ {
                wg.Add(2)
-               input.EmitGET()
                input.EmitPOST()
+               input.EmitGET()
        }

        wg.Wait()

Causing a parse error and the WaitGroup hangs:

➜  gor git:(master) ✗ go test -run TestHTTPOutput -v
warning: building out-of-date packages:
        github.com/mattbaird/elastigo/api
        github.com/araddon/gou
        github.com/mattbaird/elastigo/core
        github.com/buger/gor/elasticsearch
        github.com/buger/gor/raw_socket_listener
installing these packages with 'go test -i' will speed future tests.

=== RUN TestHTTPOutput
2013/11/26 13:27:45 Can not parse request POST /pub/WWW/ HTT malformed HTTP version "HTT"
2013/11/26 13:27:45 Can not parse request POST /pub/WWW/ HTT malformed HTTP version "HTT"
dcarley commented 10 years ago

@buger @slawosz any idea what's going on here? Dodgy pointer?

buger commented 10 years ago

Dcarly i got very busy week, will try to check on weekends. Sorry :(

dcarley commented 10 years ago

No probs.