queue_test.go 735 B

12345678910111213141516171819202122232425262728293031323334
  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. package write
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestQueue(t *testing.T) {
  10. que := newQueue(2)
  11. assert.True(t, que.isEmpty())
  12. assert.Nil(t, que.first())
  13. assert.Nil(t, que.pop())
  14. b := &Batch{Batch: "batch", RetryAttempts: 3}
  15. que.push(b)
  16. assert.False(t, que.isEmpty())
  17. b2 := que.pop()
  18. assert.Equal(t, b, b2)
  19. assert.True(t, que.isEmpty())
  20. que.push(b)
  21. que.push(b)
  22. assert.True(t, que.push(b))
  23. assert.False(t, que.isEmpty())
  24. que.pop()
  25. que.pop()
  26. assert.True(t, que.isEmpty())
  27. assert.Nil(t, que.pop())
  28. assert.True(t, que.isEmpty())
  29. }