The workflow's 45 s heartbeatTimeout is reset only by the activity's own heartbeat, and the keeper sent one inside the same promise that awaits the control-plane request. A request that stalls therefore also silenced the heartbeat, and the run was canceled as if its activity had died — the cancellation then surfaced as "Execution was canceled". The workflow is now told on every tick, before and independently of the request; a stopped keeper still says nothing, and still reports its own reason.
28 lines
1.3 KiB
TypeScript
28 lines
1.3 KiB
TypeScript
/**
|
|
* A run is canceled by the workflow when its activity stops reporting for 45 s. The lease keeper
|
|
* reports to the workflow itself, so a slow control-plane request must never be mistaken for a
|
|
* dead activity and take the run down with it.
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import { LeaseKeeper } from '../apps/worker/src/lease.js';
|
|
|
|
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
describe('execution lease keeper', () => {
|
|
it('keeps telling the workflow it is alive while a control-plane request hangs', async () => {
|
|
const beats: unknown[] = [];
|
|
const activity = {
|
|
heartbeat: (details: unknown) => beats.push(details),
|
|
cancellationSignal: new AbortController().signal,
|
|
};
|
|
// The control plane never answers a heartbeat: the first request stays in flight for ever.
|
|
const hanging = new Promise<never>(() => undefined);
|
|
const keeper = new LeaseKeeper({ request: (() => hanging) as never }, 'run-1', 3, activity as never, 10).start();
|
|
await sleep(120);
|
|
keeper.close();
|
|
// Ten ticks fit in 120 ms; the old keeper stopped at the one heartbeat it sent before hanging.
|
|
expect(beats.length).toBeGreaterThanOrEqual(4);
|
|
expect(beats.every(details => (details as { leaseToken: number }).leaseToken === 3)).toBe(true);
|
|
});
|
|
});
|