@@ -118,6 +118,21 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
118118 } )
119119 }
120120
121+ // Helper to wait for users to be synced to Electric/TanStack DB
122+ async function waitForUsersSynced (
123+ userIds : Array < string > ,
124+ timeout : number = 10000 ,
125+ ) {
126+ // Use eager collection since it continuously syncs all data
127+ const usersCollection = config . collections . eager . users
128+ await waitFor ( ( ) => {
129+ return userIds . every ( ( userId ) => usersCollection . has ( userId ) )
130+ } , {
131+ timeout,
132+ message : `Users ${ userIds . join ( ', ' ) } did not sync to collection` ,
133+ } )
134+ }
135+
121136 // Helper function to run all tests for a given sync mode
122137 function runTestsForSyncMode ( syncMode : SyncMode ) {
123138 describe ( `${ syncMode } mode` , ( ) => {
@@ -167,6 +182,10 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
167182 deletedAt : null ,
168183 } )
169184
185+ // Wait for all 3 users to be synced to Electric before inserting posts
186+ // This ensures the subquery in the WHERE clause can properly evaluate
187+ await waitForUsersSynced ( [ userId1 , userId2 , userId3 ] )
188+
170189 // Insert posts for these users
171190 const postId1 = randomUUID ( )
172191 const postId2 = randomUUID ( )
@@ -251,6 +270,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
251270 deletedAt : null ,
252271 } )
253272
273+ // Wait for user to be synced to Electric before inserting post
274+ await waitForUsersSynced ( [ userId ] )
275+
254276 // Insert post for this user
255277 const postId = randomUUID ( )
256278 await config . mutations . insertPost ( {
@@ -305,6 +327,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
305327 deletedAt : null ,
306328 } )
307329
330+ // Wait for user to be synced to Electric before inserting post
331+ await waitForUsersSynced ( [ userId ] )
332+
308333 // Insert post for this user
309334 const postId = randomUUID ( )
310335 await config . mutations . insertPost ( {
@@ -358,6 +383,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
358383 deletedAt : null ,
359384 } )
360385
386+ // Wait for user to be synced to Electric before inserting post
387+ await waitForUsersSynced ( [ userId ] )
388+
361389 // Insert post for this user
362390 const postId = randomUUID ( )
363391 await config . mutations . insertPost ( {
@@ -413,6 +441,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
413441 deletedAt : null ,
414442 } )
415443
444+ // Wait for user to be synced to Electric before inserting post
445+ await waitForUsersSynced ( [ userId ] )
446+
416447 // Insert post for this user
417448 const postId = randomUUID ( )
418449 await config . mutations . insertPost ( {
@@ -469,6 +500,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
469500 deletedAt : null ,
470501 } )
471502
503+ // Wait for user to be synced to Electric before inserting post
504+ await waitForUsersSynced ( [ userId ] )
505+
472506 // Insert post for this user
473507 const postId = randomUUID ( )
474508 await config . mutations . insertPost ( {
@@ -521,6 +555,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
521555 deletedAt : null ,
522556 } )
523557
558+ // Wait for user to be synced to Electric before inserting post
559+ await waitForUsersSynced ( [ userId ] )
560+
524561 // Insert post for this user
525562 const postId = randomUUID ( )
526563 await config . mutations . insertPost ( {
@@ -610,7 +647,9 @@ export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) {
610647 deletedAt : null ,
611648 } )
612649
613- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
650+ // Wait for all 3 users to be synced to Electric before inserting posts
651+ // This ensures the subquery in the WHERE clause can properly evaluate
652+ await waitForUsersSynced ( [ userId1 , userId2 , userId3 ] )
614653
615654 // Insert posts for these users
616655 const postId1 = randomUUID ( )
0 commit comments