From a43efe04f0f95e16131d22c2491c23a2cf759f80 Mon Sep 17 00:00:00 2001 From: Sindy Li Date: Wed, 18 Dec 2024 01:05:05 -0800 Subject: [PATCH] Added a test --- .../internal/queue/blocking_queue_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/exporter/internal/queue/blocking_queue_test.go b/exporter/internal/queue/blocking_queue_test.go index 648b395302b..331ecffad46 100644 --- a/exporter/internal/queue/blocking_queue_test.go +++ b/exporter/internal/queue/blocking_queue_test.go @@ -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) }