MCPcopy Create free account
hub / github.com/beeker1121/goque / TestPriorityQueueClose

Function TestPriorityQueueClose

priority_queue_test.go:11–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestPriorityQueueClose(t *testing.T) {
12 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
13 pq, err := OpenPriorityQueue(file, ASC)
14 if err != nil {
15 t.Error(err)
16 }
17 defer pq.Drop()
18
19 for p := 0; p <= 4; p++ {
20 for i := 1; i <= 10; i++ {
21 if _, err = pq.EnqueueString(uint8(p), fmt.Sprintf("value for item %d", i)); err != nil {
22 t.Error(err)
23 }
24 }
25 }
26
27 if pq.Length() != 50 {
28 t.Errorf("Expected queue length of 1, got %d", pq.Length())
29 }
30
31 pq.Close()
32
33 if _, err = pq.Dequeue(); err != ErrDBClosed {
34 t.Errorf("Expected to get database closed error, got %s", err.Error())
35 }
36
37 if pq.Length() != 0 {
38 t.Errorf("Expected queue length of 0, got %d", pq.Length())
39 }
40}
41
42func TestPriorityQueueDrop(t *testing.T) {
43 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 6

OpenPriorityQueueFunction · 0.85
DropMethod · 0.45
EnqueueStringMethod · 0.45
LengthMethod · 0.45
CloseMethod · 0.45
DequeueMethod · 0.45

Tested by

no test coverage detected