mirror of
https://github.com/gin-gonic/gin.git
synced 2026-07-15 15:51:17 +08:00
Compare commits
2 Commits
81c4f96879
...
8f39ea663a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f39ea663a | ||
|
|
3af7291718 |
32
gin_test.go
32
gin_test.go
@ -1067,6 +1067,38 @@ 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() {
|
||||
_ = router.Routes()
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user