| 390 | } |
| 391 | |
| 392 | func TestConcurrentHandleContext(t *testing.T) { |
| 393 | router := New() |
| 394 | router.GET("/", func(c *Context) { |
| 395 | c.Request.URL.Path = "/example" |
| 396 | router.HandleContext(c) |
| 397 | }) |
| 398 | router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") }) |
| 399 | |
| 400 | var wg sync.WaitGroup |
| 401 | iterations := 200 |
| 402 | wg.Add(iterations) |
| 403 | for range iterations { |
| 404 | go func() { |
| 405 | req, err := http.NewRequest(http.MethodGet, "/", nil) |
| 406 | assert.NoError(t, err) |
| 407 | |
| 408 | w := httptest.NewRecorder() |
| 409 | router.ServeHTTP(w, req) |
| 410 | |
| 411 | assert.Equal(t, "it worked", w.Body.String(), "resp body should match") |
| 412 | assert.Equal(t, 200, w.Code, "should get a 200") |
| 413 | wg.Done() |
| 414 | }() |
| 415 | } |
| 416 | wg.Wait() |
| 417 | } |
| 418 | |
| 419 | // func TestWithHttptestWithSpecifiedPort(t *testing.T) { |
| 420 | // router := New() |