Skip to content

Commit 4ebc750

Browse files
committed
test(daemon): flush the queued event-log append before asserting it exists
`recordEvent` queues the event-log append rather than writing it inline, so `open` can name `events.ndjson` before the file is on disk. Asserting its existence right after the handler returned only ever passed by timing: 4.1.11's module loading was slow enough to drain the queue first, Vitest 5's is not. Every other reader of that log awaits `SessionStore.flushEvents`; this was the exception.
1 parent f85bcf5 commit 4ebc750

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎src/daemon/__tests__/request-router-open.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ test('open returns and creates the session state directory', async () => {
180180
path.join(String(response.data?.sessionStateDir), 'events.ndjson'),
181181
);
182182
expect(fs.existsSync(String(response.data?.sessionStateDir))).toBe(true);
183+
// `open` records the request through `recordEvent`, which queues the event-log
184+
// append rather than writing it, so the path it returns can be named before the
185+
// file exists. Every reader of that log awaits this flush first (see
186+
// session-store.test.ts); asserting existence without it races the append and
187+
// only passes when module loading happened to drain the queue in time.
188+
await sessionStore.flushEvents('session-a');
183189
expect(fs.existsSync(String(response.data?.eventLogPath))).toBe(true);
184190
}
185191
expect(inspectDeviceClaims({ udid: device.id })[0]?.claim?.stateDir).toBe(

0 commit comments

Comments
 (0)