func TestOnceWaiter(t *testing.T) { inCh := make(chan time.Time) now := time.Now() mtutils.WaitOnce(time.Second, func() { inCh <- time.Now() }) tm := <-inCh dur := tm.Sub(now) t.Log(dur) assert.Equal(t, dur/time.Second*time.Second, time.Second, "TestOnceWaiter") }
func TestTaskWaiterStop(t *testing.T) { inCh := make(chan int) wt := mtutils.WaitOnce(time.Second, func() { inCh <- 1 }) wt.Stop() select { case <-inCh: t.Fatal("WaiterTask.Stop() does not working") case <-time.After(time.Second * 2): } }