-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue_test.go
More file actions
43 lines (38 loc) · 882 Bytes
/
queue_test.go
File metadata and controls
43 lines (38 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package taskq_test
import (
"context"
"testing"
"github.com/antonmashko/taskq"
)
func TestBlockingQueueEnqueueOK(t *testing.T) {
q := taskq.NewConcurrentQueue()
for i := 0; i < 10; i++ {
q.Enqueue(context.Background(), &testTask{})
}
if q.Len(context.Background()) != 10 {
t.Fail()
}
}
func TestBlockingQueueDequeueOK(t *testing.T) {
q := taskq.NewConcurrentQueue()
var result int
t1 := taskq.TaskFunc(func(ctx context.Context) error {
result++
return nil
})
_, err := q.Enqueue(context.Background(), t1)
if err != nil {
t.Fatal("failed to enqueue. err=", err)
}
t2, err := q.Dequeue(context.Background())
if err != nil {
t.Fatal("failed to dequeue. err=", err)
}
err = t2.Do(context.Background())
if err != nil || result != 1 {
t.Fail()
}
}
func TestTaskqQueueImplementation(t *testing.T) {
var _ taskq.Queue = taskq.NewConcurrentQueue()
}