github.com/sandwich-go/boost@v1.3.29/xsync/wg_test.go (about) 1 package xsync 2 3 import ( 4 "testing" 5 "time" 6 7 . "github.com/smartystreets/goconvey/convey" 8 ) 9 10 func TestWaitGroupWithoutTimeout(t *testing.T) { 11 var wg WaitGroupTimeout 12 wg.Add(1) 13 go func() { 14 time.Sleep(time.Second) 15 wg.Done() 16 }() 17 t0 := time.Now() 18 wg.Wait() 19 t.Logf("wait for %s", time.Since(t0)) 20 } 21 22 func TestWaitGroupWithTimeout(t *testing.T) { 23 Convey("wait group with timeout", t, func() { 24 var wg WaitGroupTimeout 25 wg.Add(1) 26 go func() { 27 time.Sleep(time.Second * 10) 28 wg.Done() 29 }() 30 t0 := time.Now() 31 tm := wg.WaitTimeout(time.Second) 32 So(tm, ShouldBeTrue) 33 t.Logf("wait for %s", time.Since(t0)) 34 }) 35 }