-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue_test.go
98 lines (79 loc) · 2.01 KB
/
queue_test.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package qstash
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestQueue(t *testing.T) {
client := NewClientWithEnv()
name := "test-queue"
err := client.Queues().Upsert(Queue{
Name: name,
Parallelism: 1,
})
assert.NoError(t, err)
queue, err := client.Queues().Get(name)
assert.NoError(t, err)
assert.Equal(t, queue.Name, name)
assert.Equal(t, queue.Parallelism, 1)
// Reconfigure queue parallelism
err = client.Queues().Upsert(Queue{
Name: name,
Parallelism: 2,
})
assert.NoError(t, err)
queues, err := client.Queues().List()
assert.NoError(t, err)
assert.Len(t, queues, 1)
assert.Equal(t, queues[0].Name, name)
assert.Equal(t, queues[0].Parallelism, 2)
// Delete queue
err = client.Queues().Delete(name)
assert.NoError(t, err)
queues, err = client.Queues().List()
assert.NoError(t, err)
assert.Empty(t, queues)
}
func TestQueuePauseAndResume(t *testing.T) {
client := NewClientWithEnv()
name := "test-queue"
err := client.Queues().Upsert(Queue{
Name: name,
Parallelism: 1,
})
assert.NoError(t, err)
queue, err := client.Queues().Get(name)
assert.NoError(t, err)
assert.False(t, queue.IsPaused)
// Pause the queue
err = client.Queues().Pause(name)
assert.NoError(t, err)
queue, err = client.Queues().Get(name)
assert.NoError(t, err)
assert.True(t, queue.IsPaused)
// Resume the queue
err = client.Queues().Resume(name)
assert.NoError(t, err)
queue, err = client.Queues().Get(name)
assert.NoError(t, err)
assert.False(t, queue.IsPaused)
// Pause the queue with upsert
err = client.Queues().Upsert(Queue{
Name: name,
Parallelism: 1,
IsPaused: true,
})
assert.NoError(t, err)
queue, err = client.Queues().Get(name)
assert.NoError(t, err)
assert.True(t, queue.IsPaused)
// Resume the queue with upsert
err = client.Queues().Upsert(Queue{
Name: name,
Parallelism: 1,
IsPaused: false,
})
assert.NoError(t, err)
queue, err = client.Queues().Get(name)
assert.NoError(t, err)
assert.False(t, queue.IsPaused)
}