{{ message }}
Repository navigation
Expand file tree
/
Copy pathworker_session.spec.ts
More file actions
871 lines (739 loc) · 24 KB
/
Copy pathworker_session.spec.ts
File metadata and controls
871 lines (739 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
import { setTimeout } from 'node:timers/promises'
import { test } from '@japa/runner'
import { fake } from '../src/drivers/fake_adapter.js'
import { JobPool } from '../src/job_pool.js'
import {
WorkerSession,
type JobExecutor,
type WorkerSessionOptions,
type WorkerSessionSettings,
} from '../src/worker_session.js'
import { ControllableAdapter } from './_mocks/controllable_adapter.js'
import { trackPromise } from './_utils/track_promise.js'
import { MemoryLogger } from './_mocks/memory_logger.js'
type SessionOverrides = Partial<Omit<WorkerSessionOptions, 'settings' | 'jobExecutionRuntime'>> & {
jobExecutionRuntime?: Partial<JobExecutor>
settings?: Partial<WorkerSessionSettings>
}
function createSession(overrides: SessionOverrides = {}): WorkerSession {
const { settings, jobExecutionRuntime, ...options } = overrides
return new WorkerSession({
workerId: 'test-worker',
queues: ['default'],
adapter: fake()(),
jobExecutionRuntime: {
execute: async () => ({ type: 'completed' as const }),
failStalled: async () => ({
type: 'failed' as const,
reason: 'stalled' as const,
error: new Error('stalled'),
}),
...jobExecutionRuntime,
},
scheduleDispatcher: {
dispatch: async () => ({ jobId: 'scheduled-job' }),
},
wrapInternal: (operation) => operation(),
logger: new MemoryLogger(),
settings: {
concurrency: 1,
idleDelay: 10,
stalledInterval: 30_000,
stalledThreshold: 30_000,
maxStalledCount: 1,
unknownJobRetries: 10,
...settings,
},
...options,
})
}
test.group('WorkerSession', () => {
test('returns an idle cycle when no work is available', async ({ assert, cleanup }) => {
const session = createSession()
cleanup(() => session.stop())
const cycle = await session.processCycle()
assert.deepEqual(cycle, { type: 'idle', suggestedDelay: 10 })
})
test('checks each queue only once when a high-concurrency worker is idle', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const session = createSession({
adapter,
queues: ['critical', 'default', 'low'],
settings: { concurrency: 50 },
})
cleanup(() => session.stop())
const cycle = await session.processCycle()
assert.deepEqual(cycle, { type: 'idle', suggestedDelay: 10 })
assert.deepEqual(adapter.polledQueues, ['critical', 'default', 'low'])
})
test('fans out remaining acquisitions after the initial probe finds work', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const executionGate = Promise.withResolvers<void>()
let executionsStarted = 0
adapter.acquisitions.block(2, 3)
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
executionsStarted++
await executionGate.promise
return { type: 'completed' }
},
},
settings: { concurrency: 3 },
})
cleanup(async () => {
adapter.releaseAll()
executionGate.resolve()
await session.stop()
})
for (let index = 1; index <= 3; index++) {
await adapter.pushOn('default', {
id: `backlog-job-${index}`,
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
}
const cycle = session.processCycle()
await adapter.acquisitions.waitForStarted(3)
assert.equal(adapter.acquisitions.calls, 3)
adapter.acquisitions.release(2, 3)
assert.equal((await cycle)?.type, 'started')
assert.equal(executionsStarted, 3)
})
test('uses one probe per subsequent empty tick after processing one job', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const session = createSession({ adapter, settings: { concurrency: 10 } })
cleanup(() => session.stop())
await adapter.pushOn('default', {
id: 'only-job',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
assert.equal((await session.processCycle())?.type, 'started')
assert.equal(adapter.acquisitions.calls, 10)
assert.equal((await session.processCycle())?.type, 'completed')
assert.equal((await session.processCycle())?.type, 'idle')
assert.equal(adapter.acquisitions.calls, 11)
assert.equal((await session.processCycle())?.type, 'idle')
assert.equal(adapter.acquisitions.calls, 12)
})
test('reuses one completion wait across idle ticks and observes a later job', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const longExecution = Promise.withResolvers<void>()
const originalWaitForNextCompletion = JobPool.prototype.waitForNextCompletion
let completionWaits = 0
let completionObservers = 0
JobPool.prototype.waitForNextCompletion = function () {
completionWaits++
const operation = originalWaitForNextCompletion.call(this)
return {
then(onFulfilled, onRejected) {
completionObservers++
return operation.then(onFulfilled, onRejected)
},
} as Promise<Awaited<typeof operation>>
}
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute(job) {
if (job.id === 'long-running') {
await longExecution.promise
}
return { type: 'completed' }
},
},
settings: { concurrency: 2, idleDelay: 1 },
})
cleanup(async () => {
JobPool.prototype.waitForNextCompletion = originalWaitForNextCompletion
longExecution.resolve()
await session.stop()
})
await adapter.pushOn('default', {
id: 'long-running',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
assert.equal((await session.processCycle())?.type, 'started')
const laterCycle = session.processCycle()
await adapter.acquisitions.waitForStarted(8)
assert.equal(completionWaits, 1)
assert.equal(completionObservers, 1)
await adapter.pushOn('default', {
id: 'later-short-job',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const started = await laterCycle
assert.equal(started?.type, 'started')
if (started?.type === 'started') {
assert.equal(started.job.id, 'later-short-job')
}
const completed = await session.processCycle()
assert.equal(completed?.type, 'completed')
if (completed?.type === 'completed') {
assert.equal(completed.job.id, 'later-short-job')
}
assert.equal(completionWaits, 1)
assert.equal(completionObservers, 1)
})
test('stops cleanly with a completion wait pending', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
const execution = Promise.withResolvers<void>()
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
await execution.promise
return { type: 'completed' }
},
},
settings: { concurrency: 2, idleDelay: 60_000 },
})
cleanup(async () => {
execution.resolve()
await session.stop()
})
await adapter.pushOn('default', {
id: 'pending-completion',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
assert.equal((await session.processCycle())?.type, 'started')
const pendingCycle = trackPromise(session.processCycle())
await setTimeout(0)
const stop = trackPromise(session.stop())
await setTimeout(0)
assert.isTrue(pendingCycle.settled)
assert.isFalse(stop.settled)
execution.resolve()
await Promise.all([pendingCycle.promise, stop.promise])
assert.isTrue(stop.settled)
assert.isNull(await session.processCycle())
})
test('start() resolves only once stop() has finalized every job', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
const executionStarted = Promise.withResolvers<void>()
adapter.finalizations.block(1)
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
executionStarted.resolve()
return { type: 'completed' }
},
},
})
cleanup(async () => {
adapter.releaseAll()
await session.stop()
})
await adapter.pushOn('default', {
id: 'finalized-before-start-resolves',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const start = trackPromise(session.start())
await executionStarted.promise
void session.stop()
await adapter.finalizations.waitForStarted()
await setTimeout(10)
assert.isFalse(start.settled, 'start() must wait for the finalization stop() drains')
adapter.finalizations.release(1)
await start.promise
assert.isNull(await adapter.getJob('finalized-before-start-resolves', 'default'))
})
test('surfaces an initial probe failure without starting fan-out acquisitions', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const acquisitionError = new Error('Failed to acquire initial job')
adapter.acquisitions.fail(1, acquisitionError)
const session = createSession({ adapter, settings: { concurrency: 10 } })
cleanup(() => session.stop())
const cycle = await session.processCycle()
assert.equal(cycle?.type, 'error')
if (cycle?.type === 'error') {
assert.strictEqual(cycle.error, acquisitionError)
}
assert.equal(adapter.acquisitions.calls, 1)
})
test('rejects continuous processing after manual processing has started', async ({
assert,
cleanup,
}) => {
const session = createSession()
cleanup(() => session.stop())
await session.processCycle()
await assert.rejects(
() => session.start(),
'Configuration error. Reason: Cannot use continuous processing during a manual WorkerSession'
)
})
test('rejects start when process already owns the continuous consumer', async ({
assert,
cleanup,
}) => {
const session = createSession()
cleanup(() => session.stop())
session.process()
await assert.rejects(
() => session.start(),
'Configuration error. Reason: WorkerSession already has an active cycle consumer'
)
})
test('waits for an in-flight probe and its job without starting fan-out after stopping', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const executionGate = Promise.withResolvers<void>()
const executionStarted = Promise.withResolvers<void>()
let executionsCompleted = 0
adapter.acquisitions.block(1)
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
executionStarted.resolve()
await executionGate.promise
executionsCompleted++
return { type: 'completed' }
},
},
settings: { concurrency: 2 },
})
cleanup(async () => {
adapter.releaseAll()
executionGate.resolve()
await session.stop()
})
await adapter.pushOn('default', {
id: 'late-job-1',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const start = session.start()
await adapter.acquisitions.waitForStarted(1)
const stop = trackPromise(session.stop())
assert.isFalse(stop.settled, 'Session must wait for acquisitions already in flight')
adapter.acquisitions.release(1)
await executionStarted.promise
await setTimeout(0)
assert.equal(adapter.acquisitions.calls, 1, 'Session must not fan out after stopping')
assert.isFalse(stop.settled, 'Session must wait for acquired jobs')
executionGate.resolve()
await Promise.all([stop.promise, start])
assert.equal(executionsCompleted, 1)
assert.isNull(await adapter.getJob('late-job-1', 'default'))
})
test('does not report or fail an unknown job whose lease was lost', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const logger = new MemoryLogger()
let failed = false
adapter.retryJob = async () => false
adapter.failJob = async () => {
failed = true
return true
}
const session = createSession({
adapter,
logger,
jobExecutionRuntime: {
execute: async () => ({
type: 'retry' as const,
retryAt: new Date(Date.now() + 30_000),
jobNotFound: true as const,
}),
},
})
cleanup(() => session.stop())
await adapter.pushOn('default', {
id: 'lost-unknown-job',
name: 'UnknownJob',
payload: {},
attempts: 0,
priority: 0,
})
assert.equal((await session.processCycle())?.type, 'started')
assert.equal((await session.processCycle())?.type, 'completed')
// The job was acquired again elsewhere: no warning about a return that did not happen.
assert.deepEqual(
logger.logs.filter((entry) => entry.level === 'warn'),
[]
)
assert.isFalse(failed)
})
test('cannot restart after reaching quiescence', async ({ assert }) => {
const session = createSession()
await session.processCycle()
await session.stop()
assert.isNull(await session.processCycle())
await session.start()
assert.isNull(await session.processCycle())
})
test('does not claim another Schedule after stopping', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
const dispatches: string[] = []
adapter.scheduleClaims.block(1)
const session = createSession({
adapter,
scheduleDispatcher: {
async dispatch(request) {
dispatches.push(request.name)
return { jobId: 'scheduled-job' }
},
},
})
cleanup(async () => {
adapter.releaseAll()
await session.stop()
})
await adapter.upsertSchedule({
id: 'due-schedule',
name: 'ScheduledJob',
payload: {},
everyMs: 60_000,
timezone: 'UTC',
})
await adapter.updateSchedule('due-schedule', {
nextRunAt: new Date(Date.now() - 1_000),
})
const cycle = session.processCycle()
await adapter.scheduleClaims.waitForStarted()
const stop = session.stop()
adapter.scheduleClaims.release(1)
await Promise.all([cycle, stop])
assert.equal(adapter.scheduleClaims.calls, 1)
assert.deepEqual(dispatches, ['ScheduledJob'])
})
test('owns an acquired job while a sibling acquisition is still pending', async ({ cleanup }) => {
const adapter = new ControllableAdapter()
const executionStarted = Promise.withResolvers<void>()
adapter.acquisitions.block(2)
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
executionStarted.resolve()
return { type: 'completed' }
},
},
settings: { concurrency: 2 },
})
cleanup(async () => {
adapter.releaseAll()
await session.stop()
})
await adapter.pushOn('default', {
id: 'immediately-owned-job',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const start = session.start()
await adapter.acquisitions.waitForStarted(2)
await executionStarted.promise
adapter.acquisitions.release(2)
await session.stop()
await start
})
test('interrupts the idle delay when stopping', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
const session = createSession({ adapter, settings: { idleDelay: 60_000 } })
cleanup(() => session.stop())
const start = trackPromise(session.start())
await adapter.acquisitions.waitForSettled(1)
await setTimeout(0)
await session.stop()
await setTimeout(0)
assert.isTrue(start.settled)
})
test('interrupts the error delay when stopping', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
adapter.acquisitions.fail(1, new Error('Failed to acquire job'))
const session = createSession({ adapter })
cleanup(() => session.stop())
const start = trackPromise(session.start())
await adapter.acquisitions.waitForSettled(1)
await setTimeout(0)
await session.stop()
await setTimeout(0)
assert.isTrue(start.settled)
})
test('logs a failed cycle through the logger', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
const error = new Error('Failed to acquire job')
adapter.acquisitions.fail(1, error)
const logger = new MemoryLogger()
const session = createSession({ adapter, logger })
cleanup(() => session.stop())
const start = session.start()
await adapter.acquisitions.waitForSettled(1)
await setTimeout(0)
await session.stop()
await start
const errors = logger.logs.filter((entry) => entry.level === 'error')
assert.lengthOf(errors, 1)
assert.strictEqual(errors[0].obj?.err, error)
assert.equal(errors[0].obj?.workerId, 'test-worker')
assert.equal(errors[0].message, 'Worker cycle failed, next attempt in 5000ms')
})
test('suppresses an acquired cycle after stopping', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
adapter.acquisitions.block(1)
const session = createSession({ adapter })
cleanup(async () => {
adapter.releaseAll()
await session.stop()
})
await adapter.pushOn('default', {
id: 'stopped-cycle-job',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const cycle = session.processCycle()
await adapter.acquisitions.waitForStarted()
const stop = session.stop()
adapter.acquisitions.release(1)
assert.isNull(await cycle)
await stop
})
test('waits for stalled jobs recovered while stopping to be failed', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const hookStarted = Promise.withResolvers<void>()
const hookGate = Promise.withResolvers<void>()
adapter.setWorkerId('crashed-worker')
await adapter.pushOn('default', {
id: 'stalled-job',
name: 'TestJob',
payload: {},
attempts: 0,
stalledCount: 1,
})
await adapter.popFrom('default')
await setTimeout(20)
adapter.stalledChecks.block(1)
const session = createSession({
adapter,
jobExecutionRuntime: {
async failStalled() {
hookStarted.resolve()
await hookGate.promise
return { type: 'failed', reason: 'stalled', error: new Error('stalled') }
},
},
settings: { stalledThreshold: 10 },
})
cleanup(async () => {
hookGate.resolve()
adapter.releaseAll()
await session.stop()
})
const cycle = session.processCycle()
await adapter.stalledChecks.waitForStarted()
const stop = trackPromise(session.stop())
adapter.stalledChecks.release(1)
await hookStarted.promise
await setTimeout(20)
assert.isFalse(stop.settled)
hookGate.resolve()
await stop.promise
assert.isNull(await cycle)
assert.isNull(await adapter.getJob('stalled-job', 'default'))
})
test('fails at most as many stalled jobs as there are free slots', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
const hookGate = Promise.withResolvers<void>()
const firstHookStarted = Promise.withResolvers<void>()
const failed: string[] = []
adapter.setWorkerId('crashed-worker')
for (const id of ['stalled-1', 'stalled-2']) {
await adapter.pushOn('default', {
id,
name: 'TestJob',
payload: {},
attempts: 0,
stalledCount: 1,
})
await adapter.popFrom('default')
}
await setTimeout(20)
const session = createSession({
adapter,
jobExecutionRuntime: {
async failStalled(job) {
failed.push(job.id)
firstHookStarted.resolve()
await hookGate.promise
return { type: 'failed', reason: 'stalled', error: new Error('stalled') }
},
},
settings: { concurrency: 1, stalledThreshold: 10 },
})
cleanup(async () => {
hookGate.resolve()
await session.stop()
})
void session.processCycle()
await firstHookStarted.promise
await setTimeout(20)
assert.lengthOf(failed, 1)
const [other] = ['stalled-1', 'stalled-2'].filter((id) => id !== failed[0])
assert.equal((await adapter.getJob(other, 'default'))!.status, 'active')
})
test('suppresses a stalled-check error after stopping', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
adapter.stalledChecks.block(1).fail(1, new Error('Failed to recover stalled jobs'))
const session = createSession({ adapter })
cleanup(async () => {
adapter.releaseAll()
await session.stop()
})
const cycle = session.processCycle()
await adapter.stalledChecks.waitForStarted()
const stop = session.stop()
adapter.stalledChecks.release(1)
assert.isNull(await cycle)
await stop
})
test('keeps renewing a late-acquired job while stopping', async ({ cleanup }) => {
const adapter = new ControllableAdapter()
const executionStarted = Promise.withResolvers<void>()
const executionGate = Promise.withResolvers<void>()
adapter.acquisitions.block(1)
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
executionStarted.resolve()
await executionGate.promise
return { type: 'completed' }
},
},
settings: { stalledThreshold: 20 },
})
cleanup(async () => {
executionGate.resolve()
adapter.releaseAll()
await session.stop()
})
await adapter.pushOn('default', {
id: 'renewed-during-stop',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const start = session.start()
await adapter.acquisitions.waitForStarted()
const stop = session.stop()
adapter.acquisitions.release(1)
await executionStarted.promise
await adapter.renewals.waitForStarted()
executionGate.resolve()
await Promise.all([stop, start])
})
test('waits for sibling acquisitions when one acquisition fails', async ({ assert, cleanup }) => {
const adapter = new ControllableAdapter()
let jobCompleted = false
adapter.acquisitions.block(2, 3).fail(2, new Error('Failed to acquire job'))
adapter.finalizations.block(1)
const session = createSession({
adapter,
jobExecutionRuntime: {
async execute() {
jobCompleted = true
return { type: 'completed' }
},
},
settings: { concurrency: 3 },
})
cleanup(async () => {
adapter.releaseAll()
await session.stop()
})
await adapter.pushOn('default', {
id: 'late-job-after-sibling-error',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const start = session.start()
await adapter.acquisitions.waitForStarted(3)
adapter.acquisitions.release(2)
await adapter.acquisitions.waitForSettled(2)
const stop = trackPromise(session.stop())
assert.isFalse(stop.settled)
adapter.acquisitions.release(3)
await adapter.finalizations.waitForStarted()
assert.isTrue(jobCompleted)
assert.isFalse(stop.settled)
adapter.finalizations.release(1)
await Promise.all([stop.promise, start])
assert.equal(adapter.acquisitions.calls, 3)
assert.isNull(await adapter.getJob('late-job-after-sibling-error', 'default'))
})
test('emits successful acquisitions before a sibling acquisition error', async ({
assert,
cleanup,
}) => {
const adapter = new ControllableAdapter()
adapter.acquisitions.fail(2, new Error('Failed to acquire sibling job'))
const session = createSession({ adapter, settings: { concurrency: 2 } })
cleanup(() => session.stop())
await adapter.pushOn('default', {
id: 'success-before-error',
name: 'TestJob',
payload: {},
attempts: 0,
priority: 0,
})
const startedCycle = await session.processCycle()
const errorCycle = await session.processCycle()
assert.equal(startedCycle?.type, 'started')
assert.equal(errorCycle?.type, 'error')
})
})
You can’t perform that action at this time.
