Process queue items by time window

This commit is contained in:
Manuel de Brito Fontes 2017-09-25 18:53:03 -03:00
parent 37262bda76
commit 768cbb89d6
4 changed files with 59 additions and 22 deletions

View file

@ -131,3 +131,29 @@ func TestEnqueueKeyError(t *testing.T) {
// shutdown queue before exit
q.Shutdown()
}
func TestSkipEnqueue(t *testing.T) {
// initialize result
atomic.StoreUint32(&sr, 0)
q := NewCustomTaskQueue(mockSynFn, mockKeyFn)
stopCh := make(chan struct{})
// run queue
go q.Run(time.Second, stopCh)
// mock object whichi will be enqueue
mo := mockEnqueueObj{
k: "testKey",
v: "testValue",
}
q.Enqueue(mo)
q.Enqueue(mo)
q.Enqueue(mo)
q.Enqueue(mo)
// wait for 'mockSynFn'
time.Sleep(time.Millisecond * 10)
if atomic.LoadUint32(&sr) != 1 {
t.Errorf("sr should be 1, but is %d", sr)
}
// shutdown queue before exit
q.Shutdown()
}