Skip to content

Commit

Permalink
Added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-sili committed Dec 18, 2024
1 parent bcd3fe8 commit a43efe0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions exporter/internal/queue/blocking_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,34 @@
package queue

import (
"context"
"errors"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestBlockingMemoryQueue(t *testing.T) {
q := NewBlockingMemoryQueue[string](BlockingMemoryQueueSettings[string]{Sizer: &RequestSizer[string]{}, Capacity: 1})

done := false
err := errors.New("This is an error")
go func() {
require.EqualError(t, q.Offer(context.Background(), "a"), err.Error())
done = true
}()

require.False(t, done)
index, ctx, req, ok := q.Read(context.Background())
require.Equal(t, index, uint64(0))
require.Equal(t, ctx, context.Background())
require.Equal(t, req, "a")
require.True(t, ok)

require.False(t, done)
q.OnProcessingFinished(index, err)

time.Sleep(100 * time.Millisecond)
require.True(t, done)
}

0 comments on commit a43efe0

Please sign in to comment.