fix travis freeze on concurrent test (#1761)
This commit is contained in:
parent
d27685e714
commit
5acf660117
@ -188,15 +188,12 @@ func TestConcurrentHandleContext(t *testing.T) {
|
|||||||
})
|
})
|
||||||
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
||||||
|
|
||||||
ts := httptest.NewServer(router)
|
|
||||||
defer ts.Close()
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
iterations := 200
|
iterations := 200
|
||||||
wg.Add(iterations)
|
wg.Add(iterations)
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
testRequest(t, ts.URL+"/")
|
testGetRequestHandler(t, router, "/")
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -217,3 +214,14 @@ func TestConcurrentHandleContext(t *testing.T) {
|
|||||||
|
|
||||||
// testRequest(t, "http://localhost:8033/example")
|
// 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")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user