Skip to content

Commit 7e9a1d8

Browse files
KyleAMathewsclaude
andauthored
Fix flaky test (#735)
fix(react-db): fix flaky test by preventing race condition The test "optimistic state is dropped after commit" was flaky because it had a race condition: 1. The test would wait for state size to become 4 2. Then immediately check that the temp-key exists 3. However, the async mutation (with only 10ms delay) could complete between steps 1 and 2 Fixed by moving all assertions into the same waitFor() block, ensuring they execute atomically. This prevents the mutation from completing between the size check and the temp-key verification. Co-authored-by: Claude <[email protected]>
1 parent 7b9c681 commit 7e9a1d8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/react-db/tests/useLiveQuery.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,13 +903,13 @@ describe(`Query Collections`, () => {
903903
await waitFor(() => {
904904
// Verify optimistic state is immediately reflected
905905
expect(result.current.state.size).toBe(4)
906+
expect(result.current.state.get(`[temp-key,1]`)).toMatchObject({
907+
id: `temp-key`,
908+
name: `John Doe`,
909+
title: `New Issue`,
910+
})
911+
expect(result.current.state.get(`[4,1]`)).toBeUndefined()
906912
})
907-
expect(result.current.state.get(`[temp-key,1]`)).toMatchObject({
908-
id: `temp-key`,
909-
name: `John Doe`,
910-
title: `New Issue`,
911-
})
912-
expect(result.current.state.get(`[4,1]`)).toBeUndefined()
913913

914914
// Wait for the transaction to be committed
915915
await transaction.isPersisted.promise

0 commit comments

Comments
 (0)