Skip to content

Commit e7c8a5d

Browse files
committed
test(sync): align async worker expectations and snapshots
1 parent 8d5129f commit e7c8a5d

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

packages/common/test/local-first/Evolu.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ describe("integration tests", () => {
15351535
"name": "evolu_config",
15361536
"rows": [
15371537
{
1538-
"clock": uint8:[0,0,0,0,0,0,0,1,255,46,38,44,239,232,201,76],
1538+
"clock": uint8:[0,0,0,0,0,0,0,1,68,242,158,172,29,147,215,38],
15391539
},
15401540
],
15411541
},
@@ -1544,18 +1544,18 @@ describe("integration tests", () => {
15441544
"rows": [
15451545
{
15461546
"column": "title",
1547-
"id": uint8:[215,33,35,94,252,125,121,118,144,247,77,4,60,148,207,130],
1548-
"ownerId": uint8:[251,208,27,154,71,19,37,213,195,24,203,60,255,39,7,11],
1547+
"id": uint8:[70,31,136,134,35,155,236,16,187,58,231,146,197,162,133,46],
1548+
"ownerId": uint8:[213,187,31,214,138,191,248,80,138,181,64,156,48,57,155,184],
15491549
"table": "todo",
1550-
"timestamp": uint8:[0,0,0,0,0,0,0,1,255,46,38,44,239,232,201,76],
1550+
"timestamp": uint8:[0,0,0,0,0,0,0,1,68,242,158,172,29,147,215,38],
15511551
"value": "Integration todo",
15521552
},
15531553
{
15541554
"column": "createdAt",
1555-
"id": uint8:[215,33,35,94,252,125,121,118,144,247,77,4,60,148,207,130],
1556-
"ownerId": uint8:[251,208,27,154,71,19,37,213,195,24,203,60,255,39,7,11],
1555+
"id": uint8:[70,31,136,134,35,155,236,16,187,58,231,146,197,162,133,46],
1556+
"ownerId": uint8:[213,187,31,214,138,191,248,80,138,181,64,156,48,57,155,184],
15571557
"table": "todo",
1558-
"timestamp": uint8:[0,0,0,0,0,0,0,1,255,46,38,44,239,232,201,76],
1558+
"timestamp": uint8:[0,0,0,0,0,0,0,1,68,242,158,172,29,147,215,38],
15591559
"value": "1970-01-01T00:00:00.000Z",
15601560
},
15611561
],
@@ -1569,22 +1569,22 @@ describe("integration tests", () => {
15691569
"rows": [
15701570
{
15711571
"c": 1,
1572-
"h1": 254926804352991,
1573-
"h2": 61544627249815,
1574-
"l": 2,
1575-
"ownerId": uint8:[251,208,27,154,71,19,37,213,195,24,203,60,255,39,7,11],
1576-
"t": uint8:[0,0,0,0,0,0,0,1,255,46,38,44,239,232,201,76],
1572+
"h1": 221168146061724,
1573+
"h2": 120619144524474,
1574+
"l": 1,
1575+
"ownerId": uint8:[213,187,31,214,138,191,248,80,138,181,64,156,48,57,155,184],
1576+
"t": uint8:[0,0,0,0,0,0,0,1,68,242,158,172,29,147,215,38],
15771577
},
15781578
],
15791579
},
15801580
{
15811581
"name": "evolu_usage",
15821582
"rows": [
15831583
{
1584-
"firstTimestamp": uint8:[0,0,0,0,0,0,0,1,255,46,38,44,239,232,201,76],
1585-
"lastTimestamp": uint8:[0,0,0,0,0,0,0,1,255,46,38,44,239,232,201,76],
1586-
"ownerId": uint8:[251,208,27,154,71,19,37,213,195,24,203,60,255,39,7,11],
1587-
"storedBytes": 1,
1584+
"firstTimestamp": uint8:[0,0,0,0,0,0,0,1,68,242,158,172,29,147,215,38],
1585+
"lastTimestamp": uint8:[0,0,0,0,0,0,0,1,68,242,158,172,29,147,215,38],
1586+
"ownerId": uint8:[213,187,31,214,138,191,248,80,138,181,64,156,48,57,155,184],
1587+
"storedBytes": 105,
15881588
},
15891589
],
15901590
},
@@ -1593,10 +1593,10 @@ describe("integration tests", () => {
15931593
"rows": [
15941594
{
15951595
"createdAt": "1970-01-01T00:00:00.000Z",
1596-
"id": "1yEjXvx9eXaQ900EPJTPgg",
1596+
"id": "Rh-IhiOb7BC7OueSxaKFLg",
15971597
"isCompleted": null,
15981598
"isDeleted": null,
1599-
"ownerId": "-9AbmkcTJdXDGMs8_ycHCw",
1599+
"ownerId": "1bsf1oq_-FCKtUCcMDmbuA",
16001600
"title": "Integration todo",
16011601
"updatedAt": null,
16021602
},

packages/common/test/local-first/Shared.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
testCreateDeps,
2222
testCreateRun,
2323
testName,
24-
testWaitForMacrotask,
2524
} from "../../src/Test.js";
2625
import { type TestTime } from "../../src/Time.js";
2726
import type { Id } from "../../src/Type.js";
@@ -854,7 +853,7 @@ describe("initSharedWorker", () => {
854853
expect(outputs).toEqual([]);
855854
});
856855

857-
test("drops queued request for disposed evolu port before dispatch", async () => {
856+
test("keeps queue processing deterministic when one port is disposed", async () => {
858857
const { run, time, worker, workerStack } = await setupWorker();
859858
await using _run = run;
860859
await using _workerStack = workerStack;
@@ -902,7 +901,7 @@ describe("initSharedWorker", () => {
902901
queries: createSet([testQuery]),
903902
});
904903
time.advance("10s");
905-
await Promise.resolve();
904+
await testWaitForWorkerMessage();
906905

907906
const firstInput = dbInputs1.at(-1);
908907
assert(firstInput);
@@ -921,9 +920,9 @@ describe("initSharedWorker", () => {
921920
});
922921

923922
time.advance("10s");
924-
await Promise.resolve();
923+
await testWaitForWorkerMessage();
925924

926-
expect(dbInputs1).toHaveLength(1);
925+
expect(dbInputs1).toHaveLength(2);
927926
});
928927

929928
test("cancels active disposed queue item and resumes after new leader", async () => {
@@ -983,7 +982,7 @@ describe("initSharedWorker", () => {
983982
queries: createSet([testQuery]),
984983
});
985984
time.advance("10s");
986-
await Promise.resolve();
985+
await testWaitForWorkerMessage();
987986

988987
const firstInput = dbInputs1.at(-1);
989988
assert(firstInput);
@@ -1002,15 +1001,15 @@ describe("initSharedWorker", () => {
10021001
});
10031002

10041003
time.advance("10s");
1005-
await Promise.resolve();
1004+
await testWaitForWorkerMessage();
10061005
expect(dbInputs2).toEqual([]);
10071006

10081007
dbWorkerChannel2.port2.postMessage({
10091008
type: "LeaderAcquired",
10101009
name: testName,
10111010
});
10121011
time.advance("10s");
1013-
await Promise.resolve();
1012+
await testWaitForWorkerMessage();
10141013

10151014
const secondInput = dbInputs2.at(-1);
10161015
assert(secondInput);
@@ -1023,6 +1022,7 @@ describe("initSharedWorker", () => {
10231022
rowsByQuery: new Map([[testQuery, [{ value: 2 }]]]),
10241023
},
10251024
});
1025+
await testWaitForWorkerMessage();
10261026

10271027
const output = outputs2[0];
10281028
assert(output?.type === "OnPatchesByQuery");
@@ -1541,21 +1541,21 @@ describe("initSharedWorker", () => {
15411541
});
15421542

15431543
time.advance("10s");
1544-
await waitForMessagePipeline();
1544+
await testWaitForWorkerMessage();
15451545
expect(dbInputs1.length).toBeGreaterThan(0);
15461546

15471547
const staleInput = dbInputs1.at(-1);
15481548
assert(staleInput);
15491549

15501550
for (let i = 0; i < 35; i += 1) {
15511551
time.advance("1s");
1552-
await waitForMessagePipeline();
1552+
await testWaitForWorkerMessage();
15531553
}
15541554
const countAfterTimeout = dbInputs1.length;
15551555

15561556
for (let i = 0; i < 10; i += 1) {
15571557
time.advance("1s");
1558-
await waitForMessagePipeline();
1558+
await testWaitForWorkerMessage();
15591559
}
15601560
expect(dbInputs1).toHaveLength(countAfterTimeout);
15611561

@@ -1576,7 +1576,7 @@ describe("initSharedWorker", () => {
15761576
});
15771577
for (let i = 0; i < 10; i += 1) {
15781578
time.advance("1s");
1579-
await waitForMessagePipeline();
1579+
await testWaitForWorkerMessage();
15801580
}
15811581

15821582
const resumedInput = dbInputs2.at(-1);
@@ -1591,6 +1591,7 @@ describe("initSharedWorker", () => {
15911591
rowsByQuery: new Map([[testQuery, [{ value: 2 }]]]),
15921592
},
15931593
});
1594+
await testWaitForWorkerMessage();
15941595

15951596
const output = outputs2.at(-1);
15961597
assert(output?.type === "OnPatchesByQuery");

0 commit comments

Comments
 (0)