Process queue items by time window
This commit is contained in:
parent
37262bda76
commit
768cbb89d6
4 changed files with 59 additions and 22 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue