fix(pi): keep active runs alive during background sleep
This commit is contained in:
@@ -50,6 +50,36 @@ describe('BackgroundLifecycleController', () => {
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
it('does not stop the runtime when a lease is acquired while sleep preparation is in flight', async () => {
|
||||
vi.useFakeTimers();
|
||||
let finishSleepPreparation!: () => void;
|
||||
const sleepPreparation = new Promise<void>((resolve) => {
|
||||
finishSleepPreparation = resolve;
|
||||
});
|
||||
const onSleep = vi.fn(() => sleepPreparation);
|
||||
const onStopRuntime = vi.fn().mockResolvedValue(undefined);
|
||||
const controller = new BackgroundLifecycleController({
|
||||
idleStopMs: 60_000,
|
||||
onSleep,
|
||||
onStopRuntime,
|
||||
});
|
||||
|
||||
controller.setActivity({ visible: false, module: 'learning' });
|
||||
await vi.advanceTimersByTimeAsync(60_000);
|
||||
expect(onSleep).toHaveBeenCalledTimes(1);
|
||||
|
||||
const release = controller.acquireLease({ id: 'coding-run:1', kind: 'coding-run' });
|
||||
finishSleepPreparation();
|
||||
await vi.runAllTicks();
|
||||
|
||||
expect(onStopRuntime).not.toHaveBeenCalled();
|
||||
|
||||
release();
|
||||
await vi.advanceTimersByTimeAsync(60_000);
|
||||
expect(onStopRuntime).toHaveBeenCalledTimes(1);
|
||||
controller.dispose();
|
||||
});
|
||||
|
||||
it('cancels the idle stop when programming becomes visible again', async () => {
|
||||
vi.useFakeTimers();
|
||||
const onSleep = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user