Skip to content

Commit 9dc6119

Browse files
committed
test(daemon): flush the queued event-log append before asserting it exists
The session journal queues its ndjson append rather than writing it inline, so `open` can name the event-log path before the file is on disk. Reading it with `fs.existsSync` 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, and the assertion started failing. Every other reader of that log awaits `SessionStore.flushEvents` for the same reason; this one was the exception.
1 parent c25534a commit 9dc6119

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)