mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 04:57:07 +08:00
refactor test case
This commit is contained in:
parent
cdaceb18a5
commit
312b621908
@ -3425,24 +3425,46 @@ func TestContextSetCookieData(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParallelHeaderWrite(t *testing.T) {
|
func TestParallelHeaderAccess(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
const iterations = 1000
|
||||||
|
const goroutines = 8
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
writerCount int
|
||||||
|
readerCount int
|
||||||
|
}{
|
||||||
|
{"parallel_write_only", goroutines, 0},
|
||||||
|
{"parallel_write_and_read", goroutines / 2, goroutines / 2},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||||
|
c.Request, _ = http.NewRequest(http.MethodGet, "/", nil)
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
for i := 0; i < tc.writerCount; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for i := 0; i < 1000; i++ {
|
for _ = range iterations {
|
||||||
c.Header("key", "value")
|
c.Header("key", "value")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
for i := 0; i < tc.readerCount; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for i := 0; i < 1000; i++ {
|
for _ = range iterations {
|
||||||
c.Header("key", "value")
|
_ = c.GetHeader("key")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMapFromFormData(t *testing.T) {
|
func TestGetMapFromFormData(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user