MCPcopy
hub / github.com/gin-gonic/gin / TestRaceParamsContextCopy

Function TestRaceParamsContextCopy

context_test.go:3066–3085  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3064}
3065
3066func TestRaceParamsContextCopy(t *testing.T) {
3067 DefaultWriter = os.Stdout
3068 router := Default()
3069 nameGroup := router.Group("/:name")
3070 var wg sync.WaitGroup
3071 wg.Add(2)
3072 {
3073 nameGroup.GET("/api", func(c *Context) {
3074 go func(c *Context, param string) {
3075 defer wg.Done()
3076 // First assert must be executed after the second request
3077 time.Sleep(50 * time.Millisecond)
3078 assert.Equal(t, c.Param("name"), param)
3079 }(c.Copy(), c.Param("name"))
3080 })
3081 }
3082 PerformRequest(router, http.MethodGet, "/name1/api")
3083 PerformRequest(router, http.MethodGet, "/name2/api")
3084 wg.Wait()
3085}
3086
3087func TestContextWithKeysMutex(t *testing.T) {
3088 c := &Context{}

Callers

nothing calls this directly

Calls 7

PerformRequestFunction · 0.85
DoneMethod · 0.80
ParamMethod · 0.80
CopyMethod · 0.80
DefaultFunction · 0.70
GroupMethod · 0.65
GETMethod · 0.65

Tested by

no test coverage detected