@@ -15,9 +15,26 @@ import 'utils/in_memory_http.dart';
1515import 'utils/test_utils_impl.dart' ;
1616
1717void main () {
18+ _declareTests (
19+ 'dart sync client' ,
20+ SyncOptions (
21+ // ignore: deprecated_member_use_from_same_package
22+ syncImplementation: SyncClientImplementation .dart,
23+ retryDelay: Duration (milliseconds: 200 )),
24+ );
25+
26+ _declareTests (
27+ 'rust sync client' ,
28+ SyncOptions (
29+ syncImplementation: SyncClientImplementation .rust,
30+ retryDelay: Duration (milliseconds: 200 )),
31+ );
32+ }
33+
34+ void _declareTests (String name, SyncOptions options) {
1835 final ignoredLogger = Logger .detached ('powersync.test' )..level = Level .OFF ;
1936
20- group ('in-memory sync tests' , () {
37+ group (name , () {
2138 late final testUtils = TestUtils ();
2239
2340 late TestPowerSyncFactory factory ;
@@ -44,8 +61,7 @@ void main() {
4461 expiresAt: DateTime .now (),
4562 );
4663 }, uploadData: (db) => uploadData (db)),
47- options: const SyncOptions (retryDelay: Duration (milliseconds: 200 )),
48- logger: logger,
64+ options: options,
4965 );
5066
5167 addTearDown (() async {
@@ -113,6 +129,7 @@ void main() {
113129 });
114130 await expectLater (
115131 status, emits (isSyncStatus (downloading: false , hasSynced: true )));
132+ await syncClient.abort ();
116133
117134 final independentDb = factory .wrapRaw (raw, logger: ignoredLogger);
118135 addTearDown (independentDb.close);
@@ -128,65 +145,68 @@ void main() {
128145 isTrue);
129146 });
130147
131- test ('can save independent buckets in same transaction' , () async {
132- final status = await waitForConnection ();
133-
134- syncService.addLine ({
135- 'checkpoint' : Checkpoint (
136- lastOpId: '0' ,
137- writeCheckpoint: null ,
138- checksums: [
139- BucketChecksum (bucket: 'a' , checksum: 0 , priority: 3 ),
140- BucketChecksum (bucket: 'b' , checksum: 0 , priority: 3 ),
141- ],
142- )
143- });
144- await expectLater (status, emits (isSyncStatus (downloading: true )));
145-
146- var commits = 0 ;
147- raw.commits.listen ((_) => commits++ );
148+ // ignore: deprecated_member_use_from_same_package
149+ if (options.syncImplementation == SyncClientImplementation .dart) {
150+ test ('can save independent buckets in same transaction' , () async {
151+ final status = await waitForConnection ();
148152
149- syncService
150- ..addLine ({
151- 'data' : {
152- 'bucket' : 'a' ,
153- 'data' : < Map <String , Object ?>> [
154- {
155- 'op_id' : '1' ,
156- 'op' : 'PUT' ,
157- 'object_type' : 'a' ,
158- 'object_id' : '1' ,
159- 'checksum' : 0 ,
160- 'data' : {},
161- }
162- ],
163- }
164- })
165- ..addLine ({
166- 'data' : {
167- 'bucket' : 'b' ,
168- 'data' : < Map <String , Object ?>> [
169- {
170- 'op_id' : '2' ,
171- 'op' : 'PUT' ,
172- 'object_type' : 'b' ,
173- 'object_id' : '1' ,
174- 'checksum' : 0 ,
175- 'data' : {},
176- }
153+ syncService.addLine ({
154+ 'checkpoint' : Checkpoint (
155+ lastOpId: '0' ,
156+ writeCheckpoint: null ,
157+ checksums: [
158+ BucketChecksum (bucket: 'a' , checksum: 0 , priority: 3 ),
159+ BucketChecksum (bucket: 'b' , checksum: 0 , priority: 3 ),
177160 ],
178- }
161+ )
179162 });
163+ await expectLater (status, emits (isSyncStatus (downloading: true )));
180164
181- // Wait for the operations to be inserted.
182- while (raw.select ('SELECT * FROM ps_oplog;' ).length < 2 ) {
183- await pumpEventQueue ();
184- }
165+ var commits = 0 ;
166+ raw.commits.listen ((_) => commits++ );
185167
186- // The two buckets should have been inserted in a single transaction
187- // because the messages were received in quick succession.
188- expect (commits, 1 );
189- });
168+ syncService
169+ ..addLine ({
170+ 'data' : {
171+ 'bucket' : 'a' ,
172+ 'data' : < Map <String , Object ?>> [
173+ {
174+ 'op_id' : '1' ,
175+ 'op' : 'PUT' ,
176+ 'object_type' : 'a' ,
177+ 'object_id' : '1' ,
178+ 'checksum' : 0 ,
179+ 'data' : {},
180+ }
181+ ],
182+ }
183+ })
184+ ..addLine ({
185+ 'data' : {
186+ 'bucket' : 'b' ,
187+ 'data' : < Map <String , Object ?>> [
188+ {
189+ 'op_id' : '2' ,
190+ 'op' : 'PUT' ,
191+ 'object_type' : 'b' ,
192+ 'object_id' : '1' ,
193+ 'checksum' : 0 ,
194+ 'data' : {},
195+ }
196+ ],
197+ }
198+ });
199+
200+ // Wait for the operations to be inserted.
201+ while (raw.select ('SELECT * FROM ps_oplog;' ).length < 2 ) {
202+ await pumpEventQueue ();
203+ }
204+
205+ // The two buckets should have been inserted in a single transaction
206+ // because the messages were received in quick succession.
207+ expect (commits, 1 );
208+ });
209+ }
190210
191211 group ('partial sync' , () {
192212 test ('updates sync state incrementally' , () async {
@@ -287,6 +307,7 @@ void main() {
287307 });
288308 await database.waitForFirstSync (priority: BucketPriority (1 ));
289309 expect (database.currentStatus.hasSynced, isFalse);
310+ await syncClient.abort ();
290311
291312 final independentDb = factory .wrapRaw (raw, logger: ignoredLogger);
292313 addTearDown (independentDb.close);
@@ -491,7 +512,7 @@ void main() {
491512 }) async {
492513 await expectLater (
493514 status,
494- emits (isSyncStatus (
515+ emitsThrough (isSyncStatus (
495516 downloading: true ,
496517 downloadProgress: isSyncDownloadProgress (
497518 progress: total,
@@ -679,7 +700,6 @@ void main() {
679700 await checkProgress (progress (8 , 8 ), progress (10 , 14 ));
680701
681702 addCheckpointComplete (0 );
682- await checkProgress (progress (8 , 8 ), progress (10 , 14 ));
683703
684704 addDataLine ('b' , 4 );
685705 await checkProgress (progress (8 , 8 ), progress (14 , 14 ));
0 commit comments