aboutsummaryrefslogtreecommitdiff
path: root/http_test.go
diff options
context:
space:
mode:
authorGravatar kinggo <lilong.21@bytedance.com> 2023-01-14 10:44:11 +0800
committerGravatar GitHub <noreply@github.com> 2023-01-14 10:44:11 +0800
commite87f84c51aad6a56cfebeff2d566de907bf73b7d (patch)
tree7f7dd943729d7772822d28ca97aff5b5849c9f13 /http_test.go
parentchore: Update README.md (#1470) (diff)
downloadfasthttp-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.go32
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))
+ }
+ }
+}