Skip to content

Commit

Permalink
test: remove unused race test & fix a ut
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever committed Aug 28, 2023
1 parent eb9ecb2 commit ed2d9c6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
47 changes: 0 additions & 47 deletions pkg/protocol/http1/req/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,42 +456,6 @@ func TestCopyRequestPostArgsBodyStream(t *testing.T) {
assert.Nil(t, err)
}

func TestRequestPostArgsBodyStreamRace(t *testing.T) {
var req protocol.Request
s := "POST / HTTP/1.1\r\nHost: aaa.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 8196\r\n\r\n"
contentB := make([]byte, 8192)
for i := 0; i < len(contentB); i++ {
contentB[i] = 'a'
}
content := string(contentB)
body := url.Values{"key": []string{content}}.Encode()
requestString := s + body

zr := mock.NewOneTimeConn(requestString)
if err := ReadHeader(&req.Header, zr); err != nil {
t.Fatalf("Unexpected error when reading header %q: %s", s, err)
}

err := ReadBodyStream(&req, zr, 1024*4, false, false)
if err != nil {
t.Fatalf("Unexpected error when reading bodystream %q: %s", s, err)
}

errG := errgroup.Group{}

for i := 0; i < 500; i++ {
errG.Go(func() error {
if string(req.PostArgs().Peek("key")) != content {
return errors.New("race error happened")
}
return nil
})
}

err = errG.Wait()
assert.DeepEqual(t, "race error happened", err.Error())
}

func testRequestWriteError(t *testing.T, method, requestURI, host, userAgent, body string) {
var req protocol.Request

Expand Down Expand Up @@ -1565,17 +1529,6 @@ Content-Type: application/octet-stream
assert.Nil(t, err)

r.RemoveMultipartFormFiles()

eg = errgroup.Group{}
for i := 0; i < 500; i++ {
eg.Go(func() error {
return testCopyRequestReadMultipartForm(t, &r)
})
}
err = eg.Wait()
assert.NotNil(t, err)

r.RemoveMultipartFormFiles()
}

func testCopyRequestReadMultipartForm(t *testing.T, r *protocol.Request) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/multipart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestWriteMultipartFormFile(t *testing.T) {
assert.True(t, strings.Contains(bodyBuffer.String(), string(buf1)))

// test file not found
assert.NotNil(t, WriteMultipartFormFile(w, multipartFile.ParamName, "test.go", multipartFile.Reader))
assert.Nil(t, WriteMultipartFormFile(w, multipartFile.ParamName, "test.go", multipartFile.Reader))

// Test Add File Function
err = AddFile(w, "responseCode", "./response.go")
Expand Down

0 comments on commit ed2d9c6

Please sign in to comment.