1// Copyright 2020-2021 InfluxData, Inc. All rights reserved.
2// Use of this source code is governed by MIT
3// license that can be found in the LICENSE file.
4
5package write
6
7import (
8	"testing"
9
10	"github.com/stretchr/testify/assert"
11)
12
13func TestQueue(t *testing.T) {
14	que := newQueue(2)
15	assert.True(t, que.isEmpty())
16	assert.Nil(t, que.first())
17	assert.Nil(t, que.pop())
18	b := &Batch{Batch: "batch", RetryDelay: 3, RetryAttempts: 3}
19	que.push(b)
20	assert.False(t, que.isEmpty())
21	b2 := que.pop()
22	assert.Equal(t, b, b2)
23	assert.True(t, que.isEmpty())
24
25	que.push(b)
26	que.push(b)
27	assert.True(t, que.push(b))
28	assert.False(t, que.isEmpty())
29	que.pop()
30	que.pop()
31	assert.True(t, que.isEmpty())
32	assert.Nil(t, que.pop())
33	assert.True(t, que.isEmpty())
34}
35