@@ -566,6 +566,45 @@ function defineSyncTests(bson: boolean) {
566566 await vi . waitFor ( ( ) => expect ( connector . uploadDataInvocations ) . toStrictEqual ( 2 ) ) ;
567567 } ) ;
568568
569+ mockSyncServiceTest ( 'should restart uploads on write even if not connected' , async ( { syncService } ) => {
570+ let database = await syncService . createDatabase ( ) ;
571+ let attemptedUploads = 0 ;
572+ await database . execute ( 'INSERT INTO lists (id, name) values (uuid(), ?)' , [ 'local write' ] ) ;
573+
574+ syncService . installRequestInterceptor ( async ( request ) => {
575+ if ( request . url . includes ( '/sync/stream' ) ) {
576+ throw new Error ( 'Pretend that the service is unavailable' ) ;
577+ }
578+ } ) ;
579+
580+ database . connect (
581+ {
582+ fetchCredentials : async ( ) => {
583+ return {
584+ endpoint : 'https://powersync.example.org' ,
585+ token : 'test'
586+ } ;
587+ } ,
588+ uploadData : async ( ) => {
589+ attemptedUploads ++ ;
590+ throw new Error ( 'deliberate failure' ) ;
591+ }
592+ } ,
593+ { ...options , retryDelayMs : 100 , crudUploadThrottleMs : 100 }
594+ ) ;
595+ await database . waitForStatus ( ( s ) => s . dataFlowStatus . downloadError != null ) ;
596+
597+ // Because we start a crud upload on connect, there should have been a call.
598+ expect ( attemptedUploads ) . toStrictEqual ( 1 ) ;
599+ expect ( database . currentStatus . dataFlowStatus . uploadError ) . toMatchObject ( { name : 'Error' } ) ;
600+
601+ // Currently, we don't retry crud uploads if we're not connected. We might revisit that in the future, but either
602+ // way we definitely want to retry if there's a new CRUD entry.
603+ console . log ( 'second write' ) ;
604+ await database . execute ( 'INSERT INTO lists (id, name) values (uuid(), ?)' , [ 'second local write' ] ) ;
605+ await vi . waitFor ( ( ) => expect ( attemptedUploads ) . toStrictEqual ( 2 ) ) ;
606+ } ) ;
607+
569608 mockSyncServiceTest ( 'handles uploads across checkpoints' , async ( { syncService } ) => {
570609 const logger = createLogger ( 'test' , { logLevel : Logger . TRACE } ) ;
571610 const logMessages : string [ ] = [ ] ;
0 commit comments