From a28451dc0cdd59265e3c2db3015d9dbde37262e0 Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Fri, 28 Jun 2019 09:19:14 +0200 Subject: [PATCH] Test Pause/Resume --- cncd/queue/fifo_test.go | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cncd/queue/fifo_test.go b/cncd/queue/fifo_test.go index a5642ba38e..2252bbb7f4 100644 --- a/cncd/queue/fifo_test.go +++ b/cncd/queue/fifo_test.go @@ -238,6 +238,52 @@ func TestFifoCancel(t *testing.T) { } } +func TestFifoPause(t *testing.T) { + task1 := &Task{ + ID: "1", + } + + q := New().(*fifo) + var wg sync.WaitGroup + wg.Add(1) + go func() { + _, _ = q.Poll(noContext, func(*Task) bool { return true }) + wg.Done() + }() + + + q.Pause() + t0 := time.Now() + q.Push(noContext, task1) + time.Sleep(20 * time.Millisecond) + q.Resume() + + wg.Wait() + t1 := time.Now() + + if t1.Sub(t0) < 20 * time.Millisecond { + t.Errorf("Should have waited til resume") + } + + q.Pause() + q.Push(noContext, task1) + q.Resume() + _, _ = q.Poll(noContext, func(*Task) bool { return true }) +} + +func TestFifoPauseResume(t *testing.T) { + task1 := &Task{ + ID: "1", + } + + q := New().(*fifo) + q.Pause() + q.Push(noContext, task1) + q.Resume() + + _, _ = q.Poll(noContext, func(*Task) bool { return true }) +} + func TestShouldRun(t *testing.T) { task := &Task{ ID: "2",