@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/golang-queue/queue"
13
13
"github.com/golang-queue/queue/core"
14
+ "github.com/golang-queue/queue/job"
14
15
15
16
"github.com/stretchr/testify/assert"
16
17
"go.uber.org/goleak"
@@ -124,7 +125,7 @@ func TestJobReachTimeout(t *testing.T) {
124
125
assert .NoError (t , err )
125
126
q .Start ()
126
127
time .Sleep (50 * time .Millisecond )
127
- assert .NoError (t , q .QueueWithTimeout ( 20 * time .Millisecond , m ))
128
+ assert .NoError (t , q .Queue ( m , job . WithTimeout ( 20 * time .Millisecond ) ))
128
129
time .Sleep (100 * time .Millisecond )
129
130
q .Shutdown ()
130
131
q .Wait ()
@@ -161,7 +162,7 @@ func TestCancelJobAfterShutdown(t *testing.T) {
161
162
assert .NoError (t , err )
162
163
q .Start ()
163
164
time .Sleep (50 * time .Millisecond )
164
- assert .NoError (t , q .QueueWithTimeout ( 150 * time .Millisecond , m ))
165
+ assert .NoError (t , q .Queue ( m , job . WithTimeout ( 150 * time .Millisecond ) ))
165
166
time .Sleep (100 * time .Millisecond )
166
167
q .Shutdown ()
167
168
q .Wait ()
@@ -237,84 +238,3 @@ func TestGoroutinePanic(t *testing.T) {
237
238
assert .Error (t , q .Queue (m ))
238
239
q .Wait ()
239
240
}
240
-
241
- func TestHandleTimeout (t * testing.T ) {
242
- job := & queue.Job {
243
- Timeout : 100 * time .Millisecond ,
244
- Payload : []byte ("foo" ),
245
- }
246
- w := NewWorker (
247
- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
248
- time .Sleep (200 * time .Millisecond )
249
- return nil
250
- }),
251
- )
252
-
253
- err := w .handle (job )
254
- assert .Error (t , err )
255
- assert .Equal (t , context .DeadlineExceeded , err )
256
- assert .NoError (t , w .Shutdown ())
257
-
258
- job = & queue.Job {
259
- Timeout : 150 * time .Millisecond ,
260
- Payload : []byte ("foo" ),
261
- }
262
-
263
- w = NewWorker (
264
- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
265
- time .Sleep (200 * time .Millisecond )
266
- return nil
267
- }),
268
- )
269
-
270
- done := make (chan error )
271
- go func () {
272
- done <- w .handle (job )
273
- }()
274
-
275
- assert .NoError (t , w .Shutdown ())
276
-
277
- err = <- done
278
- assert .Error (t , err )
279
- assert .Equal (t , context .DeadlineExceeded , err )
280
- }
281
-
282
- func TestJobComplete (t * testing.T ) {
283
- job := & queue.Job {
284
- Timeout : 100 * time .Millisecond ,
285
- Payload : []byte ("foo" ),
286
- }
287
- w := NewWorker (
288
- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
289
- return errors .New ("job completed" )
290
- }),
291
- )
292
-
293
- err := w .handle (job )
294
- assert .Error (t , err )
295
- assert .Equal (t , errors .New ("job completed" ), err )
296
- assert .NoError (t , w .Shutdown ())
297
-
298
- job = & queue.Job {
299
- Timeout : 250 * time .Millisecond ,
300
- Payload : []byte ("foo" ),
301
- }
302
-
303
- w = NewWorker (
304
- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
305
- time .Sleep (200 * time .Millisecond )
306
- return errors .New ("job completed" )
307
- }),
308
- )
309
-
310
- done := make (chan error )
311
- go func () {
312
- done <- w .handle (job )
313
- }()
314
-
315
- assert .NoError (t , w .Shutdown ())
316
-
317
- err = <- done
318
- assert .Error (t , err )
319
- assert .Equal (t , errors .New ("job completed" ), err )
320
- }
0 commit comments