diff --git a/context_test.go b/context_test.go index 41694585..cf12f508 100644 --- a/context_test.go +++ b/context_test.go @@ -1031,6 +1031,7 @@ func TestContextGetCookie(t *testing.T) { } func TestContextBodyAllowedForStatus(t *testing.T) { + assert.False(t, bodyAllowedForStatus(http.StatusContinue)) assert.False(t, bodyAllowedForStatus(http.StatusProcessing)) assert.False(t, bodyAllowedForStatus(http.StatusNoContent)) assert.False(t, bodyAllowedForStatus(http.StatusNotModified)) diff --git a/gin_test.go b/gin_test.go index 43c9494d..9480ff5e 100644 --- a/gin_test.go +++ b/gin_test.go @@ -1067,6 +1067,39 @@ func TestLiteralColonWithHTTPServer(t *testing.T) { assert.Contains(t, w2.Body.String(), "foo") } +func TestConcurrentAddRouteAndRoutes(t *testing.T) { + router := New() + + done := make(chan bool) + + for i := 0; i < 10; i++ { + go func(n int) { + router.GET(fmt.Sprintf("/route%d", n), func(c *Context) { + c.String(http.StatusOK, fmt.Sprintf("route%d", n)) + }) + router.POST(fmt.Sprintf("/route%d", n), func(c *Context) { + c.String(http.StatusOK, fmt.Sprintf("route%d", n)) + }) + done <- true + }(i) + } + + for i := 0; i < 10; i++ { + go func() { + routes := router.Routes() + assert.GreaterOrEqual(t, len(routes), 0) + done <- true + }() + } + + for i := 0; i < 20; i++ { + <-done + } + + routes := router.Routes() + assert.Len(t, routes, 20) +} + // Test that updateRouteTrees is called only once func TestUpdateRouteTreesCalledOnce(t *testing.T) { SetMode(TestMode)