@@ -15,9 +15,26 @@ import 'utils/in_memory_http.dart';
15
15
import 'utils/test_utils_impl.dart' ;
16
16
17
17
void 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) {
18
35
final ignoredLogger = Logger .detached ('powersync.test' )..level = Level .OFF ;
19
36
20
- group ('in-memory sync tests' , () {
37
+ group (name , () {
21
38
late final testUtils = TestUtils ();
22
39
23
40
late TestPowerSyncFactory factory ;
@@ -44,8 +61,7 @@ void main() {
44
61
expiresAt: DateTime .now (),
45
62
);
46
63
}, uploadData: (db) => uploadData (db)),
47
- options: const SyncOptions (retryDelay: Duration (milliseconds: 200 )),
48
- logger: logger,
64
+ options: options,
49
65
);
50
66
51
67
addTearDown (() async {
@@ -113,6 +129,7 @@ void main() {
113
129
});
114
130
await expectLater (
115
131
status, emits (isSyncStatus (downloading: false , hasSynced: true )));
132
+ await syncClient.abort ();
116
133
117
134
final independentDb = factory .wrapRaw (raw, logger: ignoredLogger);
118
135
addTearDown (independentDb.close);
@@ -128,65 +145,68 @@ void main() {
128
145
isTrue);
129
146
});
130
147
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 ();
148
152
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 ),
177
160
],
178
- }
161
+ )
179
162
});
163
+ await expectLater (status, emits (isSyncStatus (downloading: true )));
180
164
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++ );
185
167
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
+ }
190
210
191
211
group ('partial sync' , () {
192
212
test ('updates sync state incrementally' , () async {
@@ -287,6 +307,7 @@ void main() {
287
307
});
288
308
await database.waitForFirstSync (priority: BucketPriority (1 ));
289
309
expect (database.currentStatus.hasSynced, isFalse);
310
+ await syncClient.abort ();
290
311
291
312
final independentDb = factory .wrapRaw (raw, logger: ignoredLogger);
292
313
addTearDown (independentDb.close);
@@ -491,7 +512,7 @@ void main() {
491
512
}) async {
492
513
await expectLater (
493
514
status,
494
- emits (isSyncStatus (
515
+ emitsThrough (isSyncStatus (
495
516
downloading: true ,
496
517
downloadProgress: isSyncDownloadProgress (
497
518
progress: total,
@@ -679,7 +700,6 @@ void main() {
679
700
await checkProgress (progress (8 , 8 ), progress (10 , 14 ));
680
701
681
702
addCheckpointComplete (0 );
682
- await checkProgress (progress (8 , 8 ), progress (10 , 14 ));
683
703
684
704
addDataLine ('b' , 4 );
685
705
await checkProgress (progress (8 , 8 ), progress (14 , 14 ));
0 commit comments