Files
DevRunbook-Public/apps/worker/src/jobs/worker-loop.test.ts
T
DevRunbook release export cfd2804e27
Managed validation / full (push) Successful in 3m18s
Publish DevRunbook source
2026-09-03 04:09:17 +02:00

54 lines
1.5 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import type { JobStore } from '@devrunbook/application'
import { runWorkerLoop } from './worker-loop'
describe('worker loop', () => {
it('stops cleanly after an idle poll is aborted', async () => {
const controller = new AbortController()
const store = {
claim: vi.fn(async () => {
controller.abort()
return null
}),
} as unknown as JobStore
await runWorkerLoop({
store,
handlers: {},
workerId: 'worker-test',
nextLeaseId: () => 'lease-test',
leaseDurationMs: 30_000,
pollIntervalMs: 2_000,
signal: controller.signal,
})
expect(store.claim).toHaveBeenCalledOnce()
})
it('runs periodic planning before polling and contains planner failures', async () => {
const controller = new AbortController()
const order: string[] = []
const store = {
claim: vi.fn(async () => {
order.push('poll')
controller.abort()
return null
}),
} as unknown as JobStore
await runWorkerLoop({
store,
handlers: {},
workerId: 'worker-test',
nextLeaseId: () => 'lease-test',
leaseDurationMs: 30_000,
pollIntervalMs: 2_000,
signal: controller.signal,
schedule: async () => {
order.push('schedule')
throw new Error('temporary planner failure')
},
onScheduleError: vi.fn(),
})
expect(order).toEqual(['schedule', 'poll'])
})
})