From bfbe6a708fa02b79ed140bc8d1c0649f02927d0a Mon Sep 17 00:00:00 2001 From: Samuel Abreu Date: Sat, 13 Apr 2019 10:43:34 -0300 Subject: [PATCH] Using waitgroup to wait asynchronous test case --- context_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/context_test.go b/context_test.go index 1044265c..acbeb28e 100644 --- a/context_test.go +++ b/context_test.go @@ -16,6 +16,7 @@ import ( "os" "reflect" "strings" + "sync" "testing" "time" @@ -1818,15 +1819,19 @@ func TestRaceParamsContextCopy(t *testing.T) { DefaultWriter = os.Stdout router := Default() nameGroup := router.Group("/:name") + var wg sync.WaitGroup + wg.Add(2) { nameGroup.GET("/api", func(c *Context) { go func(c *Context, param string) { - time.Sleep(100 * time.Millisecond) + defer wg.Done() + // First assert must be executed after the second request + time.Sleep(50 * time.Millisecond) assert.Equal(t, c.Param("name"), param) }(c.Copy(), c.Param("name")) }) } performRequest(router, "GET", "/name1/api") performRequest(router, "GET", "/name2/api") - time.Sleep(200 * time.Millisecond) + wg.Wait() }