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

Function TestConcurrentHandleContext

gin_integration_test.go:392–417  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

390}
391
392func 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()

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
HandleContextMethod · 0.80
DoneMethod · 0.80
GETMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected