@@ -248,6 +248,65 @@ void main() {
248248 {'r' : isNull});
249249 expect (db.select ('SELECT * FROM ps_sync_state' ), hasLength (0 ));
250250 });
251+
252+ test ('tracks download progress' , () {
253+ const bucket = 'bkt' ;
254+ void expectProgress (int atLast, int sinceLast) {
255+ final [row] = db.select (
256+ 'SELECT count_at_last, count_since_last FROM ps_buckets WHERE name = ?' ,
257+ [bucket],
258+ );
259+ final [actualAtLast, actualSinceLast] = row.values;
260+
261+ expect (actualAtLast, atLast, reason: 'count_at_last mismatch' );
262+ expect (actualSinceLast, sinceLast, reason: 'count_since_last mismatch' );
263+ }
264+
265+ pushSyncData (bucket, '1' , 'row-0' , 'PUT' , {'col' : 'hi' });
266+ expectProgress (0 , 1 );
267+
268+ pushSyncData (bucket, '2' , 'row-1' , 'PUT' , {'col' : 'hi' });
269+ expectProgress (0 , 2 );
270+
271+ expect (
272+ pushCheckpointComplete (
273+ '2' ,
274+ null ,
275+ [_bucketChecksum (bucket, 1 , checksum: 0 )],
276+ priority: 1 ,
277+ ),
278+ isTrue,
279+ );
280+
281+ // Despite committing data, a partial checkpoint should not clear download
282+ // progress stats.
283+ expectProgress (0 , 2 );
284+ expect (db.select ('SELECT * FROM items' ), isNotEmpty);
285+
286+ // Full checkpoint sets count_at_last
287+ expect (
288+ pushCheckpointComplete (
289+ '2' ,
290+ null ,
291+ [_bucketChecksum (bucket, 1 , checksum: 0 )],
292+ ),
293+ isTrue,
294+ );
295+ expectProgress (2 , 0 );
296+
297+ // Run another iteration of this
298+ pushSyncData (bucket, '3' , 'row-3' , 'PUT' , {'col' : 'hi' });
299+ expectProgress (2 , 1 );
300+ expect (
301+ pushCheckpointComplete (
302+ '3' ,
303+ null ,
304+ [_bucketChecksum (bucket, 1 , checksum: 0 )],
305+ ),
306+ isTrue,
307+ );
308+ expectProgress (3 , 0 );
309+ });
251310 });
252311}
253312
0 commit comments