@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/golang-queue/queue"
1313 "github.com/golang-queue/queue/core"
14+ "github.com/golang-queue/queue/job"
1415
1516 "github.com/stretchr/testify/assert"
1617 "go.uber.org/goleak"
@@ -154,7 +155,7 @@ func TestJobReachTimeout(t *testing.T) {
154155 assert .NoError (t , err )
155156 q .Start ()
156157 time .Sleep (400 * time .Millisecond )
157- assert .NoError (t , q .QueueWithTimeout ( 20 * time .Millisecond , m ))
158+ assert .NoError (t , q .Queue ( m , job . WithTimeout ( 20 * time .Millisecond ) ))
158159 time .Sleep (2 * time .Second )
159160 q .Release ()
160161}
@@ -191,7 +192,7 @@ func TestCancelJobAfterShutdown(t *testing.T) {
191192 assert .NoError (t , err )
192193 q .Start ()
193194 time .Sleep (400 * time .Millisecond )
194- assert .NoError (t , q .QueueWithTimeout ( 3 * time .Second , m ))
195+ assert .NoError (t , q .Queue ( m , job . WithTimeout ( 3 * time .Second ) ))
195196 time .Sleep (2 * time .Second )
196197 q .Release ()
197198}
@@ -267,85 +268,6 @@ func TestGoroutinePanic(t *testing.T) {
267268 q .Wait ()
268269}
269270
270- func TestHandleTimeout (t * testing.T ) {
271- job := & queue.Job {
272- Timeout : 100 * time .Millisecond ,
273- Payload : []byte ("foo" ),
274- }
275- w := NewWorker (
276- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
277- time .Sleep (200 * time .Millisecond )
278- return nil
279- }),
280- )
281-
282- err := w .handle (job )
283- assert .Error (t , err )
284- assert .Equal (t , context .DeadlineExceeded , err )
285-
286- job = & queue.Job {
287- Timeout : 150 * time .Millisecond ,
288- Payload : []byte ("foo" ),
289- }
290-
291- w = NewWorker (
292- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
293- time .Sleep (200 * time .Millisecond )
294- return nil
295- }),
296- )
297-
298- done := make (chan error )
299- go func () {
300- done <- w .handle (job )
301- }()
302-
303- assert .NoError (t , w .Shutdown ())
304-
305- err = <- done
306- assert .Error (t , err )
307- assert .Equal (t , context .DeadlineExceeded , err )
308- }
309-
310- func TestJobComplete (t * testing.T ) {
311- job := & queue.Job {
312- Timeout : 100 * time .Millisecond ,
313- Payload : []byte ("foo" ),
314- }
315- w := NewWorker (
316- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
317- return errors .New ("job completed" )
318- }),
319- )
320-
321- err := w .handle (job )
322- assert .Error (t , err )
323- assert .Equal (t , errors .New ("job completed" ), err )
324-
325- job = & queue.Job {
326- Timeout : 250 * time .Millisecond ,
327- Payload : []byte ("foo" ),
328- }
329-
330- w = NewWorker (
331- WithRunFunc (func (ctx context.Context , m core.QueuedMessage ) error {
332- time .Sleep (200 * time .Millisecond )
333- return errors .New ("job completed" )
334- }),
335- )
336-
337- done := make (chan error )
338- go func () {
339- done <- w .handle (job )
340- }()
341-
342- assert .NoError (t , w .Shutdown ())
343-
344- err = <- done
345- assert .Error (t , err )
346- assert .Equal (t , errors .New ("job completed" ), err )
347- }
348-
349271func TestNSQStatsinQueue (t * testing.T ) {
350272 m := mockMessage {
351273 Message : "foo" ,
0 commit comments