Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/platform-android/src/recording/chunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ async function waitForReady(
): Promise<boolean> {
for (let attempt = 0; attempt < 3; attempt += 1) {
signal?.throwIfAborted();
if ((await transport.exists(remotePath, signal)) === true) return true;
const size = await transport.size(remotePath, signal);
if (typeof size === 'number' && size > 0) return true;
if ((await transport.inspect(nativeProcess, signal)) !== 'owned-alive') return false;
if (attempt < 2) await new Promise<void>((resolve) => setTimeout(resolve, 250));
}
Expand Down
53 changes: 50 additions & 3 deletions packages/platform-android/src/recording/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ test('waits for a SIGINT-accepted recorder to exit before sizing or pulling its
return { stdout: '', stderr: '', exitCode: 0, playable: true };
},
});
const finishing = (await runtime.screenRecordingStart(recordingInput())).pendingHandle
.transfer()
.finish();
const handle = (await runtime.screenRecordingStart(recordingInput())).pendingHandle.transfer();
calls.length = 0;
const finishing = handle.finish();
await vi.advanceTimersByTimeAsync(0);
expect(calls).toEqual(['sigint']);
alive = false;
Expand Down Expand Up @@ -724,6 +724,53 @@ test('falls back to sequential rotation when concurrent start is unavailable', a
}
});

test('falls back to sequential rotation when a concurrent chunk exits with an empty artifact', async () => {
vi.useFakeTimers();
try {
let starts = 0;
let manifest = '';
const stopped = new Set<string>();
const exitedEmpty = new Set<string>();
const emptyPaths = new Set<string>();
const runtime = await start({
// The device refuses a second recorder while the first one runs: the process exits at once
// and leaves a zero-byte artifact behind.
start: async ({ remotePath }: { remotePath: string }) => {
const pid = String(42 + starts++);
if (pid !== '42' && !stopped.has('42')) {
exitedEmpty.add(pid);
emptyPaths.add(remotePath);
}
return recordingProcess(pid, remotePath);
},
size: async (remotePath: string) => (emptyPaths.has(remotePath) ? 0 : 1),
remove: async (remotePath: string) => {
emptyPaths.delete(remotePath);
return true;
},
signal: async ({ pid }: { pid: string }) => {
stopped.add(pid);
return true;
},
isRunning: async (pid: string) => !stopped.has(pid) && !exitedEmpty.has(pid),
writeManifest: async ({ contents }: { contents: string }) => {
manifest = contents;
},
});
const handle = (await runtime.screenRecordingStart(recordingInput())).pendingHandle.transfer();
await vi.advanceTimersByTimeAsync(170_000);
const committed = JSON.parse(manifest).chunks as { remotePid: string }[];
expect(committed).toHaveLength(2);
expect(exitedEmpty.size).toBeGreaterThan(0);
expect(exitedEmpty.has(committed[1]!.remotePid)).toBe(false);
const finishing = handle.finish();
await vi.advanceTimersByTimeAsync(5_000);
await expect(finishing).resolves.toMatchObject({ status: 'completed' });
} finally {
vi.useRealTimers();
}
});

test('rolls back a failed concurrent rotation commit and restores prior active evidence', async () => {
vi.useFakeTimers();
try {
Expand Down
Loading