|
|
@ -47,8 +47,8 @@ func TestExpiryHeap(t *testing.T) {
|
|
|
|
testNoMessage(t, ch)
|
|
|
|
testNoMessage(t, ch)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
runStep(t, "update entry3 to expire first", func(t *testing.T) {
|
|
|
|
runStep(t, "update so that entry3 expires first", func(t *testing.T) {
|
|
|
|
h.Update(entry3.heapIndex, 10*time.Millisecond)
|
|
|
|
h.Update(entry.heapIndex, 2000*time.Millisecond)
|
|
|
|
assert.Equal(t, 1, entry.heapIndex)
|
|
|
|
assert.Equal(t, 1, entry.heapIndex)
|
|
|
|
assert.Equal(t, 0, entry3.heapIndex)
|
|
|
|
assert.Equal(t, 0, entry3.heapIndex)
|
|
|
|
testMessage(t, ch)
|
|
|
|
testMessage(t, ch)
|
|
|
@ -56,12 +56,19 @@ func TestExpiryHeap(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
runStep(t, "0th element change triggers a notify", func(t *testing.T) {
|
|
|
|
runStep(t, "0th element change triggers a notify", func(t *testing.T) {
|
|
|
|
h.Update(entry3.heapIndex, 20)
|
|
|
|
h.Update(entry3.heapIndex, 1500*time.Millisecond)
|
|
|
|
assert.Equal(t, 1, entry.heapIndex) // no move
|
|
|
|
assert.Equal(t, 1, entry.heapIndex) // no move
|
|
|
|
assert.Equal(t, 0, entry3.heapIndex)
|
|
|
|
assert.Equal(t, 0, entry3.heapIndex)
|
|
|
|
testMessage(t, ch)
|
|
|
|
testMessage(t, ch)
|
|
|
|
testNoMessage(t, ch) // one message
|
|
|
|
testNoMessage(t, ch) // one message
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runStep(t, "update can not decrease expiry time", func(t *testing.T) {
|
|
|
|
|
|
|
|
h.Update(entry.heapIndex, 100*time.Millisecond)
|
|
|
|
|
|
|
|
assert.Equal(t, 1, entry.heapIndex) // no move
|
|
|
|
|
|
|
|
assert.Equal(t, 0, entry3.heapIndex)
|
|
|
|
|
|
|
|
testNoMessage(t, ch) // no notify, because no change in the heap
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func testNoMessage(t *testing.T, ch <-chan struct{}) {
|
|
|
|
func testNoMessage(t *testing.T, ch <-chan struct{}) {
|
|
|
|