@@ -16,9 +16,26 @@ import 'utils/in_memory_http.dart';
16
16
import 'utils/test_utils_impl.dart' ;
17
17
18
18
void main () {
19
+ _declareTests (
20
+ 'dart sync client' ,
21
+ SyncOptions (
22
+ // ignore: deprecated_member_use_from_same_package
23
+ syncImplementation: SyncClientImplementation .dart,
24
+ ),
25
+ );
26
+
27
+ _declareTests (
28
+ 'rust sync client' ,
29
+ SyncOptions (
30
+ syncImplementation: SyncClientImplementation .rust,
31
+ ),
32
+ );
33
+ }
34
+
35
+ void _declareTests (String name, SyncOptions options) {
19
36
final ignoredLogger = Logger .detached ('powersync.test' )..level = Level .OFF ;
20
37
21
- group ('in-memory sync tests' , () {
38
+ group (name , () {
22
39
late final testUtils = TestUtils ();
23
40
24
41
late TestPowerSyncFactory factory ;
@@ -44,6 +61,7 @@ void main() {
44
61
expiresAt: DateTime .now (),
45
62
);
46
63
}, uploadData: (db) => uploadData (db)),
64
+ options: options,
47
65
);
48
66
}
49
67
@@ -107,6 +125,7 @@ void main() {
107
125
});
108
126
await expectLater (
109
127
status, emits (isSyncStatus (downloading: false , hasSynced: true )));
128
+ await syncClient.abort ();
110
129
111
130
final independentDb = factory .wrapRaw (raw, logger: ignoredLogger);
112
131
addTearDown (independentDb.close);
@@ -122,65 +141,68 @@ void main() {
122
141
isTrue);
123
142
});
124
143
125
- test ('can save independent buckets in same transaction' , () async {
126
- final status = await waitForConnection ();
127
-
128
- syncService.addLine ({
129
- 'checkpoint' : Checkpoint (
130
- lastOpId: '0' ,
131
- writeCheckpoint: null ,
132
- checksums: [
133
- BucketChecksum (bucket: 'a' , checksum: 0 , priority: 3 ),
134
- BucketChecksum (bucket: 'b' , checksum: 0 , priority: 3 ),
135
- ],
136
- )
137
- });
138
- await expectLater (status, emits (isSyncStatus (downloading: true )));
139
-
140
- var commits = 0 ;
141
- raw.commits.listen ((_) => commits++ );
144
+ // ignore: deprecated_member_use_from_same_package
145
+ if (options.syncImplementation == SyncClientImplementation .dart) {
146
+ test ('can save independent buckets in same transaction' , () async {
147
+ final status = await waitForConnection ();
142
148
143
- syncService
144
- ..addLine ({
145
- 'data' : {
146
- 'bucket' : 'a' ,
147
- 'data' : < Map <String , Object ?>> [
148
- {
149
- 'op_id' : '1' ,
150
- 'op' : 'PUT' ,
151
- 'object_type' : 'a' ,
152
- 'object_id' : '1' ,
153
- 'checksum' : 0 ,
154
- 'data' : {},
155
- }
156
- ],
157
- }
158
- })
159
- ..addLine ({
160
- 'data' : {
161
- 'bucket' : 'b' ,
162
- 'data' : < Map <String , Object ?>> [
163
- {
164
- 'op_id' : '2' ,
165
- 'op' : 'PUT' ,
166
- 'object_type' : 'b' ,
167
- 'object_id' : '1' ,
168
- 'checksum' : 0 ,
169
- 'data' : {},
170
- }
149
+ syncService.addLine ({
150
+ 'checkpoint' : Checkpoint (
151
+ lastOpId: '0' ,
152
+ writeCheckpoint: null ,
153
+ checksums: [
154
+ BucketChecksum (bucket: 'a' , checksum: 0 , priority: 3 ),
155
+ BucketChecksum (bucket: 'b' , checksum: 0 , priority: 3 ),
171
156
],
172
- }
157
+ )
173
158
});
159
+ await expectLater (status, emits (isSyncStatus (downloading: true )));
174
160
175
- // Wait for the operations to be inserted.
176
- while (raw.select ('SELECT * FROM ps_oplog;' ).length < 2 ) {
177
- await pumpEventQueue ();
178
- }
161
+ var commits = 0 ;
162
+ raw.commits.listen ((_) => commits++ );
179
163
180
- // The two buckets should have been inserted in a single transaction
181
- // because the messages were received in quick succession.
182
- expect (commits, 1 );
183
- });
164
+ syncService
165
+ ..addLine ({
166
+ 'data' : {
167
+ 'bucket' : 'a' ,
168
+ 'data' : < Map <String , Object ?>> [
169
+ {
170
+ 'op_id' : '1' ,
171
+ 'op' : 'PUT' ,
172
+ 'object_type' : 'a' ,
173
+ 'object_id' : '1' ,
174
+ 'checksum' : 0 ,
175
+ 'data' : {},
176
+ }
177
+ ],
178
+ }
179
+ })
180
+ ..addLine ({
181
+ 'data' : {
182
+ 'bucket' : 'b' ,
183
+ 'data' : < Map <String , Object ?>> [
184
+ {
185
+ 'op_id' : '2' ,
186
+ 'op' : 'PUT' ,
187
+ 'object_type' : 'b' ,
188
+ 'object_id' : '1' ,
189
+ 'checksum' : 0 ,
190
+ 'data' : {},
191
+ }
192
+ ],
193
+ }
194
+ });
195
+
196
+ // Wait for the operations to be inserted.
197
+ while (raw.select ('SELECT * FROM ps_oplog;' ).length < 2 ) {
198
+ await pumpEventQueue ();
199
+ }
200
+
201
+ // The two buckets should have been inserted in a single transaction
202
+ // because the messages were received in quick succession.
203
+ expect (commits, 1 );
204
+ });
205
+ }
184
206
185
207
group ('partial sync' , () {
186
208
test ('updates sync state incrementally' , () async {
@@ -281,6 +303,7 @@ void main() {
281
303
});
282
304
await database.waitForFirstSync (priority: BucketPriority (1 ));
283
305
expect (database.currentStatus.hasSynced, isFalse);
306
+ await syncClient.abort ();
284
307
285
308
final independentDb = factory .wrapRaw (raw, logger: ignoredLogger);
286
309
addTearDown (independentDb.close);
@@ -485,7 +508,7 @@ void main() {
485
508
}) async {
486
509
await expectLater (
487
510
status,
488
- emits (isSyncStatus (
511
+ emitsThrough (isSyncStatus (
489
512
downloading: true ,
490
513
downloadProgress: isSyncDownloadProgress (
491
514
progress: total,
@@ -644,7 +667,6 @@ void main() {
644
667
await checkProgress (progress (8 , 8 ), progress (10 , 14 ));
645
668
646
669
addCheckpointComplete (0 );
647
- await checkProgress (progress (8 , 8 ), progress (10 , 14 ));
648
670
649
671
addDataLine ('b' , 4 );
650
672
await checkProgress (progress (8 , 8 ), progress (14 , 14 ));
0 commit comments