Skip to content

Commit

Permalink
Modify test to work with low resolution timer.
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
  • Loading branch information
pstibrany committed Jun 17, 2022
1 parent eb9a028 commit 5198a92
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tsdb/chunks/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func TestQueuePushBlocksOnFullQueue(t *testing.T) {
require.True(t, queue.push(chunkWriteJob{seriesRef: 3}))
require.True(t, queue.push(chunkWriteJob{seriesRef: 4}))
require.True(t, queue.push(chunkWriteJob{seriesRef: 5}))
// This will block
pushTime <- time.Now()
// This will block
require.True(t, queue.push(chunkWriteJob{seriesRef: 6}))
pushTime <- time.Now()
}()

before := <-pushTime
timeBeforePush := <-pushTime

delay := 100 * time.Millisecond
select {
Expand All @@ -145,10 +145,10 @@ func TestQueuePushBlocksOnFullQueue(t *testing.T) {
require.True(t, b)
require.Equal(t, HeadSeriesRef(1), j.seriesRef)

after := <-pushTime
timeAfterPush := <-pushTime

require.True(t, after.After(popTime))
require.True(t, after.Sub(before) > delay)
require.GreaterOrEqual(t, timeAfterPush.Sub(popTime), time.Duration(0))
require.GreaterOrEqual(t, timeAfterPush.Sub(timeBeforePush), delay)
}

func TestQueuePopBlocksOnEmptyQueue(t *testing.T) {
Expand All @@ -172,7 +172,7 @@ func TestQueuePopBlocksOnEmptyQueue(t *testing.T) {

queue.push(chunkWriteJob{seriesRef: 1})

before := <-popTime
timeBeforePop := <-popTime

delay := 100 * time.Millisecond
select {
Expand All @@ -185,10 +185,10 @@ func TestQueuePopBlocksOnEmptyQueue(t *testing.T) {
pushTime := time.Now()
require.True(t, queue.push(chunkWriteJob{seriesRef: 2}))

after := <-popTime
timeAfterPop := <-popTime

require.True(t, after.After(pushTime))
require.True(t, after.Sub(before) > delay)
require.GreaterOrEqual(t, timeAfterPop.Sub(pushTime), time.Duration(0))
require.Greater(t, timeAfterPop.Sub(timeBeforePop), delay)
}

func TestQueuePopUnblocksOnClose(t *testing.T) {
Expand All @@ -211,7 +211,7 @@ func TestQueuePopUnblocksOnClose(t *testing.T) {

queue.push(chunkWriteJob{seriesRef: 1})

before := <-popTime
timeBeforePop := <-popTime

delay := 100 * time.Millisecond
select {
Expand All @@ -224,10 +224,10 @@ func TestQueuePopUnblocksOnClose(t *testing.T) {
closeTime := time.Now()
queue.close()

after := <-popTime
timeAfterPop := <-popTime

require.True(t, after.After(closeTime))
require.True(t, after.Sub(before) > delay)
require.GreaterOrEqual(t, timeAfterPop.Sub(closeTime), time.Duration(0))
require.GreaterOrEqual(t, timeAfterPop.Sub(timeBeforePop), delay)
}

func TestQueuePopAfterCloseReturnsAllElements(t *testing.T) {
Expand Down

0 comments on commit 5198a92

Please sign in to comment.