@@ -131,13 +131,6 @@ func TestJobKeys(t *testing.T) {
131
131
for _ , job := range jobs {
132
132
assert .Contains (t , allJobKeys , job .key , fmt .Sprintf ("Job key %s not found in JobKeys" , job .key ))
133
133
}
134
-
135
- // Dispatch a job with an existing key to node1
136
- assert .NoError (t , node1 .DispatchJob (ctx , "job1" , []byte ("updated payload" )), "Failed to dispatch job with existing key" )
137
-
138
- // Check that the number of job keys hasn't changed
139
- updatedAllJobKeys := node1 .JobKeys ()
140
- assert .Equal (t , len (allJobKeys ), len (updatedAllJobKeys ), "Number of job keys shouldn't change when updating an existing job" )
141
134
}
142
135
143
136
func TestJobPayload (t * testing.T ) {
@@ -176,14 +169,12 @@ func TestJobPayload(t *testing.T) {
176
169
assert .False (t , ok , "Expected false for non-existent job" )
177
170
assert .Nil (t , payload , "Expected nil payload for non-existent job" )
178
171
179
- // Update existing job
180
- updatedPayload := []byte ("updated payload" )
181
- assert .NoError (t , node .DispatchJob (ctx , "job1" , updatedPayload ), "Failed to update existing job" )
182
-
183
- // Check if the payload was updated
172
+ // Remove existing job
173
+ assert .NoError (t , node .StopJob (ctx , "job1" ))
174
+ // Check if the payload was removed
184
175
assert .Eventually (t , func () bool {
185
- payload , ok := node .JobPayload ("job1" )
186
- return ok && assert . Equal ( t , updatedPayload , payload , "Payload was not updated correctly" )
176
+ _ , ok := node .JobPayload ("job1" )
177
+ return ! ok
187
178
}, max , delay , "Failed to get updated payload for job" )
188
179
}
189
180
@@ -333,30 +324,17 @@ func TestDispatchJobRaceCondition(t *testing.T) {
333
324
payload := []byte ("test payload" )
334
325
335
326
// Set a stale pending timestamp
336
- staleTS := time .Now ().Add (- 3 * node1 . ackGracePeriod ).UnixNano ()
337
- _ , err := node1 .pendingJobsMap .Set (ctx , jobKey , strconv .FormatInt (staleTS , 10 ))
327
+ staleTS := time .Now ().Add (- time . Hour ).UnixNano ()
328
+ _ , err := node1 .pendingJobsMap .SetAndWait (ctx , jobKey , strconv .FormatInt (staleTS , 10 ))
338
329
require .NoError (t , err , "Failed to set stale pending timestamp" )
330
+ defer func () {
331
+ _ , err = node1 .pendingJobsMap .Delete (ctx , jobKey )
332
+ assert .NoError (t , err , "Failed to delete pending timestamp" )
333
+ }()
339
334
340
335
// Dispatch should succeed because pending timestamp is in the past
341
- err = node2 .DispatchJob (ctx , jobKey , payload )
342
- assert .NoError (t , err , "Dispatch should succeed after pending timeout" )
343
- })
344
-
345
- t .Run ("dispatch cleans up pending entry on failure" , func (t * testing.T ) {
346
- jobKey := "cleanup-job"
347
- payload := []byte ("test payload" )
348
-
349
- // Corrupt the pool stream to force dispatch failure
350
- err := rdb .Del (ctx , "pulse:stream:" + poolStreamName (node1 .PoolName )).Err ()
351
- require .NoError (t , err , "Failed to delete pool stream" )
352
-
353
- // Attempt dispatch (should fail)
354
336
err = node1 .DispatchJob (ctx , jobKey , payload )
355
- require .Error (t , err , "Expected dispatch to fail" )
356
-
357
- // Verify pending entry was cleaned up
358
- _ , exists := node1 .pendingJobsMap .Get (jobKey )
359
- assert .False (t , exists , "Pending entry should be cleaned up after failed dispatch" )
337
+ assert .NoError (t , err , "Dispatch should succeed after pending timeout" )
360
338
})
361
339
362
340
t .Run ("dispatch cleans up pending entry on success" , func (t * testing.T ) {
@@ -386,6 +364,27 @@ func TestDispatchJobRaceCondition(t *testing.T) {
386
364
err = node1 .DispatchJob (ctx , jobKey , payload )
387
365
assert .NoError (t , err , "Dispatch should succeed with invalid pending timestamp" )
388
366
})
367
+
368
+ // Keep this test last, it destroys the stream
369
+ t .Run ("dispatch cleans up pending entry on failure" , func (t * testing.T ) {
370
+ jobKey := "cleanup-job"
371
+ payload := []byte ("test payload" )
372
+
373
+ // Corrupt the pool stream to force dispatch failure
374
+ err := rdb .Del (ctx , "pulse:stream:" + poolStreamName (node1 .PoolName )).Err ()
375
+ require .NoError (t , err , "Failed to delete pool stream" )
376
+
377
+ // Attempt dispatch (should fail)
378
+ err = node1 .DispatchJob (ctx , jobKey , payload )
379
+ require .Error (t , err , "Expected dispatch to fail" )
380
+
381
+ // Verify pending entry was cleaned up
382
+ require .Eventually (t , func () bool {
383
+ _ , exists := node1 .pendingJobsMap .Get (jobKey )
384
+ return ! exists
385
+ }, max , delay , "Pending entry should be cleaned up after failed dispatch" )
386
+ })
387
+
389
388
}
390
389
391
390
func TestNotifyWorker (t * testing.T ) {
0 commit comments