| 3064 | } |
| 3065 | |
| 3066 | func 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 | |
| 3087 | func TestContextWithKeysMutex(t *testing.T) { |
| 3088 | c := &Context{} |