diff options
author | kinggo <lilong.21@bytedance.com> | 2023-01-14 10:44:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 10:44:11 +0800 |
commit | e87f84c51aad6a56cfebeff2d566de907bf73b7d (patch) | |
tree | 7f7dd943729d7772822d28ca97aff5b5849c9f13 /http_test.go | |
parent | chore: Update README.md (#1470) (diff) | |
download | fasthttp-e87f84c51aad6a56cfebeff2d566de907bf73b7d.tar.gz fasthttp-e87f84c51aad6a56cfebeff2d566de907bf73b7d.tar.bz2 fasthttp-e87f84c51aad6a56cfebeff2d566de907bf73b7d.zip |
fix: CopyTo doesn't copy bodyraw deeply (#1471)
Diffstat (limited to 'http_test.go')
-rw-r--r-- | http_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/http_test.go b/http_test.go index 52d8a67..ba5d675 100644 --- a/http_test.go +++ b/http_test.go @@ -3033,3 +3033,35 @@ func testRequestMultipartFormPipeEmptyFormField(t *testing.T, boundary string, f return req.Body() } + +func TestReqCopeToRace(t *testing.T) { + req := AcquireRequest() + reqs := make([]*Request, 1000) + for i := 0; i < 1000; i++ { + req.SetBodyRaw([]byte(strconv.Itoa(i))) + tmpReq := AcquireRequest() + req.CopyTo(tmpReq) + reqs[i] = tmpReq + } + for i := 0; i < 1000; i++ { + if strconv.Itoa(i) != string(reqs[i].Body()) { + t.Fatalf("Unexpected req body %s. Expected %s", string(reqs[i].Body()), strconv.Itoa(i)) + } + } +} + +func TestRespCopeToRace(t *testing.T) { + resp := AcquireResponse() + resps := make([]*Response, 1000) + for i := 0; i < 1000; i++ { + resp.SetBodyRaw([]byte(strconv.Itoa(i))) + tmpResq := AcquireResponse() + resp.CopyTo(tmpResq) + resps[i] = tmpResq + } + for i := 0; i < 1000; i++ { + if strconv.Itoa(i) != string(resps[i].Body()) { + t.Fatalf("Unexpected resp body %s. Expected %s", string(resps[i].Body()), strconv.Itoa(i)) + } + } +} |