@@ -61,7 +61,7 @@ describe('Sync', () => {
6161 mockSyncServiceTest ( 'without priorities' , async ( { syncService } ) => {
6262 const database = await syncService . createDatabase ( ) ;
6363 database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
64- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 1 ) ) ;
64+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
6565
6666 syncService . pushLine ( {
6767 checkpoint : {
@@ -96,7 +96,7 @@ describe('Sync', () => {
9696 mockSyncServiceTest ( 'interrupted sync' , async ( { syncService } ) => {
9797 let database = await syncService . createDatabase ( ) ;
9898 database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
99- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 1 ) ) ;
99+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
100100
101101 syncService . pushLine ( {
102102 checkpoint : {
@@ -111,12 +111,12 @@ describe('Sync', () => {
111111
112112 // Close this database before sending the checkpoint...
113113 await database . close ( ) ;
114- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 0 ) ) ;
114+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 0 ) ) ;
115115
116116 // And open a new one
117117 database = await syncService . createDatabase ( ) ;
118118 database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
119- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 1 ) ) ;
119+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
120120
121121 // Send same checkpoint again
122122 syncService . pushLine ( {
@@ -135,7 +135,7 @@ describe('Sync', () => {
135135 mockSyncServiceTest ( 'interrupted sync with new checkpoint' , async ( { syncService } ) => {
136136 let database = await syncService . createDatabase ( ) ;
137137 database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
138- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 1 ) ) ;
138+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
139139
140140 syncService . pushLine ( {
141141 checkpoint : {
@@ -150,10 +150,10 @@ describe('Sync', () => {
150150
151151 // Re-open database
152152 await database . close ( ) ;
153- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 0 ) ) ;
153+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 0 ) ) ;
154154 database = await syncService . createDatabase ( ) ;
155155 database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
156- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 1 ) ) ;
156+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
157157
158158 // Send checkpoint with new data
159159 syncService . pushLine ( {
@@ -171,7 +171,7 @@ describe('Sync', () => {
171171 mockSyncServiceTest ( 'different priorities' , async ( { syncService } ) => {
172172 let database = await syncService . createDatabase ( ) ;
173173 database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
174- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 1 ) ) ;
174+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
175175
176176 syncService . pushLine ( {
177177 checkpoint : {
@@ -219,6 +219,39 @@ describe('Sync', () => {
219219 pushCheckpointComplete ( syncService ) ;
220220 await waitForSyncStatus ( database , ( s ) => s . downloadProgress == null ) ;
221221 } ) ;
222+
223+ mockSyncServiceTest ( 'uses correct state when reconnecting' , async ( { syncService} ) => {
224+ let database = await syncService . createDatabase ( ) ;
225+ database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
226+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
227+
228+ syncService . pushLine ( {
229+ checkpoint : {
230+ last_op_id : '10' ,
231+ buckets : [
232+ bucket ( 'a' , 5 , { priority : 0 } ) ,
233+ bucket ( 'b' , 5 , { priority : 3 } ) ,
234+ ]
235+ }
236+ } ) ;
237+
238+ // Sync priority 0 completely, start with rest
239+ pushDataLine ( syncService , 'a' , 5 ) ;
240+ pushDataLine ( syncService , 'b' , 1 ) ;
241+ pushCheckpointComplete ( syncService , 0 ) ;
242+ await database . waitForFirstSync ( { priority : 0 } ) ;
243+
244+ await database . close ( ) ;
245+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 0 ) ) ;
246+ database = await syncService . createDatabase ( ) ;
247+ database . connect ( new TestConnector ( ) , { connectionMethod : SyncStreamConnectionMethod . HTTP } ) ;
248+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 1 ) ) ;
249+
250+ expect ( syncService . connectedListeners [ 0 ] . buckets ) . toStrictEqual ( [
251+ { "name" : "a" , "after" : "10" } ,
252+ { "name" : "b" , "after" : "6" } ,
253+ ] ) ;
254+ } ) ;
222255 } ) ;
223256} ) ;
224257
0 commit comments