@powersync/service-core-tests 0.0.0-dev-20260803144812 → 0.0.0-dev-20260929095716
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -5
- package/dist/test-utils/AbstractStreamTestContext.js +4 -3
- package/dist/test-utils/AbstractStreamTestContext.js.map +1 -1
- package/dist/test-utils/leased-storage.d.ts +9 -0
- package/dist/test-utils/leased-storage.js +53 -0
- package/dist/test-utils/leased-storage.js.map +1 -0
- package/dist/test-utils/storage-combinations.d.ts +13 -0
- package/dist/test-utils/storage-combinations.js +26 -0
- package/dist/test-utils/storage-combinations.js.map +1 -0
- package/dist/test-utils/test-utils-index.d.ts +2 -0
- package/dist/test-utils/test-utils-index.js +2 -0
- package/dist/test-utils/test-utils-index.js.map +1 -1
- package/dist/tests/register-compacting-tests.js +16 -15
- package/dist/tests/register-compacting-tests.js.map +1 -1
- package/dist/tests/register-data-storage-checkpoint-tests.js +47 -21
- package/dist/tests/register-data-storage-checkpoint-tests.js.map +1 -1
- package/dist/tests/register-data-storage-data-tests.js +37 -24
- package/dist/tests/register-data-storage-data-tests.js.map +1 -1
- package/dist/tests/register-data-storage-parameter-tests.js +16 -15
- package/dist/tests/register-data-storage-parameter-tests.js.map +1 -1
- package/dist/tests/register-parameter-compacting-tests.js +6 -4
- package/dist/tests/register-parameter-compacting-tests.js.map +1 -1
- package/dist/tests/register-sync-tests.js +28 -26
- package/dist/tests/register-sync-tests.js.map +1 -1
- package/dist/tests/util.d.ts +6 -0
- package/dist/tests/util.js +12 -0
- package/dist/tests/util.js.map +1 -1
- package/package.json +4 -4
- package/src/test-utils/AbstractStreamTestContext.ts +4 -3
- package/src/test-utils/leased-storage.ts +58 -0
- package/src/test-utils/storage-combinations.ts +51 -0
- package/src/test-utils/test-utils-index.ts +2 -0
- package/src/tests/register-compacting-tests.ts +16 -15
- package/src/tests/register-data-storage-checkpoint-tests.ts +85 -56
- package/src/tests/register-data-storage-data-tests.ts +41 -24
- package/src/tests/register-data-storage-parameter-tests.ts +16 -15
- package/src/tests/register-parameter-compacting-tests.ts +6 -4
- package/src/tests/register-sync-tests.ts +28 -26
- package/src/tests/util.ts +13 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
updateSyncRulesFromYaml
|
|
9
9
|
} from '@powersync/service-core';
|
|
10
10
|
import { describe, expect, test } from 'vitest';
|
|
11
|
+
import { getTestStorage } from '../test-utils/leased-storage.js';
|
|
11
12
|
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
12
13
|
import { bucketRequest } from '../test-utils/test-utils-index.js';
|
|
13
14
|
|
|
@@ -36,6 +37,21 @@ export function registerDataStorageDataTests(config: storage.TestStorageConfig)
|
|
|
36
37
|
const generateStorageFactory = config.factory;
|
|
37
38
|
const storageVersion = config.storageVersion ?? storage.CURRENT_STORAGE_VERSION;
|
|
38
39
|
|
|
40
|
+
test('releases test replication leases when leaving an await using scope', async () => {
|
|
41
|
+
{
|
|
42
|
+
await using factory = await generateStorageFactory();
|
|
43
|
+
const stream = await factory.updateSyncRules(
|
|
44
|
+
updateSyncRulesFromYaml('bucket_definitions: {}', { storageVersion })
|
|
45
|
+
);
|
|
46
|
+
await getTestStorage(factory, stream);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await using replacement = await generateStorageFactory({ doNotClear: true });
|
|
50
|
+
const deploying = await replacement.getDeployingSyncConfig();
|
|
51
|
+
expect(deploying).not.toBeNull();
|
|
52
|
+
await getTestStorage(replacement, deploying!.replicationStream);
|
|
53
|
+
});
|
|
54
|
+
|
|
39
55
|
test('removing row', async () => {
|
|
40
56
|
await using factory = await generateStorageFactory();
|
|
41
57
|
const { stream: replicationStream, content: syncRules } = await test_utils.deploySyncRules(
|
|
@@ -50,7 +66,7 @@ bucket_definitions:
|
|
|
50
66
|
{ storageVersion }
|
|
51
67
|
)
|
|
52
68
|
);
|
|
53
|
-
const bucketStorage = factory
|
|
69
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
54
70
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
55
71
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
56
72
|
|
|
@@ -116,7 +132,7 @@ bucket_definitions:
|
|
|
116
132
|
{ storageVersion }
|
|
117
133
|
)
|
|
118
134
|
);
|
|
119
|
-
const bucketStorage = factory
|
|
135
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
120
136
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
121
137
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
122
138
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -181,7 +197,7 @@ bucket_definitions:
|
|
|
181
197
|
{ storageVersion }
|
|
182
198
|
)
|
|
183
199
|
);
|
|
184
|
-
const bucketStorage = factory
|
|
200
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
185
201
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
186
202
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
187
203
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -251,7 +267,7 @@ bucket_definitions:
|
|
|
251
267
|
}
|
|
252
268
|
)
|
|
253
269
|
);
|
|
254
|
-
const bucketStorage = factory
|
|
270
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
255
271
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
256
272
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
257
273
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -314,7 +330,7 @@ bucket_definitions:
|
|
|
314
330
|
}
|
|
315
331
|
)
|
|
316
332
|
);
|
|
317
|
-
const bucketStorage = factory
|
|
333
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
318
334
|
{
|
|
319
335
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
320
336
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
@@ -393,7 +409,7 @@ bucket_definitions:
|
|
|
393
409
|
}
|
|
394
410
|
)
|
|
395
411
|
);
|
|
396
|
-
const bucketStorage = factory
|
|
412
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
397
413
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
398
414
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
399
415
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -465,7 +481,7 @@ bucket_definitions:
|
|
|
465
481
|
}
|
|
466
482
|
)
|
|
467
483
|
);
|
|
468
|
-
const bucketStorage = factory
|
|
484
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
469
485
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
470
486
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
471
487
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -540,7 +556,7 @@ bucket_definitions:
|
|
|
540
556
|
{ storageVersion }
|
|
541
557
|
)
|
|
542
558
|
);
|
|
543
|
-
const bucketStorage = factory
|
|
559
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
544
560
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
545
561
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
546
562
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -671,7 +687,7 @@ bucket_definitions:
|
|
|
671
687
|
{ storageVersion }
|
|
672
688
|
)
|
|
673
689
|
);
|
|
674
|
-
const bucketStorage = factory
|
|
690
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
675
691
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
676
692
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
677
693
|
|
|
@@ -835,7 +851,7 @@ bucket_definitions:
|
|
|
835
851
|
}
|
|
836
852
|
)
|
|
837
853
|
);
|
|
838
|
-
const bucketStorage = factory
|
|
854
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
839
855
|
|
|
840
856
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
841
857
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id', 'description'], config);
|
|
@@ -949,7 +965,7 @@ bucket_definitions:
|
|
|
949
965
|
}
|
|
950
966
|
)
|
|
951
967
|
);
|
|
952
|
-
const bucketStorage = factory
|
|
968
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
953
969
|
|
|
954
970
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
955
971
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id', 'description'], config);
|
|
@@ -1053,7 +1069,7 @@ bucket_definitions:
|
|
|
1053
1069
|
}
|
|
1054
1070
|
)
|
|
1055
1071
|
);
|
|
1056
|
-
const bucketStorage = factory
|
|
1072
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1057
1073
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1058
1074
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1059
1075
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -1167,7 +1183,7 @@ bucket_definitions:
|
|
|
1167
1183
|
}
|
|
1168
1184
|
)
|
|
1169
1185
|
);
|
|
1170
|
-
const bucketStorage = factory
|
|
1186
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1171
1187
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1172
1188
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1173
1189
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -1267,7 +1283,7 @@ bucket_definitions:
|
|
|
1267
1283
|
{ storageVersion }
|
|
1268
1284
|
)
|
|
1269
1285
|
);
|
|
1270
|
-
const bucketStorage = factory
|
|
1286
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1271
1287
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1272
1288
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1273
1289
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -1458,14 +1474,15 @@ bucket_definitions:
|
|
|
1458
1474
|
test('empty storage metrics', async () => {
|
|
1459
1475
|
await using f = await generateStorageFactory({ dropAll: true });
|
|
1460
1476
|
const metrics = await f.getStorageMetrics();
|
|
1461
|
-
expect(metrics).
|
|
1477
|
+
expect(metrics).toMatchObject({
|
|
1462
1478
|
operations_size_bytes: 0,
|
|
1463
1479
|
parameters_size_bytes: 0,
|
|
1464
|
-
replication_size_bytes: 0
|
|
1480
|
+
replication_size_bytes: 0,
|
|
1481
|
+
object_storage_size_bytes: 0
|
|
1465
1482
|
});
|
|
1466
1483
|
|
|
1467
1484
|
const r = await f.configureSyncRules(updateSyncRulesFromYaml('bucket_definitions: {}'));
|
|
1468
|
-
const storage = f
|
|
1485
|
+
const storage = await getTestStorage(f, r.persisted_sync_rules!);
|
|
1469
1486
|
await using writer = await storage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1470
1487
|
await writer.markAllSnapshotDone('1/0');
|
|
1471
1488
|
await writer.keepalive('1/0');
|
|
@@ -1494,7 +1511,7 @@ bucket_definitions:
|
|
|
1494
1511
|
}
|
|
1495
1512
|
)
|
|
1496
1513
|
);
|
|
1497
|
-
const bucketStorage = factory
|
|
1514
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1498
1515
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1499
1516
|
|
|
1500
1517
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config, 1);
|
|
@@ -1546,7 +1563,7 @@ bucket_definitions:
|
|
|
1546
1563
|
}
|
|
1547
1564
|
)
|
|
1548
1565
|
);
|
|
1549
|
-
const bucketStorage = factory
|
|
1566
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1550
1567
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1551
1568
|
|
|
1552
1569
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
@@ -1588,7 +1605,7 @@ bucket_definitions:
|
|
|
1588
1605
|
{ storageVersion }
|
|
1589
1606
|
)
|
|
1590
1607
|
);
|
|
1591
|
-
const bucketStorage = factory
|
|
1608
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1592
1609
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1593
1610
|
await writer.markAllSnapshotDone('1/1');
|
|
1594
1611
|
await writer.commit('1/1');
|
|
@@ -1627,7 +1644,7 @@ bucket_definitions:
|
|
|
1627
1644
|
}
|
|
1628
1645
|
)
|
|
1629
1646
|
);
|
|
1630
|
-
const bucketStorage = factory
|
|
1647
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1631
1648
|
await using writer1 = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1632
1649
|
await using writer2 = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1633
1650
|
const sourceTable = await test_utils.resolveTestTable(writer2, 'test', ['id'], config);
|
|
@@ -1678,7 +1695,7 @@ bucket_definitions:
|
|
|
1678
1695
|
}
|
|
1679
1696
|
)
|
|
1680
1697
|
);
|
|
1681
|
-
const bucketStorage = factory
|
|
1698
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1682
1699
|
|
|
1683
1700
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1684
1701
|
const result1 = await writer.commit('1/1', { createEmptyCheckpoints: false });
|
|
@@ -1731,7 +1748,7 @@ bucket_definitions:
|
|
|
1731
1748
|
}
|
|
1732
1749
|
)
|
|
1733
1750
|
);
|
|
1734
|
-
const bucketStorage = factory
|
|
1751
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1735
1752
|
await using snapshotWriter = await bucketStorage.createWriter({
|
|
1736
1753
|
...test_utils.BATCH_OPTIONS,
|
|
1737
1754
|
skipExistingRows: true
|
|
@@ -1802,7 +1819,7 @@ bucket_definitions:
|
|
|
1802
1819
|
}
|
|
1803
1820
|
)
|
|
1804
1821
|
);
|
|
1805
|
-
const bucketStorage = factory
|
|
1822
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1806
1823
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1807
1824
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1808
1825
|
await writer.markAllSnapshotDone('1/1');
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
UnscopedParameterLookup
|
|
8
8
|
} from '@powersync/service-sync-rules';
|
|
9
9
|
import { expect, test } from 'vitest';
|
|
10
|
+
import { getTestStorage } from '../test-utils/leased-storage.js';
|
|
10
11
|
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
11
12
|
import { bucketRequest } from '../test-utils/test-utils-index.js';
|
|
12
13
|
|
|
@@ -41,7 +42,7 @@ bucket_definitions:
|
|
|
41
42
|
}
|
|
42
43
|
)
|
|
43
44
|
);
|
|
44
|
-
const bucketStorage = factory
|
|
45
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
45
46
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
46
47
|
|
|
47
48
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -108,7 +109,7 @@ bucket_definitions:
|
|
|
108
109
|
}
|
|
109
110
|
)
|
|
110
111
|
);
|
|
111
|
-
const bucketStorage = factory
|
|
112
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
112
113
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
113
114
|
|
|
114
115
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -180,7 +181,7 @@ bucket_definitions:
|
|
|
180
181
|
{ storageVersion }
|
|
181
182
|
)
|
|
182
183
|
);
|
|
183
|
-
const bucketStorage = factory
|
|
184
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
184
185
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
185
186
|
|
|
186
187
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -268,7 +269,7 @@ bucket_definitions:
|
|
|
268
269
|
}
|
|
269
270
|
)
|
|
270
271
|
);
|
|
271
|
-
const bucketStorage = factory
|
|
272
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
272
273
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
273
274
|
|
|
274
275
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -337,7 +338,7 @@ bucket_definitions:
|
|
|
337
338
|
}
|
|
338
339
|
)
|
|
339
340
|
);
|
|
340
|
-
const bucketStorage = factory
|
|
341
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
341
342
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
342
343
|
|
|
343
344
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -407,7 +408,7 @@ bucket_definitions:
|
|
|
407
408
|
)
|
|
408
409
|
);
|
|
409
410
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
410
|
-
const bucketStorage = factory
|
|
411
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
411
412
|
|
|
412
413
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
413
414
|
const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', ['id'], config);
|
|
@@ -466,7 +467,7 @@ bucket_definitions:
|
|
|
466
467
|
)
|
|
467
468
|
);
|
|
468
469
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
469
|
-
const bucketStorage = factory
|
|
470
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
470
471
|
|
|
471
472
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
472
473
|
const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
|
|
@@ -561,7 +562,7 @@ bucket_definitions:
|
|
|
561
562
|
)
|
|
562
563
|
);
|
|
563
564
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
564
|
-
const bucketStorage = factory
|
|
565
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
565
566
|
|
|
566
567
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
567
568
|
const workspaceTable = await test_utils.resolveTestTable(writer, 'workspace', undefined, config);
|
|
@@ -662,7 +663,7 @@ bucket_definitions:
|
|
|
662
663
|
}
|
|
663
664
|
)
|
|
664
665
|
);
|
|
665
|
-
const bucketStorage = factory
|
|
666
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
666
667
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
667
668
|
|
|
668
669
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -716,7 +717,7 @@ bucket_definitions:
|
|
|
716
717
|
}
|
|
717
718
|
)
|
|
718
719
|
);
|
|
719
|
-
const syncBucketStorage = bucketStorageFactory
|
|
720
|
+
const syncBucketStorage = await getTestStorage(bucketStorageFactory, syncRules);
|
|
720
721
|
|
|
721
722
|
const parsedSchema1 = syncBucketStorage.getParsedSyncRules({
|
|
722
723
|
defaultSchema: 'public'
|
|
@@ -754,7 +755,7 @@ streams:
|
|
|
754
755
|
WHERE data.foo = param.bar AND param.baz = auth.user_id()
|
|
755
756
|
`)
|
|
756
757
|
);
|
|
757
|
-
const bucketStorage = factory
|
|
758
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
758
759
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
759
760
|
|
|
760
761
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -826,7 +827,7 @@ streams:
|
|
|
826
827
|
}
|
|
827
828
|
)
|
|
828
829
|
);
|
|
829
|
-
const bucketStorage = factory
|
|
830
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
830
831
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
831
832
|
|
|
832
833
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -876,7 +877,7 @@ streams:
|
|
|
876
877
|
WHERE a.x = x.value AND y.value = auth.user_id()
|
|
877
878
|
`)
|
|
878
879
|
);
|
|
879
|
-
const bucketStorage = factory
|
|
880
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
880
881
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
881
882
|
|
|
882
883
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -1005,7 +1006,7 @@ streams:
|
|
|
1005
1006
|
query: SELECT * FROM b WHERE p IN (SELECT id FROM param_b WHERE u = auth.user_id())
|
|
1006
1007
|
`)
|
|
1007
1008
|
);
|
|
1008
|
-
const bucketStorage = factory
|
|
1009
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1009
1010
|
const parsedSyncRules = syncRules.parsed(test_utils.PARSE_OPTIONS);
|
|
1010
1011
|
const hydrationState = parsedSyncRules.hydrationState;
|
|
1011
1012
|
const [parsedSyncConfig] = parsedSyncRules.syncConfigs;
|
|
@@ -1106,7 +1107,7 @@ streams:
|
|
|
1106
1107
|
}
|
|
1107
1108
|
)
|
|
1108
1109
|
);
|
|
1109
|
-
const bucketStorage = factory
|
|
1110
|
+
const bucketStorage = await getTestStorage(factory, replicationStream);
|
|
1110
1111
|
const sync_rules = syncRules.parsed(test_utils.PARSE_OPTIONS).hydratedSyncConfig;
|
|
1111
1112
|
|
|
1112
1113
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
2
2
|
import { ScopedParameterLookup } from '@powersync/service-sync-rules';
|
|
3
3
|
import { expect, test } from 'vitest';
|
|
4
|
+
import { getTestStorage } from '../test-utils/leased-storage.js';
|
|
4
5
|
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
6
|
+
import { compactActive } from './util.js';
|
|
5
7
|
|
|
6
8
|
export function registerParameterCompactTests(config: storage.TestStorageConfig) {
|
|
7
9
|
const generateStorageFactory = config.factory;
|
|
@@ -16,7 +18,7 @@ bucket_definitions:
|
|
|
16
18
|
data: []
|
|
17
19
|
`)
|
|
18
20
|
);
|
|
19
|
-
const bucketStorage = factory
|
|
21
|
+
const bucketStorage = await getTestStorage(factory, syncRules);
|
|
20
22
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
21
23
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
22
24
|
|
|
@@ -74,7 +76,7 @@ bucket_definitions:
|
|
|
74
76
|
expect(parameters2).toEqual([]);
|
|
75
77
|
|
|
76
78
|
const statsBefore = await bucketStorage.factory.getStorageMetrics();
|
|
77
|
-
await
|
|
79
|
+
await compactActive(factory, { compactParameterData: true });
|
|
78
80
|
|
|
79
81
|
// Check consistency
|
|
80
82
|
const parameters1b = await checkpoint1.getParameterSets([lookup], 1000);
|
|
@@ -98,7 +100,7 @@ bucket_definitions:
|
|
|
98
100
|
data: []
|
|
99
101
|
`)
|
|
100
102
|
);
|
|
101
|
-
const bucketStorage = factory
|
|
103
|
+
const bucketStorage = await getTestStorage(factory, syncRules);
|
|
102
104
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
103
105
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
104
106
|
|
|
@@ -154,7 +156,7 @@ bucket_definitions:
|
|
|
154
156
|
expect(parameters1).toEqual([]);
|
|
155
157
|
|
|
156
158
|
const statsBefore = await bucketStorage.factory.getStorageMetrics();
|
|
157
|
-
await
|
|
159
|
+
await compactActive(factory, { compactParameterData: true, compactParameterCacheLimit: cacheLimit });
|
|
158
160
|
|
|
159
161
|
// Check consistency
|
|
160
162
|
const parameters1b = await checkpoint1.getParameterSets([lookup], 1000);
|
|
@@ -13,8 +13,10 @@ import path from 'path';
|
|
|
13
13
|
import * as timers from 'timers/promises';
|
|
14
14
|
import { fileURLToPath } from 'url';
|
|
15
15
|
import { expect, test, vi } from 'vitest';
|
|
16
|
+
import { getTestStorage } from '../test-utils/leased-storage.js';
|
|
16
17
|
import * as test_utils from '../test-utils/test-utils-index.js';
|
|
17
18
|
import { bucketRequest, METRICS_HELPER } from '../test-utils/test-utils-index.js';
|
|
19
|
+
import { compactActive } from './util.js';
|
|
18
20
|
|
|
19
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
22
|
const __dirname = path.dirname(__filename);
|
|
@@ -69,7 +71,7 @@ export function registerSyncTests(
|
|
|
69
71
|
content: BASIC_SYNC_RULES
|
|
70
72
|
});
|
|
71
73
|
|
|
72
|
-
const bucketStorage = f
|
|
74
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
73
75
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
74
76
|
const sourceTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
75
77
|
|
|
@@ -132,7 +134,7 @@ bucket_definitions:
|
|
|
132
134
|
`
|
|
133
135
|
});
|
|
134
136
|
|
|
135
|
-
const bucketStorage = f
|
|
137
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
136
138
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
137
139
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
138
140
|
|
|
@@ -191,7 +193,7 @@ streams:
|
|
|
191
193
|
`
|
|
192
194
|
});
|
|
193
195
|
|
|
194
|
-
const bucketStorage = f
|
|
196
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
195
197
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
196
198
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
197
199
|
|
|
@@ -272,7 +274,7 @@ bucket_definitions:
|
|
|
272
274
|
`
|
|
273
275
|
});
|
|
274
276
|
|
|
275
|
-
const bucketStorage = f
|
|
277
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
276
278
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
277
279
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
278
280
|
const syncRulesContent = syncRules.syncConfigContent[0];
|
|
@@ -450,7 +452,7 @@ bucket_definitions:
|
|
|
450
452
|
`
|
|
451
453
|
});
|
|
452
454
|
|
|
453
|
-
const bucketStorage = f
|
|
455
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
454
456
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
455
457
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
456
458
|
|
|
@@ -584,7 +586,7 @@ bucket_definitions:
|
|
|
584
586
|
`
|
|
585
587
|
});
|
|
586
588
|
|
|
587
|
-
const bucketStorage = f
|
|
589
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
588
590
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
589
591
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
590
592
|
const syncRulesContent = syncRules.syncConfigContent[0];
|
|
@@ -760,7 +762,7 @@ bucket_definitions:
|
|
|
760
762
|
const syncRules = await updateSyncRules(f, {
|
|
761
763
|
content: BASIC_SYNC_RULES
|
|
762
764
|
});
|
|
763
|
-
const bucketStorage = f
|
|
765
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
764
766
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
765
767
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
766
768
|
|
|
@@ -823,7 +825,7 @@ bucket_definitions:
|
|
|
823
825
|
content: BASIC_SYNC_RULES
|
|
824
826
|
});
|
|
825
827
|
|
|
826
|
-
const bucketStorage = await f
|
|
828
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
827
829
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
828
830
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
829
831
|
|
|
@@ -868,7 +870,7 @@ bucket_definitions:
|
|
|
868
870
|
content: BASIC_SYNC_RULES
|
|
869
871
|
});
|
|
870
872
|
|
|
871
|
-
const bucketStorage = await f
|
|
873
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
872
874
|
|
|
873
875
|
const stream = sync.streamResponse({
|
|
874
876
|
syncContext,
|
|
@@ -895,7 +897,7 @@ bucket_definitions:
|
|
|
895
897
|
content: BASIC_SYNC_RULES
|
|
896
898
|
});
|
|
897
899
|
|
|
898
|
-
const bucketStorage = await f
|
|
900
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
899
901
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
900
902
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
901
903
|
// Activate
|
|
@@ -963,7 +965,7 @@ bucket_definitions:
|
|
|
963
965
|
`
|
|
964
966
|
});
|
|
965
967
|
|
|
966
|
-
const bucketStorage = await f
|
|
968
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
967
969
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
968
970
|
const usersTable = await test_utils.resolveTestTable(writer, 'users', ['id'], config, 1);
|
|
969
971
|
|
|
@@ -1029,7 +1031,7 @@ bucket_definitions:
|
|
|
1029
1031
|
`
|
|
1030
1032
|
});
|
|
1031
1033
|
|
|
1032
|
-
const bucketStorage = await f
|
|
1034
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
1033
1035
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1034
1036
|
const usersTable = await test_utils.resolveTestTable(writer, 'users', ['id'], config, 1);
|
|
1035
1037
|
const listsTable = await test_utils.resolveTestTable(writer, 'lists', ['id'], config, 2);
|
|
@@ -1104,7 +1106,7 @@ bucket_definitions:
|
|
|
1104
1106
|
`
|
|
1105
1107
|
});
|
|
1106
1108
|
|
|
1107
|
-
const bucketStorage = await f
|
|
1109
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
1108
1110
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1109
1111
|
const usersTable = await test_utils.resolveTestTable(writer, 'users', ['id'], config, 1);
|
|
1110
1112
|
const listsTable = await test_utils.resolveTestTable(writer, 'lists', ['id'], config, 2);
|
|
@@ -1174,7 +1176,7 @@ bucket_definitions:
|
|
|
1174
1176
|
content: BASIC_SYNC_RULES
|
|
1175
1177
|
});
|
|
1176
1178
|
|
|
1177
|
-
const bucketStorage = await f
|
|
1179
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
1178
1180
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1179
1181
|
// Activate
|
|
1180
1182
|
await writer.markAllSnapshotDone('0/0');
|
|
@@ -1214,7 +1216,7 @@ bucket_definitions:
|
|
|
1214
1216
|
content: BASIC_SYNC_RULES
|
|
1215
1217
|
});
|
|
1216
1218
|
|
|
1217
|
-
const bucketStorage = await f
|
|
1219
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
1218
1220
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1219
1221
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1220
1222
|
|
|
@@ -1305,9 +1307,10 @@ bucket_definitions:
|
|
|
1305
1307
|
content: BASIC_SYNC_RULES
|
|
1306
1308
|
});
|
|
1307
1309
|
|
|
1308
|
-
const bucketStorage = await f
|
|
1310
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
1309
1311
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1310
1312
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1313
|
+
const bucket = bucketRequest(syncRules.syncConfigContent[0], 'mybucket[]').bucket;
|
|
1311
1314
|
|
|
1312
1315
|
await writer.markAllSnapshotDone('0/1');
|
|
1313
1316
|
await writer.save({
|
|
@@ -1386,10 +1389,7 @@ bucket_definitions:
|
|
|
1386
1389
|
|
|
1387
1390
|
await writer.commit('0/2');
|
|
1388
1391
|
|
|
1389
|
-
await
|
|
1390
|
-
minBucketChanges: 1,
|
|
1391
|
-
minChangeRatio: 0
|
|
1392
|
-
});
|
|
1392
|
+
await compactActive(f, { compactBuckets: [bucket] });
|
|
1393
1393
|
|
|
1394
1394
|
const lines2 = await getCheckpointLines(iter, { consume: true });
|
|
1395
1395
|
|
|
@@ -1467,9 +1467,10 @@ bucket_definitions:
|
|
|
1467
1467
|
`
|
|
1468
1468
|
});
|
|
1469
1469
|
|
|
1470
|
-
const bucketStorage = await f
|
|
1470
|
+
const bucketStorage = await await getTestStorage(f, syncRules);
|
|
1471
1471
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1472
1472
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config);
|
|
1473
|
+
const highPriorityBucket = bucketRequest(syncRules.syncConfigContent[0], 'high_priority[]').bucket;
|
|
1473
1474
|
|
|
1474
1475
|
await writer.markAllSnapshotDone('0/1');
|
|
1475
1476
|
await writer.save({
|
|
@@ -1552,9 +1553,10 @@ bucket_definitions:
|
|
|
1552
1553
|
});
|
|
1553
1554
|
await writer.commit('0/2');
|
|
1554
1555
|
|
|
1555
|
-
await
|
|
1556
|
-
|
|
1557
|
-
|
|
1556
|
+
await compactActive(f, {
|
|
1557
|
+
// Explicitly compact the high-priority bucket: V3 schedules background
|
|
1558
|
+
// compaction, while this test needs compaction at this exact point.
|
|
1559
|
+
compactBuckets: [highPriorityBucket]
|
|
1558
1560
|
});
|
|
1559
1561
|
|
|
1560
1562
|
const lines = await getCheckpointLines(iter, { consume: true });
|
|
@@ -1592,7 +1594,7 @@ bucket_definitions:
|
|
|
1592
1594
|
content: BASIC_SYNC_RULES
|
|
1593
1595
|
});
|
|
1594
1596
|
|
|
1595
|
-
const bucketStorage = f
|
|
1597
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
1596
1598
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1597
1599
|
|
|
1598
1600
|
await writer.markAllSnapshotDone('0/1');
|
|
@@ -1678,7 +1680,7 @@ config:
|
|
|
1678
1680
|
const syncRules = await updateSyncRules(f, {
|
|
1679
1681
|
content: rules[i]
|
|
1680
1682
|
});
|
|
1681
|
-
const bucketStorage = f
|
|
1683
|
+
const bucketStorage = await getTestStorage(f, syncRules);
|
|
1682
1684
|
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
1683
1685
|
|
|
1684
1686
|
const testTable = await test_utils.resolveTestTable(writer, 'test', ['id'], config, i + 1);
|
package/src/tests/util.ts
CHANGED
|
@@ -8,6 +8,19 @@ import {
|
|
|
8
8
|
} from '@powersync/service-sync-rules';
|
|
9
9
|
import { bucketRequest } from '../test-utils/general-utils.js';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Resolve storage again after test writes activate the sync config. The storage
|
|
13
|
+
* instance used by the writer retains its original PROCESSING stream snapshot,
|
|
14
|
+
* while compact() expects an instance constructed with the current state.
|
|
15
|
+
*/
|
|
16
|
+
export async function compactActive(factory: storage.BucketStorageFactory, options: storage.CompactOptions) {
|
|
17
|
+
const active = await factory.getActiveSyncConfig();
|
|
18
|
+
if (active == null) {
|
|
19
|
+
throw new Error('Expected an active sync config before compacting');
|
|
20
|
+
}
|
|
21
|
+
await active.storage.compact(options);
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
export function bucketRequestMap(
|
|
12
25
|
syncRules: storage.PersistedSyncConfigContent,
|
|
13
26
|
buckets: Iterable<readonly [string, bigint]>
|