@@ -12,12 +12,13 @@ import (
12
12
"github.com/golang-queue/queue"
13
13
"github.com/golang-queue/queue/core"
14
14
"github.com/golang-queue/queue/job"
15
+ "github.com/nats-io/nats.go"
15
16
16
17
"github.com/stretchr/testify/assert"
17
18
"go.uber.org/goleak"
18
19
)
19
20
20
- var host = "127.0.0.1"
21
+ var host = nats . DefaultURL
21
22
22
23
func TestMain (m * testing.M ) {
23
24
goleak .VerifyTestMain (m )
@@ -36,7 +37,28 @@ func TestDefaultFlow(t *testing.T) {
36
37
Message : "foo" ,
37
38
}
38
39
w := NewWorker (
39
- WithAddr (host + ":4222" ),
40
+ WithAddr (host ),
41
+ WithSubj ("test" ),
42
+ WithQueue ("test" ),
43
+ )
44
+ q , err := queue .NewQueue (
45
+ queue .WithWorker (w ),
46
+ queue .WithWorkerCount (1 ),
47
+ )
48
+ assert .NoError (t , err )
49
+ assert .NoError (t , q .Queue (m ))
50
+ assert .NoError (t , q .Queue (m ))
51
+ q .Start ()
52
+ time .Sleep (500 * time .Millisecond )
53
+ q .Release ()
54
+ }
55
+
56
+ func TestClusteredHost (t * testing.T ) {
57
+ m := & mockMessage {
58
+ Message : "foo" ,
59
+ }
60
+ w := NewWorker (
61
+ WithAddr (host , "nats://localhost:4223" ),
40
62
WithSubj ("test" ),
41
63
WithQueue ("test" ),
42
64
)
@@ -54,7 +76,7 @@ func TestDefaultFlow(t *testing.T) {
54
76
55
77
func TestShutdown (t * testing.T ) {
56
78
w := NewWorker (
57
- WithAddr (host + ":4222" ),
79
+ WithAddr (host ),
58
80
WithSubj ("test" ),
59
81
WithQueue ("test" ),
60
82
)
@@ -76,7 +98,7 @@ func TestCustomFuncAndWait(t *testing.T) {
76
98
Message : "foo" ,
77
99
}
78
100
w := NewWorker (
79
- WithAddr (host + ":4222" ),
101
+ WithAddr (host ),
80
102
WithSubj ("test" ),
81
103
WithQueue ("test" ),
82
104
WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
@@ -107,7 +129,7 @@ func TestEnqueueJobAfterShutdown(t *testing.T) {
107
129
Message : "foo" ,
108
130
}
109
131
w := NewWorker (
110
- WithAddr (host + ":4222" ),
132
+ WithAddr (host ),
111
133
)
112
134
q , err := queue .NewQueue (
113
135
queue .WithWorker (w ),
@@ -129,7 +151,7 @@ func TestJobReachTimeout(t *testing.T) {
129
151
Message : "foo" ,
130
152
}
131
153
w := NewWorker (
132
- WithAddr (host + ":4222" ),
154
+ WithAddr (host ),
133
155
WithSubj ("JobReachTimeout" ),
134
156
WithQueue ("test" ),
135
157
WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
@@ -167,7 +189,7 @@ func TestCancelJobAfterShutdown(t *testing.T) {
167
189
Message : "test" ,
168
190
}
169
191
w := NewWorker (
170
- WithAddr (host + ":4222" ),
192
+ WithAddr (host ),
171
193
WithSubj ("CancelJob" ),
172
194
WithQueue ("test" ),
173
195
WithLogger (queue .NewLogger ()),
@@ -206,7 +228,7 @@ func TestGoroutineLeak(t *testing.T) {
206
228
Message : "foo" ,
207
229
}
208
230
w := NewWorker (
209
- WithAddr (host + ":4222" ),
231
+ WithAddr (host ),
210
232
WithSubj ("GoroutineLeak" ),
211
233
WithQueue ("test" ),
212
234
WithLogger (queue .NewEmptyLogger ()),
@@ -252,7 +274,7 @@ func TestGoroutinePanic(t *testing.T) {
252
274
Message : "foo" ,
253
275
}
254
276
w := NewWorker (
255
- WithAddr (host + ":4222" ),
277
+ WithAddr (host ),
256
278
WithSubj ("GoroutinePanic" ),
257
279
WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
258
280
panic ("missing something" )
@@ -278,7 +300,7 @@ func TestReQueueTaskInWorkerBeforeShutdown(t *testing.T) {
278
300
Payload : []byte ("foo" ),
279
301
}
280
302
w := NewWorker (
281
- WithAddr (host + ":4222" ),
303
+ WithAddr (host ),
282
304
WithSubj ("test02" ),
283
305
WithQueue ("test02" ),
284
306
)
0 commit comments