From 4857f7c66ebfc1ed55f6cff157e89240c5a3e95f Mon Sep 17 00:00:00 2001 From: Saksham Arya Date: Wed, 20 Nov 2024 16:18:37 +0530 Subject: [PATCH] add test case fix lint --- context_test.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/context_test.go b/context_test.go index 5b63a647..b587177d 100644 --- a/context_test.go +++ b/context_test.go @@ -27,11 +27,12 @@ import ( "time" "github.com/gin-contrib/sse" - "github.com/gin-gonic/gin/binding" - testdata "github.com/gin-gonic/gin/testdata/protoexample" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" + + "github.com/gin-gonic/gin/binding" + testdata "github.com/gin-gonic/gin/testdata/protoexample" ) var _ context.Context = (*Context)(nil) @@ -166,7 +167,7 @@ func TestSaveUploadedFileWithPermission(t *testing.T) { require.NoError(t, err) mw.Close() c, _ := CreateTestContext(httptest.NewRecorder()) - c.Request, _ = http.NewRequest("POST", "/", buf) + c.Request, _ = http.NewRequest(http.MethodPost, "/", buf) c.Request.Header.Set("Content-Type", mw.FormDataContentType()) f, err := c.FormFile("file") require.NoError(t, err) @@ -187,7 +188,7 @@ func TestSaveUploadedFileWithPermissionFailed(t *testing.T) { require.NoError(t, err) mw.Close() c, _ := CreateTestContext(httptest.NewRecorder()) - c.Request, _ = http.NewRequest("POST", "/", buf) + c.Request, _ = http.NewRequest(http.MethodPost, "/", buf) c.Request.Header.Set("Content-Type", mw.FormDataContentType()) f, err := c.FormFile("file") require.NoError(t, err) @@ -3123,3 +3124,23 @@ func TestContextNext(t *testing.T) { assert.True(t, exists) assert.Equal(t, "value3", value) } + +func TestParallelHeaderWrite(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + wg := sync.WaitGroup{} + wg.Add(1) + go func() { + defer wg.Done() + for i := 0; i < 1000; i++ { + c.Header("key", "value") + } + }() + wg.Add(1) + go func() { + defer wg.Done() + for i := 0; i < 1000; i++ { + c.Header("key", "value") + } + }() + wg.Wait() +}