@@ -14,7 +14,6 @@ import (
14
14
"github.com/cschleiden/go-workflows/backend"
15
15
"github.com/cschleiden/go-workflows/core"
16
16
"github.com/cschleiden/go-workflows/workflow"
17
- "github.com/stretchr/testify/assert"
18
17
"github.com/stretchr/testify/mock"
19
18
"github.com/stretchr/testify/require"
20
19
)
@@ -173,17 +172,17 @@ func TestNewWorker(t *testing.T) {
173
172
174
173
worker := NewWorker (mockBackend , mockTaskWorker , options )
175
174
176
- assert .NotNil (t , worker )
177
- assert .Equal (t , mockTaskWorker , worker .tw )
178
- assert .Equal (t , options , worker .options )
179
- assert .NotNil (t , worker .taskQueue )
180
- assert .NotNil (t , worker .logger )
181
- assert .NotNil (t , worker .dispatcherDone )
175
+ require .NotNil (t , worker )
176
+ require .Equal (t , mockTaskWorker , worker .tw )
177
+ require .Equal (t , options , worker .options )
178
+ require .NotNil (t , worker .taskQueue )
179
+ require .NotNil (t , worker .logger )
180
+ require .NotNil (t , worker .dispatcherDone )
182
181
183
182
// Should add default queue if none provided
184
- assert .Contains (t , worker .options .Queues , workflow .QueueDefault )
183
+ require .Contains (t , worker .options .Queues , workflow .QueueDefault )
185
184
// Should always include system queue
186
- assert .Contains (t , worker .options .Queues , core .QueueSystem )
185
+ require .Contains (t , worker .options .Queues , core .QueueSystem )
187
186
})
188
187
189
188
t .Run ("with custom queues" , func (t * testing.T ) {
@@ -199,9 +198,9 @@ func TestNewWorker(t *testing.T) {
199
198
200
199
worker := NewWorker (mockBackend , mockTaskWorker , options )
201
200
202
- assert .Contains (t , worker .options .Queues , customQueue )
203
- assert .Contains (t , worker .options .Queues , core .QueueSystem )
204
- assert .Len (t , worker .options .Queues , 2 )
201
+ require .Contains (t , worker .options .Queues , customQueue )
202
+ require .Contains (t , worker .options .Queues , core .QueueSystem )
203
+ require .Len (t , worker .options .Queues , 2 )
205
204
})
206
205
207
206
t .Run ("system queue already included" , func (t * testing.T ) {
@@ -223,7 +222,7 @@ func TestNewWorker(t *testing.T) {
223
222
queueCount ++
224
223
}
225
224
}
226
- assert .Equal (t , 1 , queueCount )
225
+ require .Equal (t , 1 , queueCount )
227
226
})
228
227
}
229
228
@@ -253,7 +252,7 @@ func TestWorker_Start(t *testing.T) {
253
252
mockTaskWorker .On ("Get" , mock .Anything , mock .Anything ).Return (nil , nil )
254
253
255
254
err := worker .Start (ctx )
256
- assert .NoError (t , err )
255
+ require .NoError (t , err )
257
256
258
257
// Give pollers a moment to start
259
258
time .Sleep (10 * time .Millisecond )
@@ -263,7 +262,7 @@ func TestWorker_Start(t *testing.T) {
263
262
264
263
// Wait for completion
265
264
err = worker .WaitForCompletion ()
266
- assert .NoError (t , err )
265
+ require .NoError (t , err )
267
266
268
267
mockTaskWorker .AssertExpectations (t )
269
268
})
@@ -285,9 +284,9 @@ func TestWorker_Start(t *testing.T) {
285
284
mockTaskWorker .On ("Start" , ctx , mock .Anything ).Return (expectedErr )
286
285
287
286
err := worker .Start (ctx )
288
- assert .Error (t , err )
289
- assert .Contains (t , err .Error (), "starting task worker" )
290
- assert .Contains (t , err .Error (), expectedErr .Error ())
287
+ require .Error (t , err )
288
+ require .Contains (t , err .Error (), "starting task worker" )
289
+ require .Contains (t , err .Error (), expectedErr .Error ())
291
290
292
291
mockTaskWorker .AssertExpectations (t )
293
292
})
@@ -311,8 +310,8 @@ func TestWorker_Poll(t *testing.T) {
311
310
mockTaskWorker .On ("Get" , mock .Anything , mock .Anything ).Return (expectedTask , nil )
312
311
313
312
task , err := worker .poll (ctx , time .Second )
314
- assert .NoError (t , err )
315
- assert .Equal (t , expectedTask , task )
313
+ require .NoError (t , err )
314
+ require .Equal (t , expectedTask , task )
316
315
317
316
mockTaskWorker .AssertExpectations (t )
318
317
})
@@ -333,8 +332,8 @@ func TestWorker_Poll(t *testing.T) {
333
332
mockTaskWorker .On ("Get" , mock .Anything , mock .Anything ).Return (nil , context .DeadlineExceeded )
334
333
335
334
task , err := worker .poll (ctx , time .Millisecond )
336
- assert .NoError (t , err )
337
- assert .Nil (t , task )
335
+ require .NoError (t , err )
336
+ require .Nil (t , task )
338
337
339
338
mockTaskWorker .AssertExpectations (t )
340
339
})
@@ -356,9 +355,9 @@ func TestWorker_Poll(t *testing.T) {
356
355
mockTaskWorker .On ("Get" , mock .Anything , mock .Anything ).Return (nil , expectedErr )
357
356
358
357
task , err := worker .poll (ctx , time .Second )
359
- assert .Error (t , err )
360
- assert .Equal (t , expectedErr , err )
361
- assert .Nil (t , task )
358
+ require .Error (t , err )
359
+ require .Equal (t , expectedErr , err )
360
+ require .Nil (t , task )
362
361
363
362
mockTaskWorker .AssertExpectations (t )
364
363
})
@@ -380,8 +379,8 @@ func TestWorker_Poll(t *testing.T) {
380
379
381
380
// Pass 0 timeout to test default timeout behavior
382
381
task , err := worker .poll (ctx , 0 )
383
- assert .NoError (t , err )
384
- assert .Nil (t , task )
382
+ require .NoError (t , err )
383
+ require .Nil (t , task )
385
384
386
385
mockTaskWorker .AssertExpectations (t )
387
386
})
@@ -408,7 +407,7 @@ func TestWorker_Handle(t *testing.T) {
408
407
mockTaskWorker .On ("Complete" , mock .Anything , result , task ).Return (nil )
409
408
410
409
err := worker .handle (ctx , task )
411
- assert .NoError (t , err )
410
+ require .NoError (t , err )
412
411
413
412
mockTaskWorker .AssertExpectations (t )
414
413
})
@@ -435,7 +434,7 @@ func TestWorker_Handle(t *testing.T) {
435
434
mockTaskWorker .On ("Extend" , mock .Anything , task ).Return (nil ).Maybe ()
436
435
437
436
err := worker .handle (ctx , task )
438
- assert .NoError (t , err )
437
+ require .NoError (t , err )
439
438
440
439
mockTaskWorker .AssertExpectations (t )
441
440
})
@@ -458,9 +457,9 @@ func TestWorker_Handle(t *testing.T) {
458
457
mockTaskWorker .On ("Execute" , mock .Anything , task ).Return (nil , expectedErr )
459
458
460
459
err := worker .handle (ctx , task )
461
- assert .Error (t , err )
462
- assert .Contains (t , err .Error (), "executing task" )
463
- assert .Contains (t , err .Error (), expectedErr .Error ())
460
+ require .Error (t , err )
461
+ require .Contains (t , err .Error (), "executing task" )
462
+ require .Contains (t , err .Error (), expectedErr .Error ())
464
463
465
464
mockTaskWorker .AssertExpectations (t )
466
465
})
@@ -485,8 +484,8 @@ func TestWorker_Handle(t *testing.T) {
485
484
mockTaskWorker .On ("Complete" , mock .Anything , result , task ).Return (expectedErr )
486
485
487
486
err := worker .handle (ctx , task )
488
- assert .Error (t , err )
489
- assert .Equal (t , expectedErr , err )
487
+ require .Error (t , err )
488
+ require .Equal (t , expectedErr , err )
490
489
491
490
mockTaskWorker .AssertExpectations (t )
492
491
})
@@ -601,7 +600,7 @@ func TestWorker_HeartbeatTask(t *testing.T) {
601
600
worker .heartbeatTask (ctx , task , nil )
602
601
duration := time .Since (start )
603
602
604
- assert .Less (t , duration , time .Millisecond * 100 )
603
+ require .Less (t , duration , time .Millisecond * 100 )
605
604
606
605
// Should not have called Extend
607
606
mockTaskWorker .AssertNotCalled (t , "Extend" )
@@ -629,8 +628,8 @@ func TestWorker_HeartbeatTask(t *testing.T) {
629
628
630
629
worker .heartbeatTask (ctx , task , nil )
631
630
632
- assert .False (t , testLogger .hasErrorLog ("could not heartbeat task" ))
633
- assert .Equal (t , 0 , testLogger .errorLogCount ())
631
+ require .False (t , testLogger .hasErrorLog ("could not heartbeat task" ))
632
+ require .Equal (t , 0 , testLogger .errorLogCount ())
634
633
635
634
mockTaskWorker .AssertExpectations (t )
636
635
})
@@ -657,8 +656,8 @@ func TestWorker_HeartbeatTask(t *testing.T) {
657
656
658
657
worker .heartbeatTask (ctx , task , nil )
659
658
660
- assert .False (t , testLogger .hasErrorLog ("could not heartbeat task" ))
661
- assert .Equal (t , 0 , testLogger .errorLogCount ())
659
+ require .False (t , testLogger .hasErrorLog ("could not heartbeat task" ))
660
+ require .Equal (t , 0 , testLogger .errorLogCount ())
662
661
663
662
mockTaskWorker .AssertExpectations (t )
664
663
})
@@ -688,8 +687,8 @@ func TestWorker_HeartbeatTask(t *testing.T) {
688
687
worker .heartbeatTask (ctx , task , nil )
689
688
690
689
// Verify that other errors DO generate ERROR logs
691
- assert .True (t , testLogger .hasErrorLog ("could not heartbeat task" ))
692
- assert .Equal (t , 1 , testLogger .errorLogCount ())
690
+ require .True (t , testLogger .hasErrorLog ("could not heartbeat task" ))
691
+ require .Equal (t , 1 , testLogger .errorLogCount ())
693
692
694
693
mockTaskWorker .AssertExpectations (t )
695
694
})
@@ -757,11 +756,11 @@ func TestWorker_FullWorkflow(t *testing.T) {
757
756
// Cancel and wait for completion
758
757
cancel ()
759
758
err = worker .WaitForCompletion ()
760
- assert .NoError (t , err )
759
+ require .NoError (t , err )
761
760
762
761
// Verify results
763
- assert .Equal (t , int32 (2 ), atomic .LoadInt32 (& processedTasks ))
764
- assert .Len (t , taskResults , 2 )
762
+ require .Equal (t , int32 (2 ), atomic .LoadInt32 (& processedTasks ))
763
+ require .Len (t , taskResults , 2 )
765
764
766
765
mockTaskWorker .AssertExpectations (t )
767
766
})
@@ -833,13 +832,13 @@ func TestWorker_FullWorkflow(t *testing.T) {
833
832
// Cancel and wait for completion
834
833
cancel ()
835
834
err = worker .WaitForCompletion ()
836
- assert .NoError (t , err )
835
+ require .NoError (t , err )
837
836
838
837
// Verify concurrent execution
839
- assert .GreaterOrEqual (t , int (atomic .LoadInt32 (& processedCount )), taskCount - 1 ) // Allow for timing issues
838
+ require .GreaterOrEqual (t , int (atomic .LoadInt32 (& processedCount )), taskCount - 1 ) // Allow for timing issues
840
839
841
840
mu .Lock ()
842
- assert .GreaterOrEqual (t , len (executionTimes ), taskCount - 1 ) // Allow for timing issues
841
+ require .GreaterOrEqual (t , len (executionTimes ), taskCount - 1 ) // Allow for timing issues
843
842
mu .Unlock ()
844
843
845
844
mockTaskWorker .AssertExpectations (t )
@@ -876,7 +875,7 @@ func TestWorker_ErrorHandling(t *testing.T) {
876
875
877
876
cancel ()
878
877
err = worker .WaitForCompletion ()
879
- assert .NoError (t , err )
878
+ require .NoError (t , err )
880
879
881
880
mockTaskWorker .AssertExpectations (t )
882
881
})
@@ -910,7 +909,7 @@ func TestWorker_ErrorHandling(t *testing.T) {
910
909
cancel ()
911
910
912
911
err = worker .WaitForCompletion ()
913
- assert .NoError (t , err )
912
+ require .NoError (t , err )
914
913
915
914
// Don't assert specific expectations since timing can vary
916
915
})
@@ -937,7 +936,7 @@ func TestWorker_Configuration(t *testing.T) {
937
936
require .NoError (t , err )
938
937
939
938
err = worker .WaitForCompletion ()
940
- assert .NoError (t , err )
939
+ require .NoError (t , err )
941
940
942
941
// Should not call Get since no pollers
943
942
mockTaskWorker .AssertNotCalled (t , "Get" )
@@ -956,12 +955,12 @@ func TestWorker_Configuration(t *testing.T) {
956
955
worker := NewWorker (mockBackend , mockTaskWorker , options )
957
956
958
957
// The workQueue should be created with unlimited capacity
959
- assert .NotNil (t , worker .taskQueue )
958
+ require .NotNil (t , worker .taskQueue )
960
959
961
960
// Test that reservation works without blocking
962
961
ctx := context .Background ()
963
962
err := worker .taskQueue .reserve (ctx )
964
- assert .NoError (t , err )
963
+ require .NoError (t , err )
965
964
966
965
// Release should be no-op
967
966
worker .taskQueue .release ()
@@ -993,7 +992,7 @@ func TestWorker_Configuration(t *testing.T) {
993
992
994
993
cancel ()
995
994
err = worker .WaitForCompletion ()
996
- assert .NoError (t , err )
995
+ require .NoError (t , err )
997
996
998
997
mockTaskWorker .AssertExpectations (t )
999
998
})
0 commit comments