@@ -61,7 +61,7 @@ describe('Sync', () => {
61
61
mockSyncServiceTest ( 'without priorities' , async ( { syncService } ) => {
62
62
const database = await syncService . createDatabase ( ) ;
63
63
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 ) ) ;
65
65
66
66
syncService . pushLine ( {
67
67
checkpoint : {
@@ -96,7 +96,7 @@ describe('Sync', () => {
96
96
mockSyncServiceTest ( 'interrupted sync' , async ( { syncService } ) => {
97
97
let database = await syncService . createDatabase ( ) ;
98
98
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 ) ) ;
100
100
101
101
syncService . pushLine ( {
102
102
checkpoint : {
@@ -111,12 +111,12 @@ describe('Sync', () => {
111
111
112
112
// Close this database before sending the checkpoint...
113
113
await database . close ( ) ;
114
- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 0 ) ) ;
114
+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 0 ) ) ;
115
115
116
116
// And open a new one
117
117
database = await syncService . createDatabase ( ) ;
118
118
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 ) ) ;
120
120
121
121
// Send same checkpoint again
122
122
syncService . pushLine ( {
@@ -135,7 +135,7 @@ describe('Sync', () => {
135
135
mockSyncServiceTest ( 'interrupted sync with new checkpoint' , async ( { syncService } ) => {
136
136
let database = await syncService . createDatabase ( ) ;
137
137
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 ) ) ;
139
139
140
140
syncService . pushLine ( {
141
141
checkpoint : {
@@ -150,10 +150,10 @@ describe('Sync', () => {
150
150
151
151
// Re-open database
152
152
await database . close ( ) ;
153
- await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toEqual ( 0 ) ) ;
153
+ await vi . waitFor ( ( ) => expect ( syncService . connectedListeners ) . toHaveLength ( 0 ) ) ;
154
154
database = await syncService . createDatabase ( ) ;
155
155
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 ) ) ;
157
157
158
158
// Send checkpoint with new data
159
159
syncService . pushLine ( {
@@ -171,7 +171,7 @@ describe('Sync', () => {
171
171
mockSyncServiceTest ( 'different priorities' , async ( { syncService } ) => {
172
172
let database = await syncService . createDatabase ( ) ;
173
173
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 ) ) ;
175
175
176
176
syncService . pushLine ( {
177
177
checkpoint : {
@@ -219,6 +219,39 @@ describe('Sync', () => {
219
219
pushCheckpointComplete ( syncService ) ;
220
220
await waitForSyncStatus ( database , ( s ) => s . downloadProgress == null ) ;
221
221
} ) ;
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
+ } ) ;
222
255
} ) ;
223
256
} ) ;
224
257
0 commit comments