Skip to content

Commit

Permalink
fix travis freeze on concurrent test (gin-gonic#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkd authored and thinkerou committed Feb 4, 2019
1 parent d27685e commit 5acf660
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gin_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,12 @@ func TestConcurrentHandleContext(t *testing.T) {
})
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })

ts := httptest.NewServer(router)
defer ts.Close()

var wg sync.WaitGroup
iterations := 200
wg.Add(iterations)
for i := 0; i < iterations; i++ {
go func() {
testRequest(t, ts.URL+"/")
testGetRequestHandler(t, router, "/")
wg.Done()
}()
}
Expand All @@ -217,3 +214,14 @@ func TestConcurrentHandleContext(t *testing.T) {

// testRequest(t, "http://localhost:8033/example")
// }

func testGetRequestHandler(t *testing.T, h http.Handler, url string) {
req, err := http.NewRequest("GET", url, nil)
assert.NoError(t, err)

w := httptest.NewRecorder()
h.ServeHTTP(w, req)

assert.Equal(t, "it worked", w.Body.String(), "resp body should match")
assert.Equal(t, 200, w.Code, "should get a 200")
}

0 comments on commit 5acf660

Please sign in to comment.