-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue_test.go
More file actions
50 lines (38 loc) · 773 Bytes
/
queue_test.go
File metadata and controls
50 lines (38 loc) · 773 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
44
45
46
47
48
49
50
package crawler
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestInMemoryQueue(t *testing.T) {
r := require.New(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
q := NewInMemoryQueue(ctx)
var (
req *Request
err error
)
err = q.PushBack(&Request{depth: 1})
r.NoError(err)
req, err = q.PopFront()
r.NoError(err)
r.Equal(1, req.depth)
err = q.PushBack(&Request{depth: 2})
r.NoError(err)
req.Finish()
err = q.PushBack(&Request{depth: 3})
r.NoError(err)
req, err = q.PopFront()
r.NoError(err)
r.Equal(2, req.depth)
req.Finish()
req, err = q.PopFront()
r.NoError(err)
r.Equal(3, req.depth)
req.Finish()
req, err = q.PopFront()
r.NoError(err)
r.Nil(req)
}