rivetkit 2.1.3 → 2.1.5
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/dist/browser/client.d.ts +11 -0
- package/dist/browser/client.js +1 -1
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/inspector.tar.gz +0 -0
- package/dist/tsup/{chunk-OAOF23ZY.js → chunk-2OK7S6QF.js} +2 -2
- package/dist/tsup/{chunk-5AZ6UPEF.cjs → chunk-7WF2QSIC.cjs} +24 -20
- package/dist/tsup/chunk-7WF2QSIC.cjs.map +1 -0
- package/dist/tsup/{chunk-IJAGZS57.cjs → chunk-D2SPAJVT.cjs} +30 -30
- package/dist/tsup/{chunk-IJAGZS57.cjs.map → chunk-D2SPAJVT.cjs.map} +1 -1
- package/dist/tsup/{chunk-YET3IZD6.js → chunk-EIATSBYZ.js} +2 -2
- package/dist/tsup/{chunk-YET3IZD6.js.map → chunk-EIATSBYZ.js.map} +1 -1
- package/dist/tsup/{chunk-DADGS67O.cjs → chunk-GQGRQDRL.cjs} +4 -4
- package/dist/tsup/{chunk-DADGS67O.cjs.map → chunk-GQGRQDRL.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZSJ2OTY4.cjs → chunk-HYPIHCDT.cjs} +2 -2
- package/dist/tsup/{chunk-ZSJ2OTY4.cjs.map → chunk-HYPIHCDT.cjs.map} +1 -1
- package/dist/tsup/{chunk-HPAX7L72.cjs → chunk-IIJNPVPQ.cjs} +152 -152
- package/dist/tsup/{chunk-HPAX7L72.cjs.map → chunk-IIJNPVPQ.cjs.map} +1 -1
- package/dist/tsup/{chunk-U6VWVHVW.cjs → chunk-JC6BEPE7.cjs} +3 -3
- package/dist/tsup/{chunk-U6VWVHVW.cjs.map → chunk-JC6BEPE7.cjs.map} +1 -1
- package/dist/tsup/{chunk-N7ASEZ2Y.js → chunk-JPXO2H55.js} +5 -5
- package/dist/tsup/{chunk-QUDLEWGD.js → chunk-MIX2KB6U.js} +212 -47
- package/dist/tsup/chunk-MIX2KB6U.js.map +1 -0
- package/dist/tsup/{chunk-BMNB6YRQ.cjs → chunk-OAXJWGMU.cjs} +212 -305
- package/dist/tsup/chunk-OAXJWGMU.cjs.map +1 -0
- package/dist/tsup/{chunk-KSZZRTOD.cjs → chunk-PB5AEMKQ.cjs} +3 -5
- package/dist/tsup/chunk-PB5AEMKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-6T3WSP5M.js → chunk-R5OQUSLN.js} +4 -4
- package/dist/tsup/{chunk-POUBQA6Z.js → chunk-S662Y6ZU.js} +2 -2
- package/dist/tsup/{chunk-GNGRMP5E.js → chunk-SRIM3GHD.js} +18 -11
- package/dist/tsup/chunk-SRIM3GHD.js.map +1 -0
- package/dist/tsup/{chunk-MAXIXG56.js → chunk-TADUYCHF.js} +2 -4
- package/dist/tsup/chunk-TADUYCHF.js.map +1 -0
- package/dist/tsup/{chunk-R64EFI6F.cjs → chunk-TI5PXQGG.cjs} +280 -115
- package/dist/tsup/chunk-TI5PXQGG.cjs.map +1 -0
- package/dist/tsup/{chunk-T6MM5RTW.cjs → chunk-U5SMSA27.cjs} +250 -243
- package/dist/tsup/chunk-U5SMSA27.cjs.map +1 -0
- package/dist/tsup/{chunk-6LHZQSWJ.js → chunk-WY2SHWXQ.js} +8 -4
- package/dist/tsup/chunk-WY2SHWXQ.js.map +1 -0
- package/dist/tsup/{chunk-YLDDENCZ.js → chunk-ZPWOYQHN.js} +126 -219
- package/dist/tsup/chunk-ZPWOYQHN.js.map +1 -0
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-P3XujgRr.d.ts → config-Qj-zLJPc.d.ts} +11 -0
- package/dist/tsup/{config-_gfywqqI.d.cts → config-iPj5l1bL.d.cts} +11 -0
- package/dist/tsup/{context-uNA4TRn3.d.ts → context-CQCMuHND.d.ts} +1 -1
- package/dist/tsup/{context-Bxd8Cx4H.d.cts → context-DzvH1PBK.d.cts} +1 -1
- package/dist/tsup/{driver-CPGHKXyh.d.ts → driver-Jo8v-kbU.d.ts} +1 -1
- package/dist/tsup/driver-helpers/mod.cjs +4 -4
- package/dist/tsup/driver-helpers/mod.d.cts +4 -4
- package/dist/tsup/driver-helpers/mod.d.ts +4 -4
- package/dist/tsup/driver-helpers/mod.js +3 -3
- package/dist/tsup/{driver-BcLvZcKl.d.cts → driver-iV8J-WMv.d.cts} +1 -1
- package/dist/tsup/driver-test-suite/mod.cjs +196 -60
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +2 -2
- package/dist/tsup/driver-test-suite/mod.d.ts +2 -2
- package/dist/tsup/driver-test-suite/mod.js +971 -835
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +3 -3
- package/dist/tsup/inspector/mod.js +2 -2
- package/dist/tsup/mod.cjs +8 -8
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +7 -7
- package/dist/tsup/serve-test-suite/mod.cjs +182 -100
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +93 -11
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +10 -10
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +6 -6
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +5 -5
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +6 -6
- package/src/actor/config.ts +0 -2
- package/src/actor/instance/mod.ts +17 -4
- package/src/actor/router.ts +9 -6
- package/src/driver-test-suite/mod.ts +3 -0
- package/src/driver-test-suite/tests/actor-driver.ts +4 -0
- package/src/driver-test-suite/tests/actor-lifecycle.ts +157 -0
- package/src/driver-test-suite/tests/conn-error-serialization.ts +64 -0
- package/src/drivers/engine/actor-driver.ts +47 -15
- package/src/manager/router.ts +20 -6
- package/src/{registry → utils}/serve.ts +38 -4
- package/src/workflow/context.ts +4 -0
- package/dist/tsup/chunk-5AZ6UPEF.cjs.map +0 -1
- package/dist/tsup/chunk-6LHZQSWJ.js.map +0 -1
- package/dist/tsup/chunk-BMNB6YRQ.cjs.map +0 -1
- package/dist/tsup/chunk-GNGRMP5E.js.map +0 -1
- package/dist/tsup/chunk-KSZZRTOD.cjs.map +0 -1
- package/dist/tsup/chunk-MAXIXG56.js.map +0 -1
- package/dist/tsup/chunk-QUDLEWGD.js.map +0 -1
- package/dist/tsup/chunk-R64EFI6F.cjs.map +0 -1
- package/dist/tsup/chunk-T6MM5RTW.cjs.map +0 -1
- package/dist/tsup/chunk-YLDDENCZ.js.map +0 -1
- /package/dist/tsup/{chunk-OAOF23ZY.js.map → chunk-2OK7S6QF.js.map} +0 -0
- /package/dist/tsup/{chunk-N7ASEZ2Y.js.map → chunk-JPXO2H55.js.map} +0 -0
- /package/dist/tsup/{chunk-6T3WSP5M.js.map → chunk-R5OQUSLN.js.map} +0 -0
- /package/dist/tsup/{chunk-POUBQA6Z.js.map → chunk-S662Y6ZU.js.map} +0 -0
|
@@ -4,20 +4,20 @@ import {
|
|
|
4
4
|
SLEEP_TIMEOUT,
|
|
5
5
|
WORKFLOW_QUEUE_NAME,
|
|
6
6
|
logger
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
7
|
+
} from "../chunk-R5OQUSLN.js";
|
|
8
|
+
import "../chunk-WY2SHWXQ.js";
|
|
9
|
+
import "../chunk-S662Y6ZU.js";
|
|
10
|
+
import "../chunk-ZPWOYQHN.js";
|
|
11
|
+
import "../chunk-SRIM3GHD.js";
|
|
12
12
|
import {
|
|
13
13
|
ActorError,
|
|
14
14
|
ClientConfigSchema,
|
|
15
15
|
createClient,
|
|
16
16
|
createClientWithDriver
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-JPXO2H55.js";
|
|
18
18
|
import {
|
|
19
19
|
importWebSocket
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-2OK7S6QF.js";
|
|
21
21
|
import "../chunk-KJSYAUOM.js";
|
|
22
22
|
import "../chunk-N4KRDJ56.js";
|
|
23
23
|
import {
|
|
@@ -29,14 +29,14 @@ import {
|
|
|
29
29
|
WS_PROTOCOL_TARGET,
|
|
30
30
|
WS_TEST_PROTOCOL_PATH,
|
|
31
31
|
buildManagerRouter
|
|
32
|
-
} from "../chunk-
|
|
32
|
+
} from "../chunk-MIX2KB6U.js";
|
|
33
33
|
import "../chunk-LXUQ667X.js";
|
|
34
34
|
import {
|
|
35
35
|
assertUnreachable
|
|
36
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-TADUYCHF.js";
|
|
37
37
|
import {
|
|
38
38
|
noopNext
|
|
39
|
-
} from "../chunk-
|
|
39
|
+
} from "../chunk-EIATSBYZ.js";
|
|
40
40
|
import {
|
|
41
41
|
INTERNAL_ERROR_CODE,
|
|
42
42
|
INTERNAL_ERROR_DESCRIPTION
|
|
@@ -47,7 +47,7 @@ import "../chunk-424PT5DM.js";
|
|
|
47
47
|
import { serve as honoServe } from "@hono/node-server";
|
|
48
48
|
import { createNodeWebSocket } from "@hono/node-ws";
|
|
49
49
|
import invariant2 from "invariant";
|
|
50
|
-
import { describe as
|
|
50
|
+
import { describe as describe31 } from "vitest";
|
|
51
51
|
|
|
52
52
|
// src/driver-test-suite/tests/action-features.ts
|
|
53
53
|
import { describe, expect, test } from "vitest";
|
|
@@ -1642,11 +1642,49 @@ function runActorDbTests(driverTestConfig) {
|
|
|
1642
1642
|
});
|
|
1643
1643
|
}
|
|
1644
1644
|
|
|
1645
|
+
// src/driver-test-suite/tests/conn-error-serialization.ts
|
|
1646
|
+
import { describe as describe7, expect as expect7, test as test7 } from "vitest";
|
|
1647
|
+
function runConnErrorSerializationTests(driverTestConfig) {
|
|
1648
|
+
describe7("Connection Error Serialization Tests", () => {
|
|
1649
|
+
test7("error thrown in createConnState preserves group and code through WebSocket serialization", async (c) => {
|
|
1650
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1651
|
+
const actorKey = `test-error-serialization-${Date.now()}`;
|
|
1652
|
+
const actor = client.connErrorSerializationActor.getOrCreate(
|
|
1653
|
+
[actorKey],
|
|
1654
|
+
{ params: { shouldThrow: true } }
|
|
1655
|
+
);
|
|
1656
|
+
const conn = actor.connect();
|
|
1657
|
+
let caughtError;
|
|
1658
|
+
try {
|
|
1659
|
+
await conn.getValue();
|
|
1660
|
+
} catch (err) {
|
|
1661
|
+
caughtError = err;
|
|
1662
|
+
}
|
|
1663
|
+
expect7(caughtError).toBeDefined();
|
|
1664
|
+
expect7(caughtError.group).toBe("connection");
|
|
1665
|
+
expect7(caughtError.code).toBe("custom_error");
|
|
1666
|
+
await conn.dispose();
|
|
1667
|
+
});
|
|
1668
|
+
test7("successful createConnState does not throw error", async (c) => {
|
|
1669
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1670
|
+
const actorKey = `test-no-error-${Date.now()}`;
|
|
1671
|
+
const actor = client.connErrorSerializationActor.getOrCreate(
|
|
1672
|
+
[actorKey],
|
|
1673
|
+
{ params: { shouldThrow: false } }
|
|
1674
|
+
);
|
|
1675
|
+
const conn = actor.connect();
|
|
1676
|
+
const value = await conn.getValue();
|
|
1677
|
+
expect7(value).toBe(0);
|
|
1678
|
+
await conn.dispose();
|
|
1679
|
+
});
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1645
1683
|
// src/driver-test-suite/tests/actor-destroy.ts
|
|
1646
|
-
import { describe as
|
|
1684
|
+
import { describe as describe8, expect as expect8, test as test8, vi as vi5 } from "vitest";
|
|
1647
1685
|
function runActorDestroyTests(driverTestConfig) {
|
|
1648
|
-
|
|
1649
|
-
|
|
1686
|
+
describe8("Actor Destroy Tests", () => {
|
|
1687
|
+
test8("actor destroy clears state (without connect)", async (c) => {
|
|
1650
1688
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1651
1689
|
const actorKey = "test-destroy-without-connect";
|
|
1652
1690
|
const observer = client.destroyObserver.getOrCreate(["observer"]);
|
|
@@ -1654,12 +1692,12 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1654
1692
|
const destroyActor = client.destroyActor.getOrCreate([actorKey]);
|
|
1655
1693
|
await destroyActor.setValue(42);
|
|
1656
1694
|
const value = await destroyActor.getValue();
|
|
1657
|
-
|
|
1695
|
+
expect8(value).toBe(42);
|
|
1658
1696
|
const actorId = await destroyActor.resolve();
|
|
1659
1697
|
await destroyActor.destroy();
|
|
1660
1698
|
await vi5.waitFor(async () => {
|
|
1661
1699
|
const wasDestroyed = await observer.wasDestroyed(actorKey);
|
|
1662
|
-
|
|
1700
|
+
expect8(wasDestroyed, "actor onDestroy not called").toBeTruthy();
|
|
1663
1701
|
});
|
|
1664
1702
|
await vi5.waitFor(async () => {
|
|
1665
1703
|
let actorRunning = false;
|
|
@@ -1667,20 +1705,20 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1667
1705
|
await client.destroyActor.getForId(actorId).getValue();
|
|
1668
1706
|
actorRunning = true;
|
|
1669
1707
|
} catch (err) {
|
|
1670
|
-
|
|
1671
|
-
|
|
1708
|
+
expect8(err.group).toBe("actor");
|
|
1709
|
+
expect8(err.code).toBe("not_found");
|
|
1672
1710
|
}
|
|
1673
|
-
|
|
1711
|
+
expect8(actorRunning, "actor still running").toBeFalsy();
|
|
1674
1712
|
});
|
|
1675
1713
|
let existsById = false;
|
|
1676
1714
|
try {
|
|
1677
1715
|
await client.destroyActor.getForId(actorId).getValue();
|
|
1678
1716
|
existsById = true;
|
|
1679
1717
|
} catch (err) {
|
|
1680
|
-
|
|
1681
|
-
|
|
1718
|
+
expect8(err.group).toBe("actor");
|
|
1719
|
+
expect8(err.code).toBe("not_found");
|
|
1682
1720
|
}
|
|
1683
|
-
|
|
1721
|
+
expect8(
|
|
1684
1722
|
existsById,
|
|
1685
1723
|
"actor should not exist after destroy"
|
|
1686
1724
|
).toBeFalsy();
|
|
@@ -1689,10 +1727,10 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1689
1727
|
await client.destroyActor.get(["test-destroy-without-connect"]).resolve();
|
|
1690
1728
|
existsByKey = true;
|
|
1691
1729
|
} catch (err) {
|
|
1692
|
-
|
|
1693
|
-
|
|
1730
|
+
expect8(err.group).toBe("actor");
|
|
1731
|
+
expect8(err.code).toBe("not_found");
|
|
1694
1732
|
}
|
|
1695
|
-
|
|
1733
|
+
expect8(
|
|
1696
1734
|
existsByKey,
|
|
1697
1735
|
"actor should not exist after destroy"
|
|
1698
1736
|
).toBeFalsy();
|
|
@@ -1700,9 +1738,9 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1700
1738
|
"test-destroy-without-connect"
|
|
1701
1739
|
]);
|
|
1702
1740
|
const newValue = await newActor.getValue();
|
|
1703
|
-
|
|
1741
|
+
expect8(newValue).toBe(0);
|
|
1704
1742
|
});
|
|
1705
|
-
|
|
1743
|
+
test8("actor destroy clears state (with connect)", async (c) => {
|
|
1706
1744
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1707
1745
|
const actorKey = "test-destroy-with-connect";
|
|
1708
1746
|
const observer = client.destroyObserver.getOrCreate(["observer"]);
|
|
@@ -1714,12 +1752,12 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1714
1752
|
const destroyActor = destroyActorHandle.connect();
|
|
1715
1753
|
await destroyActor.setValue(99);
|
|
1716
1754
|
const value = await destroyActor.getValue();
|
|
1717
|
-
|
|
1755
|
+
expect8(value).toBe(99);
|
|
1718
1756
|
await destroyActor.destroy();
|
|
1719
1757
|
await destroyActor.dispose();
|
|
1720
1758
|
await vi5.waitFor(async () => {
|
|
1721
1759
|
const wasDestroyed = await observer.wasDestroyed(actorKey);
|
|
1722
|
-
|
|
1760
|
+
expect8(wasDestroyed, "actor onDestroy not called").toBeTruthy();
|
|
1723
1761
|
});
|
|
1724
1762
|
await vi5.waitFor(async () => {
|
|
1725
1763
|
let actorRunning = false;
|
|
@@ -1727,20 +1765,20 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1727
1765
|
await client.destroyActor.getForId(actorId).getValue();
|
|
1728
1766
|
actorRunning = true;
|
|
1729
1767
|
} catch (err) {
|
|
1730
|
-
|
|
1731
|
-
|
|
1768
|
+
expect8(err.group).toBe("actor");
|
|
1769
|
+
expect8(err.code).toBe("not_found");
|
|
1732
1770
|
}
|
|
1733
|
-
|
|
1771
|
+
expect8(actorRunning, "actor still running").toBeFalsy();
|
|
1734
1772
|
});
|
|
1735
1773
|
let existsById = false;
|
|
1736
1774
|
try {
|
|
1737
1775
|
await client.destroyActor.getForId(actorId).getValue();
|
|
1738
1776
|
existsById = true;
|
|
1739
1777
|
} catch (err) {
|
|
1740
|
-
|
|
1741
|
-
|
|
1778
|
+
expect8(err.group).toBe("actor");
|
|
1779
|
+
expect8(err.code).toBe("not_found");
|
|
1742
1780
|
}
|
|
1743
|
-
|
|
1781
|
+
expect8(
|
|
1744
1782
|
existsById,
|
|
1745
1783
|
"actor should not exist after destroy"
|
|
1746
1784
|
).toBeFalsy();
|
|
@@ -1749,10 +1787,10 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1749
1787
|
await client.destroyActor.get(["test-destroy-with-connect"]).resolve();
|
|
1750
1788
|
existsByKey = true;
|
|
1751
1789
|
} catch (err) {
|
|
1752
|
-
|
|
1753
|
-
|
|
1790
|
+
expect8(err.group).toBe("actor");
|
|
1791
|
+
expect8(err.code).toBe("not_found");
|
|
1754
1792
|
}
|
|
1755
|
-
|
|
1793
|
+
expect8(
|
|
1756
1794
|
existsByKey,
|
|
1757
1795
|
"actor should not exist after destroy"
|
|
1758
1796
|
).toBeFalsy();
|
|
@@ -1760,9 +1798,9 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1760
1798
|
"test-destroy-with-connect"
|
|
1761
1799
|
]);
|
|
1762
1800
|
const newValue = await newActor.getValue();
|
|
1763
|
-
|
|
1801
|
+
expect8(newValue).toBe(0);
|
|
1764
1802
|
});
|
|
1765
|
-
|
|
1803
|
+
test8("actor destroy allows recreation via getOrCreate with resolve", async (c) => {
|
|
1766
1804
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1767
1805
|
const actorKey = "test-destroy-getorcreate-resolve";
|
|
1768
1806
|
const observer = client.destroyObserver.getOrCreate(["observer"]);
|
|
@@ -1770,12 +1808,12 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1770
1808
|
const destroyActor = client.destroyActor.getOrCreate([actorKey]);
|
|
1771
1809
|
await destroyActor.setValue(123);
|
|
1772
1810
|
const value = await destroyActor.getValue();
|
|
1773
|
-
|
|
1811
|
+
expect8(value).toBe(123);
|
|
1774
1812
|
const actorId = await destroyActor.resolve();
|
|
1775
1813
|
await destroyActor.destroy();
|
|
1776
1814
|
await vi5.waitFor(async () => {
|
|
1777
1815
|
const wasDestroyed = await observer.wasDestroyed(actorKey);
|
|
1778
|
-
|
|
1816
|
+
expect8(wasDestroyed, "actor onDestroy not called").toBeTruthy();
|
|
1779
1817
|
});
|
|
1780
1818
|
await vi5.waitFor(async () => {
|
|
1781
1819
|
let actorRunning = false;
|
|
@@ -1783,17 +1821,17 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1783
1821
|
await client.destroyActor.getForId(actorId).getValue();
|
|
1784
1822
|
actorRunning = true;
|
|
1785
1823
|
} catch (err) {
|
|
1786
|
-
|
|
1787
|
-
|
|
1824
|
+
expect8(err.group).toBe("actor");
|
|
1825
|
+
expect8(err.code).toBe("not_found");
|
|
1788
1826
|
}
|
|
1789
|
-
|
|
1827
|
+
expect8(actorRunning, "actor still running").toBeFalsy();
|
|
1790
1828
|
});
|
|
1791
1829
|
const newHandle = client.destroyActor.getOrCreate([actorKey]);
|
|
1792
1830
|
const newActorId = await newHandle.resolve();
|
|
1793
1831
|
const newValue = await newHandle.getValue();
|
|
1794
|
-
|
|
1832
|
+
expect8(newValue).toBe(0);
|
|
1795
1833
|
});
|
|
1796
|
-
|
|
1834
|
+
test8("actor destroy allows recreation via create", async (c) => {
|
|
1797
1835
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1798
1836
|
const actorKey = "test-destroy-create";
|
|
1799
1837
|
const observer = client.destroyObserver.getOrCreate(["observer"]);
|
|
@@ -1801,12 +1839,12 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1801
1839
|
const initialHandle = await client.destroyActor.create([actorKey]);
|
|
1802
1840
|
await initialHandle.setValue(456);
|
|
1803
1841
|
const value = await initialHandle.getValue();
|
|
1804
|
-
|
|
1842
|
+
expect8(value).toBe(456);
|
|
1805
1843
|
const actorId = await initialHandle.resolve();
|
|
1806
1844
|
await initialHandle.destroy();
|
|
1807
1845
|
await vi5.waitFor(async () => {
|
|
1808
1846
|
const wasDestroyed = await observer.wasDestroyed(actorKey);
|
|
1809
|
-
|
|
1847
|
+
expect8(wasDestroyed, "actor onDestroy not called").toBeTruthy();
|
|
1810
1848
|
});
|
|
1811
1849
|
await vi5.waitFor(async () => {
|
|
1812
1850
|
let actorRunning = false;
|
|
@@ -1814,31 +1852,127 @@ function runActorDestroyTests(driverTestConfig) {
|
|
|
1814
1852
|
await client.destroyActor.getForId(actorId).getValue();
|
|
1815
1853
|
actorRunning = true;
|
|
1816
1854
|
} catch (err) {
|
|
1817
|
-
|
|
1818
|
-
|
|
1855
|
+
expect8(err.group).toBe("actor");
|
|
1856
|
+
expect8(err.code).toBe("not_found");
|
|
1819
1857
|
}
|
|
1820
|
-
|
|
1858
|
+
expect8(actorRunning, "actor still running").toBeFalsy();
|
|
1821
1859
|
});
|
|
1822
1860
|
const newHandle = await client.destroyActor.create([actorKey]);
|
|
1823
1861
|
const newActorId = await newHandle.resolve();
|
|
1824
1862
|
const newValue = await newHandle.getValue();
|
|
1825
|
-
|
|
1863
|
+
expect8(newValue).toBe(0);
|
|
1826
1864
|
});
|
|
1827
1865
|
});
|
|
1828
1866
|
}
|
|
1829
1867
|
|
|
1830
1868
|
// src/driver-test-suite/tests/actor-driver.ts
|
|
1831
|
-
import { describe as
|
|
1869
|
+
import { describe as describe13 } from "vitest";
|
|
1870
|
+
|
|
1871
|
+
// src/driver-test-suite/tests/actor-lifecycle.ts
|
|
1872
|
+
import { describe as describe9, expect as expect9, test as test9 } from "vitest";
|
|
1873
|
+
function runActorLifecycleTests(driverTestConfig) {
|
|
1874
|
+
describe9("Actor Lifecycle Tests", () => {
|
|
1875
|
+
test9("actor stop during start waits for start to complete", async (c) => {
|
|
1876
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1877
|
+
const actorKey = `test-stop-during-start-${Date.now()}`;
|
|
1878
|
+
const actor = client.startStopRaceActor.getOrCreate([actorKey]);
|
|
1879
|
+
const pingPromise = actor.ping();
|
|
1880
|
+
const actorId = await actor.resolve();
|
|
1881
|
+
await actor.destroy();
|
|
1882
|
+
const result = await pingPromise;
|
|
1883
|
+
expect9(result).toBe("pong");
|
|
1884
|
+
let destroyed = false;
|
|
1885
|
+
try {
|
|
1886
|
+
await client.startStopRaceActor.getForId(actorId).ping();
|
|
1887
|
+
} catch (err) {
|
|
1888
|
+
destroyed = true;
|
|
1889
|
+
expect9(err.group).toBe("actor");
|
|
1890
|
+
expect9(err.code).toBe("not_found");
|
|
1891
|
+
}
|
|
1892
|
+
expect9(destroyed).toBe(true);
|
|
1893
|
+
});
|
|
1894
|
+
test9("actor stop before actor instantiation completes cleans up handler", async (c) => {
|
|
1895
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1896
|
+
const actorKey = `test-stop-before-instantiation-${Date.now()}`;
|
|
1897
|
+
const actors = Array.from(
|
|
1898
|
+
{ length: 5 },
|
|
1899
|
+
(_, i) => client.startStopRaceActor.getOrCreate([
|
|
1900
|
+
`${actorKey}-${i}`
|
|
1901
|
+
])
|
|
1902
|
+
);
|
|
1903
|
+
const ids = await Promise.all(actors.map((a) => a.resolve()));
|
|
1904
|
+
await Promise.all(actors.map((a) => a.destroy()));
|
|
1905
|
+
for (const id of ids) {
|
|
1906
|
+
let destroyed = false;
|
|
1907
|
+
try {
|
|
1908
|
+
await client.startStopRaceActor.getForId(id).ping();
|
|
1909
|
+
} catch (err) {
|
|
1910
|
+
destroyed = true;
|
|
1911
|
+
expect9(err.group).toBe("actor");
|
|
1912
|
+
expect9(err.code).toBe("not_found");
|
|
1913
|
+
}
|
|
1914
|
+
expect9(destroyed, `actor ${id} should be destroyed`).toBe(
|
|
1915
|
+
true
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
});
|
|
1919
|
+
test9("onBeforeActorStart completes before stop proceeds", async (c) => {
|
|
1920
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1921
|
+
const actorKey = `test-before-actor-start-${Date.now()}`;
|
|
1922
|
+
const actor = client.startStopRaceActor.getOrCreate([actorKey]);
|
|
1923
|
+
const statePromise = actor.getState();
|
|
1924
|
+
await actor.destroy();
|
|
1925
|
+
const state = await statePromise;
|
|
1926
|
+
expect9(state.initialized).toBe(true);
|
|
1927
|
+
expect9(state.startCompleted).toBe(true);
|
|
1928
|
+
});
|
|
1929
|
+
test9("multiple rapid create/destroy cycles handle race correctly", async (c) => {
|
|
1930
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1931
|
+
for (let i = 0; i < 10; i++) {
|
|
1932
|
+
const actorKey = `test-rapid-cycle-${Date.now()}-${i}`;
|
|
1933
|
+
const actor = client.startStopRaceActor.getOrCreate([
|
|
1934
|
+
actorKey
|
|
1935
|
+
]);
|
|
1936
|
+
const resolvePromise = actor.resolve();
|
|
1937
|
+
const destroyPromise = actor.destroy();
|
|
1938
|
+
await Promise.all([resolvePromise, destroyPromise]);
|
|
1939
|
+
}
|
|
1940
|
+
expect9(true).toBe(true);
|
|
1941
|
+
});
|
|
1942
|
+
test9("actor stop called with no actor instance cleans up handler", async (c) => {
|
|
1943
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1944
|
+
const actorKey = `test-cleanup-no-instance-${Date.now()}`;
|
|
1945
|
+
const actor = client.startStopRaceActor.getOrCreate([actorKey]);
|
|
1946
|
+
const id = await actor.resolve();
|
|
1947
|
+
await actor.destroy();
|
|
1948
|
+
const newActor = client.startStopRaceActor.getOrCreate([
|
|
1949
|
+
actorKey
|
|
1950
|
+
]);
|
|
1951
|
+
const result = await newActor.ping();
|
|
1952
|
+
expect9(result).toBe("pong");
|
|
1953
|
+
await newActor.destroy();
|
|
1954
|
+
});
|
|
1955
|
+
test9("onDestroy is called even when actor is destroyed during start", async (c) => {
|
|
1956
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1957
|
+
const actorKey = `test-ondestroy-during-start-${Date.now()}`;
|
|
1958
|
+
const actor = client.startStopRaceActor.getOrCreate([actorKey]);
|
|
1959
|
+
const statePromise = actor.getState();
|
|
1960
|
+
await actor.destroy();
|
|
1961
|
+
const state = await statePromise;
|
|
1962
|
+
expect9(state.destroyCalled).toBe(true);
|
|
1963
|
+
});
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1832
1966
|
|
|
1833
1967
|
// src/driver-test-suite/tests/actor-schedule.ts
|
|
1834
|
-
import { describe as
|
|
1968
|
+
import { describe as describe10, expect as expect10, test as test10 } from "vitest";
|
|
1835
1969
|
function runActorScheduleTests(driverTestConfig) {
|
|
1836
1970
|
var _a;
|
|
1837
|
-
|
|
1971
|
+
describe10.skipIf((_a = driverTestConfig.skip) == null ? void 0 : _a.schedule)(
|
|
1838
1972
|
"Actor Schedule Tests",
|
|
1839
1973
|
() => {
|
|
1840
|
-
|
|
1841
|
-
|
|
1974
|
+
describe10("Scheduled Alarms", () => {
|
|
1975
|
+
test10("executes c.schedule.at() with specific timestamp", async (c) => {
|
|
1842
1976
|
const { client } = await setupDriverTest(
|
|
1843
1977
|
c,
|
|
1844
1978
|
driverTestConfig
|
|
@@ -1849,10 +1983,10 @@ function runActorScheduleTests(driverTestConfig) {
|
|
|
1849
1983
|
await waitFor(driverTestConfig, 500);
|
|
1850
1984
|
const lastRun = await scheduled.getLastRun();
|
|
1851
1985
|
const scheduledCount = await scheduled.getScheduledCount();
|
|
1852
|
-
|
|
1853
|
-
|
|
1986
|
+
expect10(lastRun).toBeGreaterThan(0);
|
|
1987
|
+
expect10(scheduledCount).toBe(1);
|
|
1854
1988
|
});
|
|
1855
|
-
|
|
1989
|
+
test10("executes c.schedule.after() with delay", async (c) => {
|
|
1856
1990
|
const { client } = await setupDriverTest(
|
|
1857
1991
|
c,
|
|
1858
1992
|
driverTestConfig
|
|
@@ -1862,10 +1996,10 @@ function runActorScheduleTests(driverTestConfig) {
|
|
|
1862
1996
|
await waitFor(driverTestConfig, 500);
|
|
1863
1997
|
const lastRun = await scheduled.getLastRun();
|
|
1864
1998
|
const scheduledCount = await scheduled.getScheduledCount();
|
|
1865
|
-
|
|
1866
|
-
|
|
1999
|
+
expect10(lastRun).toBeGreaterThan(0);
|
|
2000
|
+
expect10(scheduledCount).toBe(1);
|
|
1867
2001
|
});
|
|
1868
|
-
|
|
2002
|
+
test10("multiple scheduled tasks execute in order", async (c) => {
|
|
1869
2003
|
const { client } = await setupDriverTest(
|
|
1870
2004
|
c,
|
|
1871
2005
|
driverTestConfig
|
|
@@ -1877,16 +2011,16 @@ function runActorScheduleTests(driverTestConfig) {
|
|
|
1877
2011
|
await scheduled.scheduleTaskAfterWithId("third", 1250);
|
|
1878
2012
|
await waitFor(driverTestConfig, 500);
|
|
1879
2013
|
const history1 = await scheduled.getTaskHistory();
|
|
1880
|
-
|
|
2014
|
+
expect10(history1[0]).toBe("first");
|
|
1881
2015
|
await waitFor(driverTestConfig, 500);
|
|
1882
2016
|
const history2 = await scheduled.getTaskHistory();
|
|
1883
|
-
|
|
2017
|
+
expect10(history2.slice(0, 2)).toEqual([
|
|
1884
2018
|
"first",
|
|
1885
2019
|
"second"
|
|
1886
2020
|
]);
|
|
1887
2021
|
await waitFor(driverTestConfig, 500);
|
|
1888
2022
|
const history3 = await scheduled.getTaskHistory();
|
|
1889
|
-
|
|
2023
|
+
expect10(history3).toEqual(["first", "second", "third"]);
|
|
1890
2024
|
});
|
|
1891
2025
|
});
|
|
1892
2026
|
}
|
|
@@ -1894,33 +2028,33 @@ function runActorScheduleTests(driverTestConfig) {
|
|
|
1894
2028
|
}
|
|
1895
2029
|
|
|
1896
2030
|
// src/driver-test-suite/tests/actor-sleep.ts
|
|
1897
|
-
import { describe as
|
|
2031
|
+
import { describe as describe11, expect as expect11, test as test11 } from "vitest";
|
|
1898
2032
|
function runActorSleepTests(driverTestConfig) {
|
|
1899
2033
|
var _a;
|
|
1900
|
-
|
|
1901
|
-
|
|
2034
|
+
describe11.skipIf((_a = driverTestConfig.skip) == null ? void 0 : _a.sleep)("Actor Sleep Tests", () => {
|
|
2035
|
+
test11("actor sleep persists state", async (c) => {
|
|
1902
2036
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1903
2037
|
const sleepActor = client.sleep.getOrCreate();
|
|
1904
2038
|
{
|
|
1905
2039
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1906
|
-
|
|
1907
|
-
|
|
2040
|
+
expect11(sleepCount).toBe(0);
|
|
2041
|
+
expect11(startCount).toBe(1);
|
|
1908
2042
|
}
|
|
1909
2043
|
await sleepActor.triggerSleep();
|
|
1910
2044
|
await waitFor(driverTestConfig, 250);
|
|
1911
2045
|
{
|
|
1912
2046
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1913
|
-
|
|
1914
|
-
|
|
2047
|
+
expect11(sleepCount).toBe(1);
|
|
2048
|
+
expect11(startCount).toBe(2);
|
|
1915
2049
|
}
|
|
1916
2050
|
});
|
|
1917
|
-
|
|
2051
|
+
test11("actor sleep persists state with connect", async (c) => {
|
|
1918
2052
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1919
2053
|
const sleepActor = client.sleep.getOrCreate().connect();
|
|
1920
2054
|
{
|
|
1921
2055
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1922
|
-
|
|
1923
|
-
|
|
2056
|
+
expect11(sleepCount).toBe(0);
|
|
2057
|
+
expect11(startCount).toBe(1);
|
|
1924
2058
|
}
|
|
1925
2059
|
await sleepActor.triggerSleep();
|
|
1926
2060
|
await sleepActor.dispose();
|
|
@@ -1928,108 +2062,108 @@ function runActorSleepTests(driverTestConfig) {
|
|
|
1928
2062
|
const sleepActor2 = client.sleep.getOrCreate();
|
|
1929
2063
|
{
|
|
1930
2064
|
const { startCount, sleepCount } = await sleepActor2.getCounts();
|
|
1931
|
-
|
|
1932
|
-
|
|
2065
|
+
expect11(sleepCount).toBe(1);
|
|
2066
|
+
expect11(startCount).toBe(2);
|
|
1933
2067
|
}
|
|
1934
2068
|
});
|
|
1935
|
-
|
|
2069
|
+
test11("actor automatically sleeps after timeout", async (c) => {
|
|
1936
2070
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1937
2071
|
const sleepActor = client.sleep.getOrCreate();
|
|
1938
2072
|
{
|
|
1939
2073
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1940
|
-
|
|
1941
|
-
|
|
2074
|
+
expect11(sleepCount).toBe(0);
|
|
2075
|
+
expect11(startCount).toBe(1);
|
|
1942
2076
|
}
|
|
1943
2077
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
1944
2078
|
{
|
|
1945
2079
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1946
|
-
|
|
1947
|
-
|
|
2080
|
+
expect11(sleepCount).toBe(1);
|
|
2081
|
+
expect11(startCount).toBe(2);
|
|
1948
2082
|
}
|
|
1949
2083
|
});
|
|
1950
|
-
|
|
2084
|
+
test11("actor automatically sleeps after timeout with connect", async (c) => {
|
|
1951
2085
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1952
2086
|
const sleepActor = client.sleep.getOrCreate().connect();
|
|
1953
2087
|
{
|
|
1954
2088
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1955
|
-
|
|
1956
|
-
|
|
2089
|
+
expect11(sleepCount).toBe(0);
|
|
2090
|
+
expect11(startCount).toBe(1);
|
|
1957
2091
|
}
|
|
1958
2092
|
await sleepActor.dispose();
|
|
1959
2093
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
1960
2094
|
const sleepActor2 = client.sleep.getOrCreate();
|
|
1961
2095
|
{
|
|
1962
2096
|
const { startCount, sleepCount } = await sleepActor2.getCounts();
|
|
1963
|
-
|
|
1964
|
-
|
|
2097
|
+
expect11(sleepCount).toBe(1);
|
|
2098
|
+
expect11(startCount).toBe(2);
|
|
1965
2099
|
}
|
|
1966
2100
|
});
|
|
1967
|
-
|
|
2101
|
+
test11("rpc calls keep actor awake", async (c) => {
|
|
1968
2102
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1969
2103
|
const sleepActor = client.sleep.getOrCreate();
|
|
1970
2104
|
{
|
|
1971
2105
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1972
|
-
|
|
1973
|
-
|
|
2106
|
+
expect11(sleepCount).toBe(0);
|
|
2107
|
+
expect11(startCount).toBe(1);
|
|
1974
2108
|
}
|
|
1975
2109
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT - 250);
|
|
1976
2110
|
{
|
|
1977
2111
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1978
|
-
|
|
1979
|
-
|
|
2112
|
+
expect11(sleepCount).toBe(0);
|
|
2113
|
+
expect11(startCount).toBe(1);
|
|
1980
2114
|
}
|
|
1981
2115
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT - 250);
|
|
1982
2116
|
{
|
|
1983
2117
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1984
|
-
|
|
1985
|
-
|
|
2118
|
+
expect11(sleepCount).toBe(0);
|
|
2119
|
+
expect11(startCount).toBe(1);
|
|
1986
2120
|
}
|
|
1987
2121
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
1988
2122
|
{
|
|
1989
2123
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1990
|
-
|
|
1991
|
-
|
|
2124
|
+
expect11(sleepCount).toBe(1);
|
|
2125
|
+
expect11(startCount).toBe(2);
|
|
1992
2126
|
}
|
|
1993
2127
|
});
|
|
1994
|
-
|
|
2128
|
+
test11("alarms keep actor awake", async (c) => {
|
|
1995
2129
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
1996
2130
|
const sleepActor = client.sleep.getOrCreate();
|
|
1997
2131
|
{
|
|
1998
2132
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
1999
|
-
|
|
2000
|
-
|
|
2133
|
+
expect11(sleepCount).toBe(0);
|
|
2134
|
+
expect11(startCount).toBe(1);
|
|
2001
2135
|
}
|
|
2002
2136
|
await sleepActor.setAlarm(SLEEP_TIMEOUT - 250);
|
|
2003
2137
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
2004
2138
|
{
|
|
2005
2139
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2006
|
-
|
|
2007
|
-
|
|
2140
|
+
expect11(sleepCount).toBe(0);
|
|
2141
|
+
expect11(startCount).toBe(1);
|
|
2008
2142
|
}
|
|
2009
2143
|
});
|
|
2010
|
-
|
|
2144
|
+
test11("alarms wake actors", async (c) => {
|
|
2011
2145
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2012
2146
|
const sleepActor = client.sleep.getOrCreate();
|
|
2013
2147
|
{
|
|
2014
2148
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2015
|
-
|
|
2016
|
-
|
|
2149
|
+
expect11(sleepCount).toBe(0);
|
|
2150
|
+
expect11(startCount).toBe(1);
|
|
2017
2151
|
}
|
|
2018
2152
|
await sleepActor.setAlarm(SLEEP_TIMEOUT + 250);
|
|
2019
2153
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 200);
|
|
2020
2154
|
{
|
|
2021
2155
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2022
|
-
|
|
2023
|
-
|
|
2156
|
+
expect11(sleepCount).toBe(1);
|
|
2157
|
+
expect11(startCount).toBe(2);
|
|
2024
2158
|
}
|
|
2025
2159
|
});
|
|
2026
|
-
|
|
2160
|
+
test11("long running rpcs keep actor awake", async (c) => {
|
|
2027
2161
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2028
2162
|
const sleepActor = client.sleepWithLongRpc.getOrCreate().connect();
|
|
2029
2163
|
{
|
|
2030
2164
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2031
|
-
|
|
2032
|
-
|
|
2165
|
+
expect11(sleepCount).toBe(0);
|
|
2166
|
+
expect11(startCount).toBe(1);
|
|
2033
2167
|
}
|
|
2034
2168
|
const waitPromise = new Promise(
|
|
2035
2169
|
(resolve) => sleepActor.once("waiting", resolve)
|
|
@@ -2041,19 +2175,19 @@ function runActorSleepTests(driverTestConfig) {
|
|
|
2041
2175
|
await longRunningPromise;
|
|
2042
2176
|
{
|
|
2043
2177
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2044
|
-
|
|
2045
|
-
|
|
2178
|
+
expect11(sleepCount).toBe(0);
|
|
2179
|
+
expect11(startCount).toBe(1);
|
|
2046
2180
|
}
|
|
2047
2181
|
await sleepActor.dispose();
|
|
2048
2182
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
2049
2183
|
const sleepActor2 = client.sleepWithLongRpc.getOrCreate();
|
|
2050
2184
|
{
|
|
2051
2185
|
const { startCount, sleepCount } = await sleepActor2.getCounts();
|
|
2052
|
-
|
|
2053
|
-
|
|
2186
|
+
expect11(sleepCount).toBe(1);
|
|
2187
|
+
expect11(startCount).toBe(2);
|
|
2054
2188
|
}
|
|
2055
2189
|
});
|
|
2056
|
-
|
|
2190
|
+
test11("active raw websockets keep actor awake", async (c) => {
|
|
2057
2191
|
const { client, endpoint: baseUrl } = await setupDriverTest(
|
|
2058
2192
|
c,
|
|
2059
2193
|
driverTestConfig
|
|
@@ -2061,8 +2195,8 @@ function runActorSleepTests(driverTestConfig) {
|
|
|
2061
2195
|
const sleepActor = client.sleepWithRawWebSocket.getOrCreate();
|
|
2062
2196
|
{
|
|
2063
2197
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2064
|
-
|
|
2065
|
-
|
|
2198
|
+
expect11(sleepCount).toBe(0);
|
|
2199
|
+
expect11(startCount).toBe(1);
|
|
2066
2200
|
}
|
|
2067
2201
|
const ws = await sleepActor.webSocket();
|
|
2068
2202
|
await new Promise((resolve, reject) => {
|
|
@@ -2087,17 +2221,17 @@ function runActorSleepTests(driverTestConfig) {
|
|
|
2087
2221
|
}
|
|
2088
2222
|
};
|
|
2089
2223
|
});
|
|
2090
|
-
|
|
2091
|
-
|
|
2224
|
+
expect11(counts.sleepCount).toBe(0);
|
|
2225
|
+
expect11(counts.startCount).toBe(1);
|
|
2092
2226
|
ws.close();
|
|
2093
2227
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
2094
2228
|
{
|
|
2095
2229
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2096
|
-
|
|
2097
|
-
|
|
2230
|
+
expect11(sleepCount).toBe(1);
|
|
2231
|
+
expect11(startCount).toBe(2);
|
|
2098
2232
|
}
|
|
2099
2233
|
});
|
|
2100
|
-
|
|
2234
|
+
test11("active raw fetch requests keep actor awake", async (c) => {
|
|
2101
2235
|
const { client, endpoint: baseUrl } = await setupDriverTest(
|
|
2102
2236
|
c,
|
|
2103
2237
|
driverTestConfig
|
|
@@ -2105,8 +2239,8 @@ function runActorSleepTests(driverTestConfig) {
|
|
|
2105
2239
|
const sleepActor = client.sleepWithRawHttp.getOrCreate();
|
|
2106
2240
|
{
|
|
2107
2241
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2108
|
-
|
|
2109
|
-
|
|
2242
|
+
expect11(sleepCount).toBe(0);
|
|
2243
|
+
expect11(startCount).toBe(1);
|
|
2110
2244
|
}
|
|
2111
2245
|
const fetchDuration = SLEEP_TIMEOUT + 250;
|
|
2112
2246
|
const fetchPromise = sleepActor.fetch(
|
|
@@ -2114,67 +2248,67 @@ function runActorSleepTests(driverTestConfig) {
|
|
|
2114
2248
|
);
|
|
2115
2249
|
const response = await fetchPromise;
|
|
2116
2250
|
const result = await response.json();
|
|
2117
|
-
|
|
2251
|
+
expect11(result.completed).toBe(true);
|
|
2118
2252
|
{
|
|
2119
2253
|
const { startCount, sleepCount, requestCount } = await sleepActor.getCounts();
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2254
|
+
expect11(sleepCount).toBe(0);
|
|
2255
|
+
expect11(startCount).toBe(1);
|
|
2256
|
+
expect11(requestCount).toBe(1);
|
|
2123
2257
|
}
|
|
2124
2258
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
2125
2259
|
{
|
|
2126
2260
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2127
|
-
|
|
2128
|
-
|
|
2261
|
+
expect11(sleepCount).toBe(1);
|
|
2262
|
+
expect11(startCount).toBe(2);
|
|
2129
2263
|
}
|
|
2130
2264
|
});
|
|
2131
|
-
|
|
2265
|
+
test11("noSleep option disables sleeping", async (c) => {
|
|
2132
2266
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2133
2267
|
const sleepActor = client.sleepWithNoSleepOption.getOrCreate();
|
|
2134
2268
|
{
|
|
2135
2269
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2136
|
-
|
|
2137
|
-
|
|
2270
|
+
expect11(sleepCount).toBe(0);
|
|
2271
|
+
expect11(startCount).toBe(1);
|
|
2138
2272
|
}
|
|
2139
2273
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
2140
2274
|
{
|
|
2141
2275
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2142
|
-
|
|
2143
|
-
|
|
2276
|
+
expect11(sleepCount).toBe(0);
|
|
2277
|
+
expect11(startCount).toBe(1);
|
|
2144
2278
|
}
|
|
2145
2279
|
await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
|
|
2146
2280
|
{
|
|
2147
2281
|
const { startCount, sleepCount } = await sleepActor.getCounts();
|
|
2148
|
-
|
|
2149
|
-
|
|
2282
|
+
expect11(sleepCount).toBe(0);
|
|
2283
|
+
expect11(startCount).toBe(1);
|
|
2150
2284
|
}
|
|
2151
2285
|
});
|
|
2152
2286
|
});
|
|
2153
2287
|
}
|
|
2154
2288
|
|
|
2155
2289
|
// src/driver-test-suite/tests/actor-state.ts
|
|
2156
|
-
import { describe as
|
|
2290
|
+
import { describe as describe12, expect as expect12, test as test12 } from "vitest";
|
|
2157
2291
|
function runActorStateTests(driverTestConfig) {
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2292
|
+
describe12("Actor State Tests", () => {
|
|
2293
|
+
describe12("State Persistence", () => {
|
|
2294
|
+
test12("persists state between actor instances", async (c) => {
|
|
2161
2295
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2162
2296
|
const counterInstance = client.counter.getOrCreate();
|
|
2163
2297
|
const initialCount = await counterInstance.increment(5);
|
|
2164
|
-
|
|
2298
|
+
expect12(initialCount).toBe(5);
|
|
2165
2299
|
const sameInstance = client.counter.getOrCreate();
|
|
2166
2300
|
const persistedCount = await sameInstance.increment(3);
|
|
2167
|
-
|
|
2301
|
+
expect12(persistedCount).toBe(8);
|
|
2168
2302
|
});
|
|
2169
|
-
|
|
2303
|
+
test12("restores state after actor disconnect/reconnect", async (c) => {
|
|
2170
2304
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2171
2305
|
const counterInstance = client.counter.getOrCreate();
|
|
2172
2306
|
await counterInstance.increment(5);
|
|
2173
2307
|
const reconnectedInstance = client.counter.getOrCreate();
|
|
2174
2308
|
const persistedCount = await reconnectedInstance.increment(0);
|
|
2175
|
-
|
|
2309
|
+
expect12(persistedCount).toBe(5);
|
|
2176
2310
|
});
|
|
2177
|
-
|
|
2311
|
+
test12("maintains separate state for different actors", async (c) => {
|
|
2178
2312
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2179
2313
|
const counterA = client.counter.getOrCreate(["counter-a"]);
|
|
2180
2314
|
await counterA.increment(5);
|
|
@@ -2182,8 +2316,8 @@ function runActorStateTests(driverTestConfig) {
|
|
|
2182
2316
|
await counterB.increment(10);
|
|
2183
2317
|
const countA = await counterA.increment(0);
|
|
2184
2318
|
const countB = await counterB.increment(0);
|
|
2185
|
-
|
|
2186
|
-
|
|
2319
|
+
expect12(countA).toBe(5);
|
|
2320
|
+
expect12(countB).toBe(10);
|
|
2187
2321
|
});
|
|
2188
2322
|
});
|
|
2189
2323
|
});
|
|
@@ -2191,90 +2325,91 @@ function runActorStateTests(driverTestConfig) {
|
|
|
2191
2325
|
|
|
2192
2326
|
// src/driver-test-suite/tests/actor-driver.ts
|
|
2193
2327
|
function runActorDriverTests(driverTestConfig) {
|
|
2194
|
-
|
|
2328
|
+
describe13("Actor Driver Tests", () => {
|
|
2195
2329
|
runActorStateTests(driverTestConfig);
|
|
2196
2330
|
runActorScheduleTests(driverTestConfig);
|
|
2197
2331
|
runActorSleepTests(driverTestConfig);
|
|
2332
|
+
runActorLifecycleTests(driverTestConfig);
|
|
2198
2333
|
});
|
|
2199
2334
|
}
|
|
2200
2335
|
|
|
2201
2336
|
// src/driver-test-suite/tests/actor-error-handling.ts
|
|
2202
|
-
import { describe as
|
|
2337
|
+
import { describe as describe14, expect as expect13, test as test13 } from "vitest";
|
|
2203
2338
|
function runActorErrorHandlingTests(driverTestConfig) {
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2339
|
+
describe14("Actor Error Handling Tests", () => {
|
|
2340
|
+
describe14("UserError Handling", () => {
|
|
2341
|
+
test13("should handle simple UserError with message", async (c) => {
|
|
2207
2342
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2208
2343
|
const handle = client.errorHandlingActor.getOrCreate();
|
|
2209
2344
|
try {
|
|
2210
2345
|
await handle.throwSimpleError();
|
|
2211
|
-
|
|
2346
|
+
expect13(true).toBe(false);
|
|
2212
2347
|
} catch (error) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2348
|
+
expect13(error.message).toBe("Simple error message");
|
|
2349
|
+
expect13(error.code).toBe("user_error");
|
|
2350
|
+
expect13(error.metadata).toBeUndefined();
|
|
2216
2351
|
}
|
|
2217
2352
|
});
|
|
2218
|
-
|
|
2353
|
+
test13("should handle detailed UserError with code and metadata", async (c) => {
|
|
2219
2354
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2220
2355
|
const handle = client.errorHandlingActor.getOrCreate();
|
|
2221
2356
|
try {
|
|
2222
2357
|
await handle.throwDetailedError();
|
|
2223
|
-
|
|
2358
|
+
expect13(true).toBe(false);
|
|
2224
2359
|
} catch (error) {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2360
|
+
expect13(error.message).toBe("Detailed error message");
|
|
2361
|
+
expect13(error.code).toBe("detailed_error");
|
|
2362
|
+
expect13(error.metadata).toBeDefined();
|
|
2363
|
+
expect13(error.metadata.reason).toBe("test");
|
|
2364
|
+
expect13(error.metadata.timestamp).toBeDefined();
|
|
2230
2365
|
}
|
|
2231
2366
|
});
|
|
2232
2367
|
});
|
|
2233
|
-
|
|
2234
|
-
|
|
2368
|
+
describe14("Internal Error Handling", () => {
|
|
2369
|
+
test13("should convert internal errors to safe format", async (c) => {
|
|
2235
2370
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2236
2371
|
const handle = client.errorHandlingActor.getOrCreate();
|
|
2237
2372
|
try {
|
|
2238
2373
|
await handle.throwInternalError();
|
|
2239
|
-
|
|
2374
|
+
expect13(true).toBe(false);
|
|
2240
2375
|
} catch (error) {
|
|
2241
|
-
|
|
2242
|
-
|
|
2376
|
+
expect13(error.code).toBe(INTERNAL_ERROR_CODE);
|
|
2377
|
+
expect13(error.message).toBe(INTERNAL_ERROR_DESCRIPTION);
|
|
2243
2378
|
}
|
|
2244
2379
|
});
|
|
2245
2380
|
});
|
|
2246
|
-
|
|
2247
|
-
|
|
2381
|
+
describe14.skip("Action Timeout", () => {
|
|
2382
|
+
test13("should handle action timeouts with custom duration", async (c) => {
|
|
2248
2383
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2249
2384
|
const handle = client.errorHandlingActor.getOrCreate();
|
|
2250
2385
|
const timeoutPromise = handle.timeoutAction();
|
|
2251
2386
|
try {
|
|
2252
2387
|
await timeoutPromise;
|
|
2253
|
-
|
|
2388
|
+
expect13(true).toBe(false);
|
|
2254
2389
|
} catch (error) {
|
|
2255
|
-
|
|
2390
|
+
expect13(error.message).toMatch(/timed out/i);
|
|
2256
2391
|
}
|
|
2257
2392
|
});
|
|
2258
|
-
|
|
2393
|
+
test13("should successfully run actions within timeout", async (c) => {
|
|
2259
2394
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2260
2395
|
const handle = client.errorHandlingActor.getOrCreate();
|
|
2261
2396
|
const result = await handle.delayedAction(200);
|
|
2262
|
-
|
|
2397
|
+
expect13(result).toBe("Completed after 200ms");
|
|
2263
2398
|
});
|
|
2264
|
-
|
|
2399
|
+
test13("should respect different timeouts for different actors", async (c) => {
|
|
2265
2400
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2266
2401
|
try {
|
|
2267
2402
|
await client.customTimeoutActor.getOrCreate().slowAction();
|
|
2268
|
-
|
|
2403
|
+
expect13(true).toBe(false);
|
|
2269
2404
|
} catch (error) {
|
|
2270
|
-
|
|
2405
|
+
expect13(error.message).toMatch(/timed out/i);
|
|
2271
2406
|
}
|
|
2272
2407
|
const quickResult = await client.customTimeoutActor.getOrCreate().quickAction();
|
|
2273
|
-
|
|
2408
|
+
expect13(quickResult).toBe("Quick action completed");
|
|
2274
2409
|
});
|
|
2275
2410
|
});
|
|
2276
|
-
|
|
2277
|
-
|
|
2411
|
+
describe14("Error Recovery", () => {
|
|
2412
|
+
test13("should continue working after errors", async (c) => {
|
|
2278
2413
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2279
2414
|
const handle = client.errorHandlingActor.getOrCreate();
|
|
2280
2415
|
try {
|
|
@@ -2282,27 +2417,27 @@ function runActorErrorHandlingTests(driverTestConfig) {
|
|
|
2282
2417
|
} catch (error) {
|
|
2283
2418
|
}
|
|
2284
2419
|
const result = await handle.successfulAction();
|
|
2285
|
-
|
|
2420
|
+
expect13(result).toBe("success");
|
|
2286
2421
|
});
|
|
2287
2422
|
});
|
|
2288
2423
|
});
|
|
2289
2424
|
}
|
|
2290
2425
|
|
|
2291
2426
|
// src/driver-test-suite/tests/actor-handle.ts
|
|
2292
|
-
import { describe as
|
|
2427
|
+
import { describe as describe15, expect as expect14, test as test14 } from "vitest";
|
|
2293
2428
|
function runActorHandleTests(driverTestConfig) {
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2429
|
+
describe15("Actor Handle Tests", () => {
|
|
2430
|
+
describe15("Access Methods", () => {
|
|
2431
|
+
test14("should use .get() to access a actor", async (c) => {
|
|
2297
2432
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2298
2433
|
await client.counter.create(["test-get-handle"]);
|
|
2299
2434
|
const handle = client.counter.get(["test-get-handle"]);
|
|
2300
2435
|
const count = await handle.increment(5);
|
|
2301
|
-
|
|
2436
|
+
expect14(count).toBe(5);
|
|
2302
2437
|
const retrievedCount = await handle.getCount();
|
|
2303
|
-
|
|
2438
|
+
expect14(retrievedCount).toBe(5);
|
|
2304
2439
|
});
|
|
2305
|
-
|
|
2440
|
+
test14("should use .getForId() to access a actor by ID", async (c) => {
|
|
2306
2441
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2307
2442
|
const handle = client.counter.getOrCreate([
|
|
2308
2443
|
"test-get-for-id-handle"
|
|
@@ -2311,73 +2446,73 @@ function runActorHandleTests(driverTestConfig) {
|
|
|
2311
2446
|
const actorId = await handle.resolve();
|
|
2312
2447
|
const idHandle = client.counter.getForId(actorId);
|
|
2313
2448
|
const count = await idHandle.getCount();
|
|
2314
|
-
|
|
2449
|
+
expect14(count).toBe(3);
|
|
2315
2450
|
const newCount = await idHandle.increment(4);
|
|
2316
|
-
|
|
2451
|
+
expect14(newCount).toBe(7);
|
|
2317
2452
|
});
|
|
2318
|
-
|
|
2453
|
+
test14("should use .getOrCreate() to access or create a actor", async (c) => {
|
|
2319
2454
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2320
2455
|
const handle = client.counter.getOrCreate([
|
|
2321
2456
|
"test-get-or-create-handle"
|
|
2322
2457
|
]);
|
|
2323
2458
|
const count = await handle.increment(7);
|
|
2324
|
-
|
|
2459
|
+
expect14(count).toBe(7);
|
|
2325
2460
|
const sameHandle = client.counter.getOrCreate([
|
|
2326
2461
|
"test-get-or-create-handle"
|
|
2327
2462
|
]);
|
|
2328
2463
|
const retrievedCount = await sameHandle.getCount();
|
|
2329
|
-
|
|
2464
|
+
expect14(retrievedCount).toBe(7);
|
|
2330
2465
|
});
|
|
2331
|
-
|
|
2466
|
+
test14("should use (await create()) to create and return a handle", async (c) => {
|
|
2332
2467
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2333
2468
|
const handle = await client.counter.create([
|
|
2334
2469
|
"test-create-handle"
|
|
2335
2470
|
]);
|
|
2336
2471
|
const count = await handle.increment(9);
|
|
2337
|
-
|
|
2472
|
+
expect14(count).toBe(9);
|
|
2338
2473
|
const retrievedCount = await handle.getCount();
|
|
2339
|
-
|
|
2474
|
+
expect14(retrievedCount).toBe(9);
|
|
2340
2475
|
});
|
|
2341
|
-
|
|
2476
|
+
test14("errors when calling create twice with the same key", async (c) => {
|
|
2342
2477
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2343
2478
|
const key = ["duplicate-create-handle", crypto.randomUUID()];
|
|
2344
2479
|
await client.counter.create(key);
|
|
2345
2480
|
try {
|
|
2346
2481
|
await client.counter.create(key);
|
|
2347
|
-
|
|
2482
|
+
expect14.fail("did not error on duplicate create");
|
|
2348
2483
|
} catch (err) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2484
|
+
expect14(err.group).toBe("actor");
|
|
2485
|
+
expect14(err.code).toBe("duplicate_key");
|
|
2351
2486
|
}
|
|
2352
2487
|
});
|
|
2353
|
-
|
|
2488
|
+
test14(".get().resolve() errors for non-existent actor", async (c) => {
|
|
2354
2489
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2355
2490
|
const missingId = `nonexistent-${crypto.randomUUID()}`;
|
|
2356
2491
|
try {
|
|
2357
2492
|
await client.counter.get([missingId]).resolve();
|
|
2358
|
-
|
|
2493
|
+
expect14.fail(
|
|
2359
2494
|
"did not error for get().resolve() on missing actor"
|
|
2360
2495
|
);
|
|
2361
2496
|
} catch (err) {
|
|
2362
|
-
|
|
2363
|
-
|
|
2497
|
+
expect14(err.group).toBe("actor");
|
|
2498
|
+
expect14(err.code).toBe("not_found");
|
|
2364
2499
|
}
|
|
2365
2500
|
});
|
|
2366
2501
|
});
|
|
2367
|
-
|
|
2368
|
-
|
|
2502
|
+
describe15("Action Functionality", () => {
|
|
2503
|
+
test14("should call actions directly on the handle", async (c) => {
|
|
2369
2504
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2370
2505
|
const handle = client.counter.getOrCreate([
|
|
2371
2506
|
"test-action-handle"
|
|
2372
2507
|
]);
|
|
2373
2508
|
const count1 = await handle.increment(3);
|
|
2374
|
-
|
|
2509
|
+
expect14(count1).toBe(3);
|
|
2375
2510
|
const count2 = await handle.increment(5);
|
|
2376
|
-
|
|
2511
|
+
expect14(count2).toBe(8);
|
|
2377
2512
|
const retrievedCount = await handle.getCount();
|
|
2378
|
-
|
|
2513
|
+
expect14(retrievedCount).toBe(8);
|
|
2379
2514
|
});
|
|
2380
|
-
|
|
2515
|
+
test14("should handle independent handles to the same actor", async (c) => {
|
|
2381
2516
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2382
2517
|
const handle1 = client.counter.getOrCreate([
|
|
2383
2518
|
"test-multiple-handles"
|
|
@@ -2385,82 +2520,82 @@ function runActorHandleTests(driverTestConfig) {
|
|
|
2385
2520
|
const handle2 = client.counter.get(["test-multiple-handles"]);
|
|
2386
2521
|
await handle1.increment(3);
|
|
2387
2522
|
const count = await handle2.getCount();
|
|
2388
|
-
|
|
2523
|
+
expect14(count).toBe(3);
|
|
2389
2524
|
const finalCount = await handle2.increment(4);
|
|
2390
|
-
|
|
2525
|
+
expect14(finalCount).toBe(7);
|
|
2391
2526
|
const checkCount = await handle1.getCount();
|
|
2392
|
-
|
|
2527
|
+
expect14(checkCount).toBe(7);
|
|
2393
2528
|
});
|
|
2394
|
-
|
|
2529
|
+
test14("should resolve a actor's ID", async (c) => {
|
|
2395
2530
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2396
2531
|
const handle = client.counter.getOrCreate(["test-resolve-id"]);
|
|
2397
2532
|
await handle.increment(1);
|
|
2398
2533
|
const actorId = await handle.resolve();
|
|
2399
|
-
|
|
2400
|
-
|
|
2534
|
+
expect14(typeof actorId).toBe("string");
|
|
2535
|
+
expect14(actorId).not.toBe("");
|
|
2401
2536
|
const idHandle = client.counter.getForId(actorId);
|
|
2402
2537
|
const count = await idHandle.getCount();
|
|
2403
|
-
|
|
2538
|
+
expect14(count).toBe(1);
|
|
2404
2539
|
});
|
|
2405
2540
|
});
|
|
2406
|
-
|
|
2407
|
-
|
|
2541
|
+
describe15("Lifecycle Hooks", () => {
|
|
2542
|
+
test14("should trigger lifecycle hooks on actor creation", async (c) => {
|
|
2408
2543
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2409
2544
|
const handle = client.counterWithLifecycle.getOrCreate([
|
|
2410
2545
|
"test-lifecycle-handle"
|
|
2411
2546
|
]);
|
|
2412
2547
|
const initialEvents = await handle.getEvents();
|
|
2413
|
-
|
|
2548
|
+
expect14(initialEvents).toContain("onWake");
|
|
2414
2549
|
const sameHandle = client.counterWithLifecycle.getOrCreate([
|
|
2415
2550
|
"test-lifecycle-handle"
|
|
2416
2551
|
]);
|
|
2417
2552
|
const events = await sameHandle.getEvents();
|
|
2418
|
-
|
|
2419
|
-
|
|
2553
|
+
expect14(events).toContain("onWake");
|
|
2554
|
+
expect14(events.filter((e) => e === "onWake").length).toBe(1);
|
|
2420
2555
|
});
|
|
2421
|
-
|
|
2556
|
+
test14("should trigger lifecycle hooks for each Action call", async (c) => {
|
|
2422
2557
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2423
2558
|
const viewHandle = client.counterWithLifecycle.getOrCreate([
|
|
2424
2559
|
"test-lifecycle-action"
|
|
2425
2560
|
]);
|
|
2426
2561
|
const initialEvents = await viewHandle.getEvents();
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2562
|
+
expect14(initialEvents).toContain("onWake");
|
|
2563
|
+
expect14(initialEvents).not.toContain("onBeforeConnect");
|
|
2564
|
+
expect14(initialEvents).not.toContain("onConnect");
|
|
2565
|
+
expect14(initialEvents).not.toContain("onDisconnect");
|
|
2431
2566
|
const trackingHandle = client.counterWithLifecycle.getOrCreate(
|
|
2432
2567
|
["test-lifecycle-action"],
|
|
2433
2568
|
{ params: { trackLifecycle: true } }
|
|
2434
2569
|
);
|
|
2435
2570
|
await trackingHandle.increment(5);
|
|
2436
2571
|
const eventsAfterAction = await viewHandle.getEvents();
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2572
|
+
expect14(eventsAfterAction).toContain("onBeforeConnect");
|
|
2573
|
+
expect14(eventsAfterAction).toContain("onConnect");
|
|
2574
|
+
expect14(eventsAfterAction).toContain("onDisconnect");
|
|
2575
|
+
expect14(
|
|
2441
2576
|
eventsAfterAction.filter((e) => e === "onBeforeConnect").length
|
|
2442
2577
|
).toBe(1);
|
|
2443
|
-
|
|
2578
|
+
expect14(
|
|
2444
2579
|
eventsAfterAction.filter((e) => e === "onConnect").length
|
|
2445
2580
|
).toBe(1);
|
|
2446
|
-
|
|
2581
|
+
expect14(
|
|
2447
2582
|
eventsAfterAction.filter((e) => e === "onDisconnect").length
|
|
2448
2583
|
).toBe(1);
|
|
2449
2584
|
await trackingHandle.increment(10);
|
|
2450
2585
|
const eventsAfterSecondAction = await viewHandle.getEvents();
|
|
2451
|
-
|
|
2586
|
+
expect14(
|
|
2452
2587
|
eventsAfterSecondAction.filter(
|
|
2453
2588
|
(e) => e === "onBeforeConnect"
|
|
2454
2589
|
).length
|
|
2455
2590
|
).toBe(2);
|
|
2456
|
-
|
|
2591
|
+
expect14(
|
|
2457
2592
|
eventsAfterSecondAction.filter((e) => e === "onConnect").length
|
|
2458
2593
|
).toBe(2);
|
|
2459
|
-
|
|
2594
|
+
expect14(
|
|
2460
2595
|
eventsAfterSecondAction.filter((e) => e === "onDisconnect").length
|
|
2461
2596
|
).toBe(2);
|
|
2462
2597
|
});
|
|
2463
|
-
|
|
2598
|
+
test14("should trigger lifecycle hooks for each Action call across multiple handles", async (c) => {
|
|
2464
2599
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2465
2600
|
const viewHandle = client.counterWithLifecycle.getOrCreate([
|
|
2466
2601
|
"test-lifecycle-multi-handle"
|
|
@@ -2476,12 +2611,12 @@ function runActorHandleTests(driverTestConfig) {
|
|
|
2476
2611
|
await trackingHandle1.increment(5);
|
|
2477
2612
|
await trackingHandle2.increment(10);
|
|
2478
2613
|
const events = await viewHandle.getEvents();
|
|
2479
|
-
|
|
2480
|
-
|
|
2614
|
+
expect14(events.filter((e) => e === "onWake").length).toBe(1);
|
|
2615
|
+
expect14(
|
|
2481
2616
|
events.filter((e) => e === "onBeforeConnect").length
|
|
2482
2617
|
).toBe(2);
|
|
2483
|
-
|
|
2484
|
-
|
|
2618
|
+
expect14(events.filter((e) => e === "onConnect").length).toBe(2);
|
|
2619
|
+
expect14(events.filter((e) => e === "onDisconnect").length).toBe(
|
|
2485
2620
|
2
|
|
2486
2621
|
);
|
|
2487
2622
|
});
|
|
@@ -2490,27 +2625,27 @@ function runActorHandleTests(driverTestConfig) {
|
|
|
2490
2625
|
}
|
|
2491
2626
|
|
|
2492
2627
|
// src/driver-test-suite/tests/actor-inline-client.ts
|
|
2493
|
-
import { describe as
|
|
2628
|
+
import { describe as describe16, expect as expect15, test as test15 } from "vitest";
|
|
2494
2629
|
function runActorInlineClientTests(driverTestConfig) {
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2630
|
+
describe16("Actor Inline Client Tests", () => {
|
|
2631
|
+
describe16("Stateless Client Calls", () => {
|
|
2632
|
+
test15("should make stateless calls to other actors", async (c) => {
|
|
2498
2633
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2499
2634
|
const inlineClientHandle = client.inlineClientActor.getOrCreate(
|
|
2500
2635
|
["inline-client-test"]
|
|
2501
2636
|
);
|
|
2502
2637
|
const result = await inlineClientHandle.callCounterIncrement(5);
|
|
2503
|
-
|
|
2638
|
+
expect15(result).toBe(5);
|
|
2504
2639
|
const counterState = await inlineClientHandle.getCounterState();
|
|
2505
|
-
|
|
2640
|
+
expect15(counterState).toBe(5);
|
|
2506
2641
|
const messages = await inlineClientHandle.getMessages();
|
|
2507
|
-
|
|
2508
|
-
|
|
2642
|
+
expect15(messages).toHaveLength(2);
|
|
2643
|
+
expect15(messages[0]).toContain(
|
|
2509
2644
|
"Called counter.increment(5), result: 5"
|
|
2510
2645
|
);
|
|
2511
|
-
|
|
2646
|
+
expect15(messages[1]).toContain("Got counter state: 5");
|
|
2512
2647
|
});
|
|
2513
|
-
|
|
2648
|
+
test15("should handle multiple stateless calls", async (c) => {
|
|
2514
2649
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2515
2650
|
const inlineClientHandle = client.inlineClientActor.getOrCreate(
|
|
2516
2651
|
["inline-client-multi"]
|
|
@@ -2519,58 +2654,58 @@ function runActorInlineClientTests(driverTestConfig) {
|
|
|
2519
2654
|
const result1 = await inlineClientHandle.callCounterIncrement(3);
|
|
2520
2655
|
const result2 = await inlineClientHandle.callCounterIncrement(7);
|
|
2521
2656
|
const finalState = await inlineClientHandle.getCounterState();
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2657
|
+
expect15(result1).toBe(3);
|
|
2658
|
+
expect15(result2).toBe(10);
|
|
2659
|
+
expect15(finalState).toBe(10);
|
|
2525
2660
|
const messages = await inlineClientHandle.getMessages();
|
|
2526
|
-
|
|
2527
|
-
|
|
2661
|
+
expect15(messages).toHaveLength(3);
|
|
2662
|
+
expect15(messages[0]).toContain(
|
|
2528
2663
|
"Called counter.increment(3), result: 3"
|
|
2529
2664
|
);
|
|
2530
|
-
|
|
2665
|
+
expect15(messages[1]).toContain(
|
|
2531
2666
|
"Called counter.increment(7), result: 10"
|
|
2532
2667
|
);
|
|
2533
|
-
|
|
2668
|
+
expect15(messages[2]).toContain("Got counter state: 10");
|
|
2534
2669
|
});
|
|
2535
2670
|
});
|
|
2536
|
-
|
|
2537
|
-
|
|
2671
|
+
describe16("Stateful Client Calls", () => {
|
|
2672
|
+
test15("should connect to other actors and receive events", async (c) => {
|
|
2538
2673
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2539
2674
|
const inlineClientHandle = client.inlineClientActor.getOrCreate(
|
|
2540
2675
|
["inline-client-stateful"]
|
|
2541
2676
|
);
|
|
2542
2677
|
await inlineClientHandle.clearMessages();
|
|
2543
2678
|
const result = await inlineClientHandle.connectToCounterAndIncrement(4);
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2679
|
+
expect15(result.result1).toBe(4);
|
|
2680
|
+
expect15(result.result2).toBe(12);
|
|
2681
|
+
expect15(result.events).toEqual([4, 12]);
|
|
2547
2682
|
const messages = await inlineClientHandle.getMessages();
|
|
2548
|
-
|
|
2549
|
-
|
|
2683
|
+
expect15(messages).toHaveLength(1);
|
|
2684
|
+
expect15(messages[0]).toContain(
|
|
2550
2685
|
"Connected to counter, incremented by 4 and 8"
|
|
2551
2686
|
);
|
|
2552
|
-
|
|
2553
|
-
|
|
2687
|
+
expect15(messages[0]).toContain("results: 4, 12");
|
|
2688
|
+
expect15(messages[0]).toContain("events: [4,12]");
|
|
2554
2689
|
});
|
|
2555
|
-
|
|
2690
|
+
test15("should handle stateful connection independently", async (c) => {
|
|
2556
2691
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2557
2692
|
const inlineClientHandle = client.inlineClientActor.getOrCreate(
|
|
2558
2693
|
["inline-client-independent"]
|
|
2559
2694
|
);
|
|
2560
2695
|
await inlineClientHandle.clearMessages();
|
|
2561
2696
|
const result = await inlineClientHandle.connectToCounterAndIncrement(2);
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2697
|
+
expect15(result.result1).toBe(2);
|
|
2698
|
+
expect15(result.result2).toBe(6);
|
|
2699
|
+
expect15(result.events).toEqual([2, 6]);
|
|
2565
2700
|
const messages = await inlineClientHandle.getMessages();
|
|
2566
|
-
|
|
2567
|
-
|
|
2701
|
+
expect15(messages).toHaveLength(1);
|
|
2702
|
+
expect15(messages[0]).toContain(
|
|
2568
2703
|
"Connected to counter, incremented by 2 and 4"
|
|
2569
2704
|
);
|
|
2570
2705
|
});
|
|
2571
2706
|
});
|
|
2572
|
-
|
|
2573
|
-
|
|
2707
|
+
describe16("Mixed Client Usage", () => {
|
|
2708
|
+
test15("should handle both stateless and stateful calls", async (c) => {
|
|
2574
2709
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2575
2710
|
const inlineClientHandle = client.inlineClientActor.getOrCreate(
|
|
2576
2711
|
["inline-client-mixed"]
|
|
@@ -2578,17 +2713,17 @@ function runActorInlineClientTests(driverTestConfig) {
|
|
|
2578
2713
|
await inlineClientHandle.clearMessages();
|
|
2579
2714
|
await inlineClientHandle.callCounterIncrement(1);
|
|
2580
2715
|
const statelessResult = await inlineClientHandle.getCounterState();
|
|
2581
|
-
|
|
2716
|
+
expect15(statelessResult).toBe(1);
|
|
2582
2717
|
const statefulResult = await inlineClientHandle.connectToCounterAndIncrement(3);
|
|
2583
|
-
|
|
2584
|
-
|
|
2718
|
+
expect15(statefulResult.result1).toBe(3);
|
|
2719
|
+
expect15(statefulResult.result2).toBe(9);
|
|
2585
2720
|
const messages = await inlineClientHandle.getMessages();
|
|
2586
|
-
|
|
2587
|
-
|
|
2721
|
+
expect15(messages).toHaveLength(3);
|
|
2722
|
+
expect15(messages[0]).toContain(
|
|
2588
2723
|
"Called counter.increment(1), result: 1"
|
|
2589
2724
|
);
|
|
2590
|
-
|
|
2591
|
-
|
|
2725
|
+
expect15(messages[1]).toContain("Got counter state: 1");
|
|
2726
|
+
expect15(messages[2]).toContain(
|
|
2592
2727
|
"Connected to counter, incremented by 3 and 6"
|
|
2593
2728
|
);
|
|
2594
2729
|
});
|
|
@@ -2597,10 +2732,10 @@ function runActorInlineClientTests(driverTestConfig) {
|
|
|
2597
2732
|
}
|
|
2598
2733
|
|
|
2599
2734
|
// src/driver-test-suite/tests/actor-inspector.ts
|
|
2600
|
-
import { describe as
|
|
2735
|
+
import { describe as describe17, expect as expect16, test as test16 } from "vitest";
|
|
2601
2736
|
function runActorInspectorTests(driverTestConfig) {
|
|
2602
|
-
|
|
2603
|
-
|
|
2737
|
+
describe17("Actor Inspector HTTP API", () => {
|
|
2738
|
+
test16("GET /inspector/state returns actor state", async (c) => {
|
|
2604
2739
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2605
2740
|
const handle = client.counter.getOrCreate(["inspector-state"]);
|
|
2606
2741
|
await handle.increment(5);
|
|
@@ -2608,11 +2743,11 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2608
2743
|
const response = await fetch(`${gatewayUrl}/inspector/state`, {
|
|
2609
2744
|
headers: { Authorization: "Bearer token" }
|
|
2610
2745
|
});
|
|
2611
|
-
|
|
2746
|
+
expect16(response.status).toBe(200);
|
|
2612
2747
|
const data = await response.json();
|
|
2613
|
-
|
|
2748
|
+
expect16(data).toEqual({ state: { count: 5 } });
|
|
2614
2749
|
});
|
|
2615
|
-
|
|
2750
|
+
test16("PATCH /inspector/state updates actor state", async (c) => {
|
|
2616
2751
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2617
2752
|
const handle = client.counter.getOrCreate([
|
|
2618
2753
|
"inspector-set-state"
|
|
@@ -2630,13 +2765,13 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2630
2765
|
body: JSON.stringify({ state: { count: 42 } })
|
|
2631
2766
|
}
|
|
2632
2767
|
);
|
|
2633
|
-
|
|
2768
|
+
expect16(patchResponse.status).toBe(200);
|
|
2634
2769
|
const patchData = await patchResponse.json();
|
|
2635
|
-
|
|
2770
|
+
expect16(patchData).toEqual({ ok: true });
|
|
2636
2771
|
const count = await handle.getCount();
|
|
2637
|
-
|
|
2772
|
+
expect16(count).toBe(42);
|
|
2638
2773
|
});
|
|
2639
|
-
|
|
2774
|
+
test16("GET /inspector/connections returns connections list", async (c) => {
|
|
2640
2775
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2641
2776
|
const handle = client.counter.getOrCreate([
|
|
2642
2777
|
"inspector-connections"
|
|
@@ -2649,12 +2784,12 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2649
2784
|
headers: { Authorization: "Bearer token" }
|
|
2650
2785
|
}
|
|
2651
2786
|
);
|
|
2652
|
-
|
|
2787
|
+
expect16(response.status).toBe(200);
|
|
2653
2788
|
const data = await response.json();
|
|
2654
|
-
|
|
2655
|
-
|
|
2789
|
+
expect16(data).toHaveProperty("connections");
|
|
2790
|
+
expect16(Array.isArray(data.connections)).toBe(true);
|
|
2656
2791
|
});
|
|
2657
|
-
|
|
2792
|
+
test16("GET /inspector/rpcs returns available actions", async (c) => {
|
|
2658
2793
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2659
2794
|
const handle = client.counter.getOrCreate(["inspector-rpcs"]);
|
|
2660
2795
|
await handle.increment(0);
|
|
@@ -2662,14 +2797,14 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2662
2797
|
const response = await fetch(`${gatewayUrl}/inspector/rpcs`, {
|
|
2663
2798
|
headers: { Authorization: "Bearer token" }
|
|
2664
2799
|
});
|
|
2665
|
-
|
|
2800
|
+
expect16(response.status).toBe(200);
|
|
2666
2801
|
const data = await response.json();
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2802
|
+
expect16(data).toHaveProperty("rpcs");
|
|
2803
|
+
expect16(data.rpcs).toContain("increment");
|
|
2804
|
+
expect16(data.rpcs).toContain("getCount");
|
|
2805
|
+
expect16(data.rpcs).toContain("setCount");
|
|
2671
2806
|
});
|
|
2672
|
-
|
|
2807
|
+
test16("POST /inspector/action/:name executes an action", async (c) => {
|
|
2673
2808
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2674
2809
|
const handle = client.counter.getOrCreate([
|
|
2675
2810
|
"inspector-action"
|
|
@@ -2687,13 +2822,13 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2687
2822
|
body: JSON.stringify({ args: [5] })
|
|
2688
2823
|
}
|
|
2689
2824
|
);
|
|
2690
|
-
|
|
2825
|
+
expect16(response.status).toBe(200);
|
|
2691
2826
|
const data = await response.json();
|
|
2692
|
-
|
|
2827
|
+
expect16(data.output).toBe(15);
|
|
2693
2828
|
const count = await handle.getCount();
|
|
2694
|
-
|
|
2829
|
+
expect16(count).toBe(15);
|
|
2695
2830
|
});
|
|
2696
|
-
|
|
2831
|
+
test16("GET /inspector/queue returns queue status", async (c) => {
|
|
2697
2832
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2698
2833
|
const handle = client.counter.getOrCreate(["inspector-queue"]);
|
|
2699
2834
|
await handle.increment(0);
|
|
@@ -2704,18 +2839,18 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2704
2839
|
headers: { Authorization: "Bearer token" }
|
|
2705
2840
|
}
|
|
2706
2841
|
);
|
|
2707
|
-
|
|
2842
|
+
expect16(response.status).toBe(200);
|
|
2708
2843
|
const data = await response.json();
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
});
|
|
2718
|
-
|
|
2844
|
+
expect16(data).toHaveProperty("size");
|
|
2845
|
+
expect16(data).toHaveProperty("maxSize");
|
|
2846
|
+
expect16(data).toHaveProperty("truncated");
|
|
2847
|
+
expect16(data).toHaveProperty("messages");
|
|
2848
|
+
expect16(typeof data.size).toBe("number");
|
|
2849
|
+
expect16(typeof data.maxSize).toBe("number");
|
|
2850
|
+
expect16(typeof data.truncated).toBe("boolean");
|
|
2851
|
+
expect16(Array.isArray(data.messages)).toBe(true);
|
|
2852
|
+
});
|
|
2853
|
+
test16("GET /inspector/traces returns trace data", async (c) => {
|
|
2719
2854
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2720
2855
|
const handle = client.counter.getOrCreate([
|
|
2721
2856
|
"inspector-traces"
|
|
@@ -2728,13 +2863,13 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2728
2863
|
headers: { Authorization: "Bearer token" }
|
|
2729
2864
|
}
|
|
2730
2865
|
);
|
|
2731
|
-
|
|
2866
|
+
expect16(response.status).toBe(200);
|
|
2732
2867
|
const data = await response.json();
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2868
|
+
expect16(data).toHaveProperty("otlp");
|
|
2869
|
+
expect16(data).toHaveProperty("clamped");
|
|
2870
|
+
expect16(typeof data.clamped).toBe("boolean");
|
|
2736
2871
|
});
|
|
2737
|
-
|
|
2872
|
+
test16("GET /inspector/workflow-history returns workflow status", async (c) => {
|
|
2738
2873
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2739
2874
|
const handle = client.counter.getOrCreate([
|
|
2740
2875
|
"inspector-workflow"
|
|
@@ -2747,14 +2882,14 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2747
2882
|
headers: { Authorization: "Bearer token" }
|
|
2748
2883
|
}
|
|
2749
2884
|
);
|
|
2750
|
-
|
|
2885
|
+
expect16(response.status).toBe(200);
|
|
2751
2886
|
const data = await response.json();
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2887
|
+
expect16(data).toHaveProperty("history");
|
|
2888
|
+
expect16(data).toHaveProperty("isWorkflowEnabled");
|
|
2889
|
+
expect16(data.isWorkflowEnabled).toBe(false);
|
|
2890
|
+
expect16(data.history).toBeNull();
|
|
2756
2891
|
});
|
|
2757
|
-
|
|
2892
|
+
test16("GET /inspector/summary returns full actor snapshot", async (c) => {
|
|
2758
2893
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2759
2894
|
const handle = client.counter.getOrCreate([
|
|
2760
2895
|
"inspector-summary"
|
|
@@ -2767,18 +2902,18 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2767
2902
|
headers: { Authorization: "Bearer token" }
|
|
2768
2903
|
}
|
|
2769
2904
|
);
|
|
2770
|
-
|
|
2905
|
+
expect16(response.status).toBe(200);
|
|
2771
2906
|
const data = await response.json();
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
});
|
|
2781
|
-
|
|
2907
|
+
expect16(data.state).toEqual({ count: 7 });
|
|
2908
|
+
expect16(Array.isArray(data.connections)).toBe(true);
|
|
2909
|
+
expect16(data.rpcs).toContain("increment");
|
|
2910
|
+
expect16(typeof data.queueSize).toBe("number");
|
|
2911
|
+
expect16(data.isStateEnabled).toBe(true);
|
|
2912
|
+
expect16(typeof data.isDatabaseEnabled).toBe("boolean");
|
|
2913
|
+
expect16(data.isWorkflowEnabled).toBe(false);
|
|
2914
|
+
expect16(data.workflowHistory).toBeNull();
|
|
2915
|
+
});
|
|
2916
|
+
test16("inspector endpoints require auth in non-dev mode", async (c) => {
|
|
2782
2917
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2783
2918
|
const handle = client.counter.getOrCreate([
|
|
2784
2919
|
"inspector-auth"
|
|
@@ -2788,16 +2923,16 @@ function runActorInspectorTests(driverTestConfig) {
|
|
|
2788
2923
|
const response = await fetch(`${gatewayUrl}/inspector/state`, {
|
|
2789
2924
|
headers: { Authorization: "Bearer wrong-token" }
|
|
2790
2925
|
});
|
|
2791
|
-
|
|
2926
|
+
expect16(response.status).toBe(401);
|
|
2792
2927
|
});
|
|
2793
2928
|
});
|
|
2794
2929
|
}
|
|
2795
2930
|
|
|
2796
2931
|
// src/driver-test-suite/tests/actor-kv.ts
|
|
2797
|
-
import { describe as
|
|
2932
|
+
import { describe as describe18, expect as expect17, test as test17 } from "vitest";
|
|
2798
2933
|
function runActorKvTests(driverTestConfig) {
|
|
2799
|
-
|
|
2800
|
-
|
|
2934
|
+
describe18("Actor KV Tests", () => {
|
|
2935
|
+
test17("supports text encoding and decoding", async (c) => {
|
|
2801
2936
|
const { client: rawClient } = await setupDriverTest(
|
|
2802
2937
|
c,
|
|
2803
2938
|
driverTestConfig
|
|
@@ -2806,17 +2941,17 @@ function runActorKvTests(driverTestConfig) {
|
|
|
2806
2941
|
const kvHandle = client.kvActor.getOrCreate(["kv-text"]);
|
|
2807
2942
|
await kvHandle.putText("greeting", "hello");
|
|
2808
2943
|
const value = await kvHandle.getText("greeting");
|
|
2809
|
-
|
|
2944
|
+
expect17(value).toBe("hello");
|
|
2810
2945
|
await kvHandle.putText("prefix-a", "alpha");
|
|
2811
2946
|
await kvHandle.putText("prefix-b", "beta");
|
|
2812
2947
|
const results = await kvHandle.listText("prefix-");
|
|
2813
2948
|
const sorted = results.sort((a, b) => a.key.localeCompare(b.key));
|
|
2814
|
-
|
|
2949
|
+
expect17(sorted).toEqual([
|
|
2815
2950
|
{ key: "prefix-a", value: "alpha" },
|
|
2816
2951
|
{ key: "prefix-b", value: "beta" }
|
|
2817
2952
|
]);
|
|
2818
2953
|
});
|
|
2819
|
-
|
|
2954
|
+
test17(
|
|
2820
2955
|
"supports arrayBuffer encoding and decoding",
|
|
2821
2956
|
async (c) => {
|
|
2822
2957
|
const { client: rawClient } = await setupDriverTest(
|
|
@@ -2835,32 +2970,32 @@ function runActorKvTests(driverTestConfig) {
|
|
|
2835
2970
|
23,
|
|
2836
2971
|
42
|
|
2837
2972
|
]);
|
|
2838
|
-
|
|
2973
|
+
expect17(values).toEqual([4, 8, 15, 16, 23, 42]);
|
|
2839
2974
|
}
|
|
2840
2975
|
);
|
|
2841
2976
|
});
|
|
2842
2977
|
}
|
|
2843
2978
|
|
|
2844
2979
|
// src/driver-test-suite/tests/actor-metadata.ts
|
|
2845
|
-
import { describe as
|
|
2980
|
+
import { describe as describe19, expect as expect18, test as test18 } from "vitest";
|
|
2846
2981
|
function runActorMetadataTests(driverTestConfig) {
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2982
|
+
describe19("Actor Metadata Tests", () => {
|
|
2983
|
+
describe19("Actor Name", () => {
|
|
2984
|
+
test18("should provide access to actor name", async (c) => {
|
|
2850
2985
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2851
2986
|
const handle = client.metadataActor.getOrCreate();
|
|
2852
2987
|
const actorName = await handle.getActorName();
|
|
2853
|
-
|
|
2988
|
+
expect18(actorName).toBe("metadataActor");
|
|
2854
2989
|
});
|
|
2855
|
-
|
|
2990
|
+
test18("should preserve actor name in state during onWake", async (c) => {
|
|
2856
2991
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2857
2992
|
const handle = client.metadataActor.getOrCreate();
|
|
2858
2993
|
const storedName = await handle.getStoredActorName();
|
|
2859
|
-
|
|
2994
|
+
expect18(storedName).toBe("metadataActor");
|
|
2860
2995
|
});
|
|
2861
2996
|
});
|
|
2862
|
-
|
|
2863
|
-
|
|
2997
|
+
describe19("Actor Tags", () => {
|
|
2998
|
+
test18("should provide access to tags", async (c) => {
|
|
2864
2999
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2865
3000
|
const handle = client.metadataActor.getOrCreate();
|
|
2866
3001
|
await handle.setupTestTags({
|
|
@@ -2868,12 +3003,12 @@ function runActorMetadataTests(driverTestConfig) {
|
|
|
2868
3003
|
purpose: "metadata-test"
|
|
2869
3004
|
});
|
|
2870
3005
|
const tags = await handle.getTags();
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
3006
|
+
expect18(tags).toHaveProperty("env");
|
|
3007
|
+
expect18(tags.env).toBe("test");
|
|
3008
|
+
expect18(tags).toHaveProperty("purpose");
|
|
3009
|
+
expect18(tags.purpose).toBe("metadata-test");
|
|
2875
3010
|
});
|
|
2876
|
-
|
|
3011
|
+
test18("should allow accessing individual tags", async (c) => {
|
|
2877
3012
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2878
3013
|
const handle = client.metadataActor.getOrCreate();
|
|
2879
3014
|
await handle.setupTestTags({
|
|
@@ -2883,128 +3018,128 @@ function runActorMetadataTests(driverTestConfig) {
|
|
|
2883
3018
|
const category = await handle.getTag("category");
|
|
2884
3019
|
const version = await handle.getTag("version");
|
|
2885
3020
|
const nonexistent = await handle.getTag("nonexistent");
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
3021
|
+
expect18(category).toBe("test-actor");
|
|
3022
|
+
expect18(version).toBe("1.0");
|
|
3023
|
+
expect18(nonexistent).toBeNull();
|
|
2889
3024
|
});
|
|
2890
3025
|
});
|
|
2891
|
-
|
|
2892
|
-
|
|
3026
|
+
describe19("Metadata Structure", () => {
|
|
3027
|
+
test18("should provide complete metadata object", async (c) => {
|
|
2893
3028
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2894
3029
|
const handle = client.metadataActor.getOrCreate();
|
|
2895
3030
|
await handle.setupTestTags({ type: "metadata-test" });
|
|
2896
3031
|
await handle.setupTestRegion("us-west-1");
|
|
2897
3032
|
const metadata = await handle.getMetadata();
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
3033
|
+
expect18(metadata).toHaveProperty("name");
|
|
3034
|
+
expect18(metadata.name).toBe("metadataActor");
|
|
3035
|
+
expect18(metadata).toHaveProperty("tags");
|
|
3036
|
+
expect18(metadata.tags).toHaveProperty("type");
|
|
3037
|
+
expect18(metadata.tags.type).toBe("metadata-test");
|
|
3038
|
+
expect18(metadata).toHaveProperty("region");
|
|
3039
|
+
expect18(metadata.region).toBe("us-west-1");
|
|
2905
3040
|
});
|
|
2906
3041
|
});
|
|
2907
|
-
|
|
2908
|
-
|
|
3042
|
+
describe19("Region Information", () => {
|
|
3043
|
+
test18("should retrieve region information", async (c) => {
|
|
2909
3044
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2910
3045
|
const handle = client.metadataActor.getOrCreate();
|
|
2911
3046
|
await handle.setupTestRegion("eu-central-1");
|
|
2912
3047
|
const region = await handle.getRegion();
|
|
2913
|
-
|
|
3048
|
+
expect18(region).toBe("eu-central-1");
|
|
2914
3049
|
});
|
|
2915
3050
|
});
|
|
2916
3051
|
});
|
|
2917
3052
|
}
|
|
2918
3053
|
|
|
2919
3054
|
// src/driver-test-suite/tests/actor-onstatechange.ts
|
|
2920
|
-
import { describe as
|
|
3055
|
+
import { describe as describe20, expect as expect19, test as test19 } from "vitest";
|
|
2921
3056
|
function runActorOnStateChangeTests(driverTestConfig) {
|
|
2922
|
-
|
|
2923
|
-
|
|
3057
|
+
describe20("Actor onStateChange Tests", () => {
|
|
3058
|
+
test19("triggers onStateChange when state is modified", async (c) => {
|
|
2924
3059
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2925
3060
|
const actor = client.onStateChangeActor.getOrCreate();
|
|
2926
3061
|
await actor.setValue(10);
|
|
2927
3062
|
const changeCount = await actor.getChangeCount();
|
|
2928
|
-
|
|
3063
|
+
expect19(changeCount).toBe(1);
|
|
2929
3064
|
});
|
|
2930
|
-
|
|
3065
|
+
test19("triggers onChange multiple times for multiple state changes", async (c) => {
|
|
2931
3066
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2932
3067
|
const actor = client.onStateChangeActor.getOrCreate();
|
|
2933
3068
|
await actor.incrementMultiple(3);
|
|
2934
3069
|
const changeCount = await actor.getChangeCount();
|
|
2935
|
-
|
|
3070
|
+
expect19(changeCount).toBe(3);
|
|
2936
3071
|
});
|
|
2937
|
-
|
|
3072
|
+
test19("does NOT trigger onChange for read-only actions", async (c) => {
|
|
2938
3073
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2939
3074
|
const actor = client.onStateChangeActor.getOrCreate();
|
|
2940
3075
|
await actor.setValue(5);
|
|
2941
3076
|
const value = await actor.getValue();
|
|
2942
|
-
|
|
3077
|
+
expect19(value).toBe(5);
|
|
2943
3078
|
const changeCount = await actor.getChangeCount();
|
|
2944
|
-
|
|
3079
|
+
expect19(changeCount).toBe(1);
|
|
2945
3080
|
});
|
|
2946
|
-
|
|
3081
|
+
test19("does NOT trigger onChange for computed values", async (c) => {
|
|
2947
3082
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2948
3083
|
const actor = client.onStateChangeActor.getOrCreate();
|
|
2949
3084
|
await actor.setValue(3);
|
|
2950
3085
|
{
|
|
2951
3086
|
const changeCount = await actor.getChangeCount();
|
|
2952
|
-
|
|
3087
|
+
expect19(changeCount).toBe(1);
|
|
2953
3088
|
}
|
|
2954
3089
|
const doubled = await actor.getDoubled();
|
|
2955
|
-
|
|
3090
|
+
expect19(doubled).toBe(6);
|
|
2956
3091
|
{
|
|
2957
3092
|
const changeCount = await actor.getChangeCount();
|
|
2958
|
-
|
|
3093
|
+
expect19(changeCount).toBe(1);
|
|
2959
3094
|
}
|
|
2960
3095
|
});
|
|
2961
|
-
|
|
3096
|
+
test19("simple: connect, call action, dispose does NOT trigger onChange", async (c) => {
|
|
2962
3097
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2963
3098
|
const actor = client.onStateChangeActor.getOrCreate();
|
|
2964
3099
|
const connection = await actor.connect();
|
|
2965
3100
|
const value = await connection.getValue();
|
|
2966
|
-
|
|
3101
|
+
expect19(value).toBe(0);
|
|
2967
3102
|
await connection.dispose();
|
|
2968
3103
|
const changeCount = await actor.getChangeCount();
|
|
2969
|
-
|
|
3104
|
+
expect19(changeCount).toBe(0);
|
|
2970
3105
|
});
|
|
2971
3106
|
});
|
|
2972
3107
|
}
|
|
2973
3108
|
|
|
2974
3109
|
// src/driver-test-suite/tests/actor-queue.ts
|
|
2975
|
-
import { describe as
|
|
3110
|
+
import { describe as describe21, expect as expect20, test as test20 } from "vitest";
|
|
2976
3111
|
function runActorQueueTests(driverTestConfig) {
|
|
2977
|
-
|
|
2978
|
-
|
|
3112
|
+
describe21("Actor Queue Tests", () => {
|
|
3113
|
+
test20("client can send to actor queue", async (c) => {
|
|
2979
3114
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2980
3115
|
const handle = client.queueActor.getOrCreate(["client-send"]);
|
|
2981
3116
|
await handle.send("greeting", { hello: "world" });
|
|
2982
3117
|
const message = await handle.receiveOne("greeting");
|
|
2983
|
-
|
|
3118
|
+
expect20(message).toEqual({
|
|
2984
3119
|
name: "greeting",
|
|
2985
3120
|
body: { hello: "world" }
|
|
2986
3121
|
});
|
|
2987
3122
|
});
|
|
2988
|
-
|
|
3123
|
+
test20("actor can send to its own queue", async (c) => {
|
|
2989
3124
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2990
3125
|
const handle = client.queueActor.getOrCreate(["self-send"]);
|
|
2991
3126
|
await handle.sendToSelf("self", { value: 42 });
|
|
2992
3127
|
const message = await handle.receiveOne("self");
|
|
2993
|
-
|
|
3128
|
+
expect20(message).toEqual({ name: "self", body: { value: 42 } });
|
|
2994
3129
|
});
|
|
2995
|
-
|
|
3130
|
+
test20("nextBatch supports name arrays and counts", async (c) => {
|
|
2996
3131
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
2997
3132
|
const handle = client.queueActor.getOrCreate(["receive-array"]);
|
|
2998
3133
|
await handle.send("a", 1);
|
|
2999
3134
|
await handle.send("b", 2);
|
|
3000
3135
|
await handle.send("c", 3);
|
|
3001
3136
|
const messages = await handle.receiveMany(["a", "b"], { count: 2 });
|
|
3002
|
-
|
|
3137
|
+
expect20(messages).toEqual([
|
|
3003
3138
|
{ name: "a", body: 1 },
|
|
3004
3139
|
{ name: "b", body: 2 }
|
|
3005
3140
|
]);
|
|
3006
3141
|
});
|
|
3007
|
-
|
|
3142
|
+
test20("nextBatch supports request objects", async (c) => {
|
|
3008
3143
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3009
3144
|
const handle = client.queueActor.getOrCreate(["receive-request"]);
|
|
3010
3145
|
await handle.send("one", "first");
|
|
@@ -3013,12 +3148,12 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3013
3148
|
names: ["one", "two"],
|
|
3014
3149
|
count: 2
|
|
3015
3150
|
});
|
|
3016
|
-
|
|
3151
|
+
expect20(messages).toEqual([
|
|
3017
3152
|
{ name: "one", body: "first" },
|
|
3018
3153
|
{ name: "two", body: "second" }
|
|
3019
3154
|
]);
|
|
3020
3155
|
});
|
|
3021
|
-
|
|
3156
|
+
test20("nextBatch defaults to all names when names is omitted", async (c) => {
|
|
3022
3157
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3023
3158
|
const handle = client.queueActor.getOrCreate([
|
|
3024
3159
|
"receive-request-all"
|
|
@@ -3026,66 +3161,66 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3026
3161
|
await handle.send("one", "first");
|
|
3027
3162
|
await handle.send("two", "second");
|
|
3028
3163
|
const messages = await handle.receiveRequest({ count: 2 });
|
|
3029
|
-
|
|
3164
|
+
expect20(messages).toEqual([
|
|
3030
3165
|
{ name: "one", body: "first" },
|
|
3031
3166
|
{ name: "two", body: "second" }
|
|
3032
3167
|
]);
|
|
3033
3168
|
});
|
|
3034
|
-
|
|
3169
|
+
test20("next timeout returns empty array", async (c) => {
|
|
3035
3170
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3036
3171
|
const handle = client.queueActor.getOrCreate(["receive-timeout"]);
|
|
3037
3172
|
const promise = handle.receiveMany(["missing"], { timeout: 50 });
|
|
3038
3173
|
await waitFor(driverTestConfig, 60);
|
|
3039
3174
|
const messages = await promise;
|
|
3040
|
-
|
|
3175
|
+
expect20(messages).toEqual([]);
|
|
3041
3176
|
});
|
|
3042
|
-
|
|
3177
|
+
test20("tryNextBatch does not wait and returns empty array", async (c) => {
|
|
3043
3178
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3044
3179
|
const handle = client.queueActor.getOrCreate(["try-next-empty"]);
|
|
3045
3180
|
const messages = await handle.tryReceiveMany({
|
|
3046
3181
|
names: ["missing"],
|
|
3047
3182
|
count: 1
|
|
3048
3183
|
});
|
|
3049
|
-
|
|
3184
|
+
expect20(messages).toEqual([]);
|
|
3050
3185
|
});
|
|
3051
|
-
|
|
3186
|
+
test20("abort throws ActorAborted", async (c) => {
|
|
3052
3187
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3053
3188
|
const handle = client.queueActor.getOrCreate(["abort-test"]);
|
|
3054
3189
|
try {
|
|
3055
3190
|
await handle.waitForAbort();
|
|
3056
|
-
|
|
3191
|
+
expect20.fail("expected ActorAborted error");
|
|
3057
3192
|
} catch (error) {
|
|
3058
|
-
|
|
3059
|
-
|
|
3193
|
+
expect20(error.group).toBe("actor");
|
|
3194
|
+
expect20(error.code).toBe("aborted");
|
|
3060
3195
|
}
|
|
3061
3196
|
});
|
|
3062
|
-
|
|
3197
|
+
test20("next supports signal abort", async (c) => {
|
|
3063
3198
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3064
3199
|
const handle = client.queueActor.getOrCreate(["signal-abort-next"]);
|
|
3065
3200
|
const result = await handle.waitForSignalAbort();
|
|
3066
|
-
|
|
3201
|
+
expect20(result).toEqual({
|
|
3067
3202
|
group: "actor",
|
|
3068
3203
|
code: "aborted"
|
|
3069
3204
|
});
|
|
3070
3205
|
});
|
|
3071
|
-
|
|
3206
|
+
test20("next supports actor abort when signal is provided", async (c) => {
|
|
3072
3207
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3073
3208
|
const handle = client.queueActor.getOrCreate([
|
|
3074
3209
|
"actor-abort-with-signal-next"
|
|
3075
3210
|
]);
|
|
3076
3211
|
const result = await handle.waitForActorAbortWithSignal();
|
|
3077
|
-
|
|
3212
|
+
expect20(result).toEqual({
|
|
3078
3213
|
group: "actor",
|
|
3079
3214
|
code: "aborted"
|
|
3080
3215
|
});
|
|
3081
3216
|
});
|
|
3082
|
-
|
|
3217
|
+
test20("iter supports signal abort", async (c) => {
|
|
3083
3218
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3084
3219
|
const handle = client.queueActor.getOrCreate(["signal-abort-iter"]);
|
|
3085
3220
|
const result = await handle.iterWithSignalAbort();
|
|
3086
|
-
|
|
3221
|
+
expect20(result).toEqual({ ok: true });
|
|
3087
3222
|
});
|
|
3088
|
-
|
|
3223
|
+
test20("enforces queue size limit", async (c) => {
|
|
3089
3224
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3090
3225
|
const key = `size-limit-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
3091
3226
|
const handle = client.queueLimitedActor.getOrCreate([key]);
|
|
@@ -3093,19 +3228,19 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3093
3228
|
await waitFor(driverTestConfig, 10);
|
|
3094
3229
|
try {
|
|
3095
3230
|
await handle.send("message", 2);
|
|
3096
|
-
|
|
3231
|
+
expect20.fail("expected queue full error");
|
|
3097
3232
|
} catch (error) {
|
|
3098
|
-
|
|
3099
|
-
|
|
3233
|
+
expect20(error).toBeInstanceOf(Error);
|
|
3234
|
+
expect20(error.message).toContain(
|
|
3100
3235
|
"Queue is full. Limit is"
|
|
3101
3236
|
);
|
|
3102
3237
|
if (driverTestConfig.clientType !== "http") {
|
|
3103
|
-
|
|
3104
|
-
|
|
3238
|
+
expect20(error.group).toBe("queue");
|
|
3239
|
+
expect20(error.code).toBe("full");
|
|
3105
3240
|
}
|
|
3106
3241
|
}
|
|
3107
3242
|
});
|
|
3108
|
-
|
|
3243
|
+
test20("enforces message size limit", async (c) => {
|
|
3109
3244
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3110
3245
|
const handle = client.queueLimitedActor.getOrCreate([
|
|
3111
3246
|
"message-limit"
|
|
@@ -3113,13 +3248,13 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3113
3248
|
const largePayload = "a".repeat(200);
|
|
3114
3249
|
try {
|
|
3115
3250
|
await handle.send("oversize", largePayload);
|
|
3116
|
-
|
|
3251
|
+
expect20.fail("expected message_too_large error");
|
|
3117
3252
|
} catch (error) {
|
|
3118
|
-
|
|
3119
|
-
|
|
3253
|
+
expect20(error.group).toBe("queue");
|
|
3254
|
+
expect20(error.code).toBe("message_too_large");
|
|
3120
3255
|
}
|
|
3121
3256
|
});
|
|
3122
|
-
|
|
3257
|
+
test20("wait send returns completion response", async (c) => {
|
|
3123
3258
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3124
3259
|
const handle = client.queueActor.getOrCreate(["wait-complete"]);
|
|
3125
3260
|
const waitTimeout = driverTestConfig.useRealTimers ? 5e3 : 1e3;
|
|
@@ -3130,12 +3265,12 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3130
3265
|
{ wait: true, timeout: waitTimeout }
|
|
3131
3266
|
);
|
|
3132
3267
|
await actionPromise;
|
|
3133
|
-
|
|
3268
|
+
expect20(result).toEqual({
|
|
3134
3269
|
status: "completed",
|
|
3135
3270
|
response: { echo: { value: 123 } }
|
|
3136
3271
|
});
|
|
3137
3272
|
});
|
|
3138
|
-
|
|
3273
|
+
test20("wait send times out", async (c) => {
|
|
3139
3274
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3140
3275
|
const handle = client.queueActor.getOrCreate(["wait-timeout"]);
|
|
3141
3276
|
const resultPromise = handle.send(
|
|
@@ -3145,20 +3280,20 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3145
3280
|
);
|
|
3146
3281
|
await waitFor(driverTestConfig, 60);
|
|
3147
3282
|
const result = await resultPromise;
|
|
3148
|
-
|
|
3283
|
+
expect20(result.status).toBe("timedOut");
|
|
3149
3284
|
});
|
|
3150
|
-
|
|
3285
|
+
test20("manual receive retries message when not completed", async (c) => {
|
|
3151
3286
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3152
3287
|
const handle = client.queueActor.getOrCreate([
|
|
3153
3288
|
"manual-retry-uncompleted"
|
|
3154
3289
|
]);
|
|
3155
3290
|
await handle.send("tasks", { value: 789 });
|
|
3156
3291
|
const first = await handle.receiveWithoutComplete("tasks");
|
|
3157
|
-
|
|
3292
|
+
expect20(first).toEqual({ name: "tasks", body: { value: 789 } });
|
|
3158
3293
|
const retried = await handle.receiveOne("tasks", { timeout: 1e3 });
|
|
3159
|
-
|
|
3294
|
+
expect20(retried).toEqual({ name: "tasks", body: { value: 789 } });
|
|
3160
3295
|
});
|
|
3161
|
-
|
|
3296
|
+
test20("next throws when previous manual message is not completed", async (c) => {
|
|
3162
3297
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3163
3298
|
const handle = client.queueActor.getOrCreate([
|
|
3164
3299
|
"manual-next-requires-complete"
|
|
@@ -3167,46 +3302,46 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3167
3302
|
const result = await handle.receiveManualThenNextWithoutComplete(
|
|
3168
3303
|
"tasks"
|
|
3169
3304
|
);
|
|
3170
|
-
|
|
3305
|
+
expect20(result).toEqual({
|
|
3171
3306
|
group: "queue",
|
|
3172
3307
|
code: "previous_message_not_completed"
|
|
3173
3308
|
});
|
|
3174
3309
|
});
|
|
3175
|
-
|
|
3310
|
+
test20("manual receive includes complete even without completion schema", async (c) => {
|
|
3176
3311
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3177
3312
|
const handle = client.queueActor.getOrCreate([
|
|
3178
3313
|
"complete-not-allowed"
|
|
3179
3314
|
]);
|
|
3180
3315
|
await handle.send("nowait", { value: "test" });
|
|
3181
3316
|
const result = await handle.receiveWithoutCompleteMethod("nowait");
|
|
3182
|
-
|
|
3317
|
+
expect20(result).toEqual({
|
|
3183
3318
|
hasComplete: true
|
|
3184
3319
|
});
|
|
3185
3320
|
});
|
|
3186
|
-
|
|
3321
|
+
test20("manual receive retries queues without completion schema until completed", async (c) => {
|
|
3187
3322
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3188
3323
|
const handle = client.queueActor.getOrCreate([
|
|
3189
3324
|
"complete-not-allowed-consume"
|
|
3190
3325
|
]);
|
|
3191
3326
|
await handle.send("nowait", { value: "test" });
|
|
3192
3327
|
const result = await handle.receiveWithoutCompleteMethod("nowait");
|
|
3193
|
-
|
|
3328
|
+
expect20(result).toEqual({ hasComplete: true });
|
|
3194
3329
|
const next = await handle.receiveOne("nowait", { timeout: 1e3 });
|
|
3195
|
-
|
|
3330
|
+
expect20(next).toEqual({ name: "nowait", body: { value: "test" } });
|
|
3196
3331
|
});
|
|
3197
|
-
|
|
3332
|
+
test20("complete throws when called twice", async (c) => {
|
|
3198
3333
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3199
3334
|
const handle = client.queueActor.getOrCreate([
|
|
3200
3335
|
"complete-twice"
|
|
3201
3336
|
]);
|
|
3202
3337
|
await handle.send("twice", { value: "test" });
|
|
3203
3338
|
const result = await handle.receiveAndCompleteTwice("twice");
|
|
3204
|
-
|
|
3339
|
+
expect20(result).toEqual({
|
|
3205
3340
|
group: "queue",
|
|
3206
3341
|
code: "already_completed"
|
|
3207
3342
|
});
|
|
3208
3343
|
});
|
|
3209
|
-
|
|
3344
|
+
test20("wait send no longer requires queue completion schema", async (c) => {
|
|
3210
3345
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3211
3346
|
const handle = client.queueActor.getOrCreate([
|
|
3212
3347
|
"missing-completion-schema"
|
|
@@ -3216,78 +3351,78 @@ function runActorQueueTests(driverTestConfig) {
|
|
|
3216
3351
|
{ value: "test" },
|
|
3217
3352
|
{ wait: true, timeout: 50 }
|
|
3218
3353
|
);
|
|
3219
|
-
|
|
3354
|
+
expect20(result).toEqual({ status: "timedOut" });
|
|
3220
3355
|
});
|
|
3221
|
-
|
|
3356
|
+
test20("iter can consume queued messages", async (c) => {
|
|
3222
3357
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3223
3358
|
const handle = client.queueActor.getOrCreate(["iter-consume"]);
|
|
3224
3359
|
await handle.send("one", "first");
|
|
3225
3360
|
const message = await handle.receiveWithIterator("one");
|
|
3226
|
-
|
|
3361
|
+
expect20(message).toEqual({ name: "one", body: "first" });
|
|
3227
3362
|
});
|
|
3228
|
-
|
|
3363
|
+
test20("queue async iterator can consume queued messages", async (c) => {
|
|
3229
3364
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3230
3365
|
const handle = client.queueActor.getOrCreate([
|
|
3231
3366
|
"async-iter-consume"
|
|
3232
3367
|
]);
|
|
3233
3368
|
await handle.send("two", "second");
|
|
3234
3369
|
const message = await handle.receiveWithAsyncIterator();
|
|
3235
|
-
|
|
3370
|
+
expect20(message).toEqual({ name: "two", body: "second" });
|
|
3236
3371
|
});
|
|
3237
3372
|
});
|
|
3238
3373
|
}
|
|
3239
3374
|
|
|
3240
3375
|
// src/driver-test-suite/tests/actor-run.ts
|
|
3241
|
-
import { describe as
|
|
3376
|
+
import { describe as describe22, expect as expect21, test as test21 } from "vitest";
|
|
3242
3377
|
function runActorRunTests(driverTestConfig) {
|
|
3243
3378
|
var _a;
|
|
3244
|
-
|
|
3245
|
-
|
|
3379
|
+
describe22.skipIf((_a = driverTestConfig.skip) == null ? void 0 : _a.sleep)("Actor Run Tests", () => {
|
|
3380
|
+
test21("run handler starts after actor startup", async (c) => {
|
|
3246
3381
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3247
3382
|
const actor = client.runWithTicks.getOrCreate(["run-starts"]);
|
|
3248
3383
|
await waitFor(driverTestConfig, 100);
|
|
3249
3384
|
const state = await actor.getState();
|
|
3250
|
-
|
|
3251
|
-
|
|
3385
|
+
expect21(state.runStarted).toBe(true);
|
|
3386
|
+
expect21(state.tickCount).toBeGreaterThan(0);
|
|
3252
3387
|
});
|
|
3253
|
-
|
|
3388
|
+
test21("run handler ticks continuously", async (c) => {
|
|
3254
3389
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3255
3390
|
const actor = client.runWithTicks.getOrCreate(["run-ticks"]);
|
|
3256
3391
|
await waitFor(driverTestConfig, 200);
|
|
3257
3392
|
const state1 = await actor.getState();
|
|
3258
|
-
|
|
3393
|
+
expect21(state1.tickCount).toBeGreaterThan(0);
|
|
3259
3394
|
const count1 = state1.tickCount;
|
|
3260
3395
|
await waitFor(driverTestConfig, 200);
|
|
3261
3396
|
const state2 = await actor.getState();
|
|
3262
|
-
|
|
3397
|
+
expect21(state2.tickCount).toBeGreaterThan(count1);
|
|
3263
3398
|
});
|
|
3264
|
-
|
|
3399
|
+
test21("active run handler keeps actor awake past sleep timeout", async (c) => {
|
|
3265
3400
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3266
3401
|
const actor = client.runWithTicks.getOrCreate([
|
|
3267
3402
|
"run-stays-awake"
|
|
3268
3403
|
]);
|
|
3269
3404
|
await waitFor(driverTestConfig, 100);
|
|
3270
3405
|
const state1 = await actor.getState();
|
|
3271
|
-
|
|
3406
|
+
expect21(state1.runStarted).toBe(true);
|
|
3272
3407
|
const tickCount1 = state1.tickCount;
|
|
3273
3408
|
await waitFor(driverTestConfig, RUN_SLEEP_TIMEOUT + 300);
|
|
3274
3409
|
const state2 = await actor.getState();
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3410
|
+
expect21(state2.runStarted).toBe(true);
|
|
3411
|
+
expect21(state2.runExited).toBe(false);
|
|
3412
|
+
expect21(state2.tickCount).toBeGreaterThan(tickCount1);
|
|
3278
3413
|
});
|
|
3279
|
-
|
|
3414
|
+
test21("actor without run handler works normally", async (c) => {
|
|
3280
3415
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3281
3416
|
const actor = client.runWithoutHandler.getOrCreate([
|
|
3282
3417
|
"no-run-handler"
|
|
3283
3418
|
]);
|
|
3284
3419
|
const state = await actor.getState();
|
|
3285
|
-
|
|
3420
|
+
expect21(state.wakeCount).toBe(1);
|
|
3286
3421
|
await waitFor(driverTestConfig, RUN_SLEEP_TIMEOUT + 300);
|
|
3287
3422
|
const state2 = await actor.getState();
|
|
3288
|
-
|
|
3423
|
+
expect21(state2.wakeCount).toBe(2);
|
|
3289
3424
|
});
|
|
3290
|
-
|
|
3425
|
+
test21("run handler can consume from queue", async (c) => {
|
|
3291
3426
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3292
3427
|
const actor = client.runWithQueueConsumer.getOrCreate([
|
|
3293
3428
|
"queue-consumer"
|
|
@@ -3298,127 +3433,127 @@ function runActorRunTests(driverTestConfig) {
|
|
|
3298
3433
|
await actor.sendMessage({ type: "test", value: 3 });
|
|
3299
3434
|
await waitFor(driverTestConfig, 1200);
|
|
3300
3435
|
const state = await actor.getState();
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3436
|
+
expect21(state.runStarted).toBe(true);
|
|
3437
|
+
expect21(state.messagesReceived.length).toBe(3);
|
|
3438
|
+
expect21(state.messagesReceived[0].body).toEqual({
|
|
3304
3439
|
type: "test",
|
|
3305
3440
|
value: 1
|
|
3306
3441
|
});
|
|
3307
|
-
|
|
3442
|
+
expect21(state.messagesReceived[1].body).toEqual({
|
|
3308
3443
|
type: "test",
|
|
3309
3444
|
value: 2
|
|
3310
3445
|
});
|
|
3311
|
-
|
|
3446
|
+
expect21(state.messagesReceived[2].body).toEqual({
|
|
3312
3447
|
type: "test",
|
|
3313
3448
|
value: 3
|
|
3314
3449
|
});
|
|
3315
3450
|
});
|
|
3316
|
-
|
|
3451
|
+
test21("queue-waiting run handler can sleep and resume", async (c) => {
|
|
3317
3452
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3318
3453
|
const actor = client.runWithQueueConsumer.getOrCreate([
|
|
3319
3454
|
"queue-consumer-sleep"
|
|
3320
3455
|
]);
|
|
3321
3456
|
await waitFor(driverTestConfig, 100);
|
|
3322
3457
|
const state1 = await actor.getState();
|
|
3323
|
-
|
|
3458
|
+
expect21(state1.runStarted).toBe(true);
|
|
3324
3459
|
await waitFor(driverTestConfig, RUN_SLEEP_TIMEOUT + 500);
|
|
3325
3460
|
const state2 = await actor.getState();
|
|
3326
|
-
|
|
3461
|
+
expect21(state2.wakeCount).toBeGreaterThan(state1.wakeCount);
|
|
3327
3462
|
});
|
|
3328
|
-
|
|
3463
|
+
test21("run handler that exits early triggers destroy", async (c) => {
|
|
3329
3464
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3330
3465
|
const actor = client.runWithEarlyExit.getOrCreate(["early-exit"]);
|
|
3331
3466
|
await waitFor(driverTestConfig, 100);
|
|
3332
3467
|
const state1 = await actor.getState();
|
|
3333
|
-
|
|
3468
|
+
expect21(state1.runStarted).toBe(true);
|
|
3334
3469
|
await waitFor(driverTestConfig, 300);
|
|
3335
3470
|
const actor2 = client.runWithEarlyExit.getOrCreate([
|
|
3336
3471
|
"early-exit-fresh"
|
|
3337
3472
|
]);
|
|
3338
3473
|
const state2 = await actor2.getState();
|
|
3339
|
-
|
|
3474
|
+
expect21(state2.runStarted).toBe(true);
|
|
3340
3475
|
});
|
|
3341
|
-
|
|
3476
|
+
test21("run handler that throws error triggers destroy", async (c) => {
|
|
3342
3477
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3343
3478
|
const actor = client.runWithError.getOrCreate(["run-error"]);
|
|
3344
3479
|
await waitFor(driverTestConfig, 100);
|
|
3345
3480
|
const state1 = await actor.getState();
|
|
3346
|
-
|
|
3481
|
+
expect21(state1.runStarted).toBe(true);
|
|
3347
3482
|
await waitFor(driverTestConfig, 300);
|
|
3348
3483
|
const actor2 = client.runWithError.getOrCreate(["run-error-fresh"]);
|
|
3349
3484
|
const state2 = await actor2.getState();
|
|
3350
|
-
|
|
3485
|
+
expect21(state2.runStarted).toBe(true);
|
|
3351
3486
|
});
|
|
3352
3487
|
});
|
|
3353
3488
|
}
|
|
3354
3489
|
|
|
3355
3490
|
// src/driver-test-suite/tests/actor-stateless.ts
|
|
3356
|
-
import { describe as
|
|
3491
|
+
import { describe as describe23, expect as expect22, test as test22 } from "vitest";
|
|
3357
3492
|
function runActorStatelessTests(driverTestConfig) {
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3493
|
+
describe23("Actor Stateless Tests", () => {
|
|
3494
|
+
describe23("Stateless Actor Operations", () => {
|
|
3495
|
+
test22("can call actions on stateless actor", async (c) => {
|
|
3361
3496
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3362
3497
|
const instance = client.statelessActor.getOrCreate();
|
|
3363
3498
|
const result = await instance.ping();
|
|
3364
|
-
|
|
3499
|
+
expect22(result).toBe("pong");
|
|
3365
3500
|
});
|
|
3366
|
-
|
|
3501
|
+
test22("can echo messages", async (c) => {
|
|
3367
3502
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3368
3503
|
const instance = client.statelessActor.getOrCreate();
|
|
3369
3504
|
const message = "Hello, World!";
|
|
3370
3505
|
const result = await instance.echo(message);
|
|
3371
|
-
|
|
3506
|
+
expect22(result).toBe(message);
|
|
3372
3507
|
});
|
|
3373
|
-
|
|
3508
|
+
test22("can access actorId", async (c) => {
|
|
3374
3509
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3375
3510
|
const instance = client.statelessActor.getOrCreate(["test-id"]);
|
|
3376
3511
|
const actorId = await instance.getActorId();
|
|
3377
|
-
|
|
3378
|
-
|
|
3512
|
+
expect22(actorId).toBeDefined();
|
|
3513
|
+
expect22(typeof actorId).toBe("string");
|
|
3379
3514
|
});
|
|
3380
|
-
|
|
3515
|
+
test22("accessing state throws StateNotEnabled", async (c) => {
|
|
3381
3516
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3382
3517
|
const instance = client.statelessActor.getOrCreate();
|
|
3383
3518
|
const result = await instance.tryGetState();
|
|
3384
|
-
|
|
3385
|
-
|
|
3519
|
+
expect22(result.success).toBe(false);
|
|
3520
|
+
expect22(result.error).toContain("state");
|
|
3386
3521
|
});
|
|
3387
|
-
|
|
3522
|
+
test22("accessing db throws DatabaseNotEnabled", async (c) => {
|
|
3388
3523
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3389
3524
|
const instance = client.statelessActor.getOrCreate();
|
|
3390
3525
|
const result = await instance.tryGetDb();
|
|
3391
|
-
|
|
3392
|
-
|
|
3526
|
+
expect22(result.success).toBe(false);
|
|
3527
|
+
expect22(result.error).toContain("database");
|
|
3393
3528
|
});
|
|
3394
|
-
|
|
3529
|
+
test22("multiple stateless actors can exist independently", async (c) => {
|
|
3395
3530
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3396
3531
|
const actor1 = client.statelessActor.getOrCreate(["actor-1"]);
|
|
3397
3532
|
const actor2 = client.statelessActor.getOrCreate(["actor-2"]);
|
|
3398
3533
|
const id1 = await actor1.getActorId();
|
|
3399
3534
|
const id2 = await actor2.getActorId();
|
|
3400
|
-
|
|
3535
|
+
expect22(id1).not.toBe(id2);
|
|
3401
3536
|
});
|
|
3402
3537
|
});
|
|
3403
3538
|
});
|
|
3404
3539
|
}
|
|
3405
3540
|
|
|
3406
3541
|
// src/driver-test-suite/tests/actor-vars.ts
|
|
3407
|
-
import { describe as
|
|
3542
|
+
import { describe as describe24, expect as expect23, test as test23 } from "vitest";
|
|
3408
3543
|
function runActorVarsTests(driverTestConfig) {
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3544
|
+
describe24("Actor Variables", () => {
|
|
3545
|
+
describe24("Static vars", () => {
|
|
3546
|
+
test23("should provide access to static vars", async (c) => {
|
|
3412
3547
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3413
3548
|
const instance = client.staticVarActor.getOrCreate();
|
|
3414
3549
|
const result = await instance.getVars();
|
|
3415
|
-
|
|
3550
|
+
expect23(result).toEqual({ counter: 42, name: "test-actor" });
|
|
3416
3551
|
const name = await instance.getName();
|
|
3417
|
-
|
|
3552
|
+
expect23(name).toBe("test-actor");
|
|
3418
3553
|
});
|
|
3419
3554
|
});
|
|
3420
|
-
|
|
3421
|
-
|
|
3555
|
+
describe24("Deep cloning of static vars", () => {
|
|
3556
|
+
test23("should deep clone static vars between actor instances", async (c) => {
|
|
3422
3557
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3423
3558
|
const instance1 = client.nestedVarActor.getOrCreate([
|
|
3424
3559
|
"instance1"
|
|
@@ -3427,52 +3562,52 @@ function runActorVarsTests(driverTestConfig) {
|
|
|
3427
3562
|
"instance2"
|
|
3428
3563
|
]);
|
|
3429
3564
|
const modifiedVars = await instance1.modifyNested();
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3565
|
+
expect23(modifiedVars.nested.value).toBe("modified");
|
|
3566
|
+
expect23(modifiedVars.nested.array).toContain(4);
|
|
3567
|
+
expect23(modifiedVars.nested.obj.key).toBe("new-value");
|
|
3433
3568
|
const instance2Vars = await instance2.getVars();
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3569
|
+
expect23(instance2Vars.nested.value).toBe("original");
|
|
3570
|
+
expect23(instance2Vars.nested.array).toEqual([1, 2, 3]);
|
|
3571
|
+
expect23(instance2Vars.nested.obj.key).toBe("value");
|
|
3437
3572
|
});
|
|
3438
3573
|
});
|
|
3439
|
-
|
|
3440
|
-
|
|
3574
|
+
describe24("createVars", () => {
|
|
3575
|
+
test23("should support dynamic vars creation", async (c) => {
|
|
3441
3576
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3442
3577
|
const instance = client.dynamicVarActor.getOrCreate();
|
|
3443
3578
|
const vars = await instance.getVars();
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3579
|
+
expect23(vars).toHaveProperty("random");
|
|
3580
|
+
expect23(vars).toHaveProperty("computed");
|
|
3581
|
+
expect23(typeof vars.random).toBe("number");
|
|
3582
|
+
expect23(typeof vars.computed).toBe("string");
|
|
3583
|
+
expect23(vars.computed).toMatch(/^Actor-\d+$/);
|
|
3449
3584
|
});
|
|
3450
|
-
|
|
3585
|
+
test23("should create different vars for different instances", async (c) => {
|
|
3451
3586
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3452
3587
|
const instance1 = client.uniqueVarActor.getOrCreate(["test1"]);
|
|
3453
3588
|
const instance2 = client.uniqueVarActor.getOrCreate(["test2"]);
|
|
3454
3589
|
const vars1 = await instance1.getVars();
|
|
3455
3590
|
const vars2 = await instance2.getVars();
|
|
3456
|
-
|
|
3591
|
+
expect23(vars1.id).not.toBe(vars2.id);
|
|
3457
3592
|
});
|
|
3458
3593
|
});
|
|
3459
|
-
|
|
3460
|
-
|
|
3594
|
+
describe24("Driver Context", () => {
|
|
3595
|
+
test23("should provide access to driver context", async (c) => {
|
|
3461
3596
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3462
3597
|
const instance = client.driverCtxActor.getOrCreate();
|
|
3463
3598
|
const vars = await instance.getVars();
|
|
3464
|
-
|
|
3599
|
+
expect23(vars).toHaveProperty("hasDriverCtx");
|
|
3465
3600
|
});
|
|
3466
3601
|
});
|
|
3467
3602
|
});
|
|
3468
3603
|
}
|
|
3469
3604
|
|
|
3470
3605
|
// src/driver-test-suite/tests/actor-workflow.ts
|
|
3471
|
-
import { describe as
|
|
3606
|
+
import { describe as describe25, expect as expect24, test as test24 } from "vitest";
|
|
3472
3607
|
function runActorWorkflowTests(driverTestConfig) {
|
|
3473
|
-
|
|
3608
|
+
describe25("Actor Workflow Tests", () => {
|
|
3474
3609
|
var _a;
|
|
3475
|
-
|
|
3610
|
+
test24("replays steps and guards state access", async (c) => {
|
|
3476
3611
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3477
3612
|
const actor = client.workflowCounterActor.getOrCreate([
|
|
3478
3613
|
"workflow-basic"
|
|
@@ -3485,11 +3620,11 @@ function runActorWorkflowTests(driverTestConfig) {
|
|
|
3485
3620
|
await waitFor(driverTestConfig, 100);
|
|
3486
3621
|
state = await actor.getState();
|
|
3487
3622
|
}
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3623
|
+
expect24(state.runCount).toBeGreaterThan(0);
|
|
3624
|
+
expect24(state.history.length).toBeGreaterThan(0);
|
|
3625
|
+
expect24(state.guardTriggered).toBe(true);
|
|
3491
3626
|
});
|
|
3492
|
-
|
|
3627
|
+
test24("consumes queue messages via workflow queue.next", async (c) => {
|
|
3493
3628
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3494
3629
|
const actor = client.workflowQueueActor.getOrCreate(["workflow-queue"]);
|
|
3495
3630
|
await actor.send(WORKFLOW_QUEUE_NAME, {
|
|
@@ -3497,20 +3632,20 @@ function runActorWorkflowTests(driverTestConfig) {
|
|
|
3497
3632
|
});
|
|
3498
3633
|
await waitFor(driverTestConfig, 200);
|
|
3499
3634
|
const messages = await actor.getMessages();
|
|
3500
|
-
|
|
3635
|
+
expect24(messages).toEqual([{ hello: "world" }]);
|
|
3501
3636
|
});
|
|
3502
|
-
|
|
3637
|
+
test24("workflow queue.next supports completing wait sends", async (c) => {
|
|
3503
3638
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3504
3639
|
const actor = client.workflowQueueActor.getOrCreate([
|
|
3505
3640
|
"workflow-queue-wait"
|
|
3506
3641
|
]);
|
|
3507
3642
|
const result = await actor.sendAndWait({ value: 123 });
|
|
3508
|
-
|
|
3643
|
+
expect24(result).toEqual({
|
|
3509
3644
|
status: "completed",
|
|
3510
3645
|
response: { echo: { value: 123 } }
|
|
3511
3646
|
});
|
|
3512
3647
|
});
|
|
3513
|
-
|
|
3648
|
+
test24("db and client are step-only in workflow context", async (c) => {
|
|
3514
3649
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3515
3650
|
const actor = client.workflowAccessActor.getOrCreate([
|
|
3516
3651
|
"workflow-access"
|
|
@@ -3520,24 +3655,24 @@ function runActorWorkflowTests(driverTestConfig) {
|
|
|
3520
3655
|
await waitFor(driverTestConfig, 50);
|
|
3521
3656
|
state = await actor.getState();
|
|
3522
3657
|
}
|
|
3523
|
-
|
|
3658
|
+
expect24(state.outsideDbError).toBe(
|
|
3524
3659
|
"db is only available inside workflow steps"
|
|
3525
3660
|
);
|
|
3526
|
-
|
|
3661
|
+
expect24(state.outsideClientError).toBe(
|
|
3527
3662
|
"client is only available inside workflow steps"
|
|
3528
3663
|
);
|
|
3529
|
-
|
|
3530
|
-
|
|
3664
|
+
expect24(state.insideDbCount).toBeGreaterThan(0);
|
|
3665
|
+
expect24(state.insideClientAvailable).toBe(true);
|
|
3531
3666
|
});
|
|
3532
|
-
|
|
3667
|
+
test24("sleeps and resumes between ticks", async (c) => {
|
|
3533
3668
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3534
3669
|
const actor = client.workflowSleepActor.getOrCreate(["workflow-sleep"]);
|
|
3535
3670
|
const initial = await actor.getState();
|
|
3536
3671
|
await waitFor(driverTestConfig, 200);
|
|
3537
3672
|
const next = await actor.getState();
|
|
3538
|
-
|
|
3673
|
+
expect24(next.ticks).toBeGreaterThan(initial.ticks);
|
|
3539
3674
|
});
|
|
3540
|
-
|
|
3675
|
+
test24.skipIf((_a = driverTestConfig.skip) == null ? void 0 : _a.sleep)(
|
|
3541
3676
|
"workflow run teardown does not wait for runStopTimeout",
|
|
3542
3677
|
async (c) => {
|
|
3543
3678
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
@@ -3547,69 +3682,69 @@ function runActorWorkflowTests(driverTestConfig) {
|
|
|
3547
3682
|
await actor.getTimeline();
|
|
3548
3683
|
await waitFor(driverTestConfig, 1200);
|
|
3549
3684
|
const timeline = await actor.getTimeline();
|
|
3550
|
-
|
|
3551
|
-
|
|
3685
|
+
expect24(timeline.wakeAts.length).toBeGreaterThanOrEqual(2);
|
|
3686
|
+
expect24(timeline.sleepAts.length).toBeGreaterThanOrEqual(1);
|
|
3552
3687
|
const firstSleepDelayMs = timeline.sleepAts[0] - timeline.wakeAts[0];
|
|
3553
|
-
|
|
3688
|
+
expect24(firstSleepDelayMs).toBeLessThan(1800);
|
|
3554
3689
|
}
|
|
3555
3690
|
);
|
|
3556
3691
|
});
|
|
3557
3692
|
}
|
|
3558
3693
|
|
|
3559
3694
|
// src/driver-test-suite/tests/manager-driver.ts
|
|
3560
|
-
import { describe as
|
|
3695
|
+
import { describe as describe26, expect as expect25, test as test25 } from "vitest";
|
|
3561
3696
|
function runManagerDriverTests(driverTestConfig) {
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3697
|
+
describe26("Manager Driver Tests", () => {
|
|
3698
|
+
describe26("Client Connection Methods", () => {
|
|
3699
|
+
test25("connect() - finds or creates a actor", async (c) => {
|
|
3565
3700
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3566
3701
|
const counterA = client.counter.getOrCreate();
|
|
3567
3702
|
await counterA.increment(5);
|
|
3568
3703
|
const counterAAgain = client.counter.getOrCreate();
|
|
3569
3704
|
const count = await counterAAgain.increment(0);
|
|
3570
|
-
|
|
3705
|
+
expect25(count).toBe(5);
|
|
3571
3706
|
const counterB = client.counter.getOrCreate([
|
|
3572
3707
|
"counter-b",
|
|
3573
3708
|
"testing"
|
|
3574
3709
|
]);
|
|
3575
3710
|
await counterB.increment(10);
|
|
3576
3711
|
const countB = await counterB.increment(0);
|
|
3577
|
-
|
|
3712
|
+
expect25(countB).toBe(10);
|
|
3578
3713
|
});
|
|
3579
|
-
|
|
3714
|
+
test25("throws ActorAlreadyExists when creating duplicate actors", async (c) => {
|
|
3580
3715
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3581
3716
|
const uniqueKey = ["duplicate-actor-test", crypto.randomUUID()];
|
|
3582
3717
|
const counter = client.counter.getOrCreate(uniqueKey);
|
|
3583
3718
|
await counter.increment(5);
|
|
3584
3719
|
try {
|
|
3585
3720
|
await client.counter.create(uniqueKey);
|
|
3586
|
-
|
|
3721
|
+
expect25.fail("did not error on duplicate create");
|
|
3587
3722
|
} catch (err) {
|
|
3588
|
-
|
|
3589
|
-
|
|
3723
|
+
expect25(err.group).toBe("actor");
|
|
3724
|
+
expect25(err.code).toBe("duplicate_key");
|
|
3590
3725
|
}
|
|
3591
3726
|
const count = await counter.increment(0);
|
|
3592
|
-
|
|
3727
|
+
expect25(count).toBe(5);
|
|
3593
3728
|
});
|
|
3594
3729
|
});
|
|
3595
|
-
|
|
3596
|
-
|
|
3730
|
+
describe26("Connection Options", () => {
|
|
3731
|
+
test25("get without create prevents actor creation", async (c) => {
|
|
3597
3732
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3598
3733
|
const nonexistentId = `nonexistent-${crypto.randomUUID()}`;
|
|
3599
3734
|
try {
|
|
3600
3735
|
await client.counter.get([nonexistentId]).resolve();
|
|
3601
|
-
|
|
3736
|
+
expect25.fail("did not error for get");
|
|
3602
3737
|
} catch (err) {
|
|
3603
|
-
|
|
3604
|
-
|
|
3738
|
+
expect25(err.group).toBe("actor");
|
|
3739
|
+
expect25(err.code).toBe("not_found");
|
|
3605
3740
|
}
|
|
3606
3741
|
const createdCounter = client.counter.getOrCreate(nonexistentId);
|
|
3607
3742
|
await createdCounter.increment(3);
|
|
3608
3743
|
const retrievedCounter = client.counter.get(nonexistentId);
|
|
3609
3744
|
const count = await retrievedCounter.increment(0);
|
|
3610
|
-
|
|
3745
|
+
expect25(count).toBe(3);
|
|
3611
3746
|
});
|
|
3612
|
-
|
|
3747
|
+
test25("connection params are passed to actors", async (c) => {
|
|
3613
3748
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3614
3749
|
const counter = client.counter.getOrCreate(void 0, {
|
|
3615
3750
|
params: {
|
|
@@ -3620,20 +3755,20 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3620
3755
|
});
|
|
3621
3756
|
await counter.increment(1);
|
|
3622
3757
|
const count = await counter.increment(0);
|
|
3623
|
-
|
|
3758
|
+
expect25(count).toBe(1);
|
|
3624
3759
|
});
|
|
3625
3760
|
});
|
|
3626
|
-
|
|
3627
|
-
|
|
3761
|
+
describe26("Actor Creation & Retrieval", () => {
|
|
3762
|
+
test25("creates and retrieves actors by ID", async (c) => {
|
|
3628
3763
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3629
3764
|
const uniqueId = `test-counter-${crypto.randomUUID()}`;
|
|
3630
3765
|
const counter = client.counter.getOrCreate([uniqueId]);
|
|
3631
3766
|
await counter.increment(10);
|
|
3632
3767
|
const retrievedCounter = client.counter.getOrCreate([uniqueId]);
|
|
3633
3768
|
const count = await retrievedCounter.increment(0);
|
|
3634
|
-
|
|
3769
|
+
expect25(count).toBe(10);
|
|
3635
3770
|
});
|
|
3636
|
-
|
|
3771
|
+
test25("passes input to actor during creation", async (c) => {
|
|
3637
3772
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3638
3773
|
const testInput = {
|
|
3639
3774
|
name: "test-actor",
|
|
@@ -3644,17 +3779,17 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3644
3779
|
input: testInput
|
|
3645
3780
|
});
|
|
3646
3781
|
const inputs = await actor.getInputs();
|
|
3647
|
-
|
|
3648
|
-
|
|
3782
|
+
expect25(inputs.initialInput).toEqual(testInput);
|
|
3783
|
+
expect25(inputs.onCreateInput).toEqual(testInput);
|
|
3649
3784
|
});
|
|
3650
|
-
|
|
3785
|
+
test25("input is undefined when not provided", async (c) => {
|
|
3651
3786
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3652
3787
|
const actor = await client.inputActor.create();
|
|
3653
3788
|
const inputs = await actor.getInputs();
|
|
3654
|
-
|
|
3655
|
-
|
|
3789
|
+
expect25(inputs.initialInput).toBeUndefined();
|
|
3790
|
+
expect25(inputs.onCreateInput).toBeUndefined();
|
|
3656
3791
|
});
|
|
3657
|
-
|
|
3792
|
+
test25("getOrCreate passes input to actor during creation", async (c) => {
|
|
3658
3793
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3659
3794
|
const uniqueKey = [`input-test-${crypto.randomUUID()}`];
|
|
3660
3795
|
const testInput = {
|
|
@@ -3666,22 +3801,22 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3666
3801
|
createWithInput: testInput
|
|
3667
3802
|
});
|
|
3668
3803
|
const inputs = await actor.getInputs();
|
|
3669
|
-
|
|
3670
|
-
|
|
3804
|
+
expect25(inputs.initialInput).toEqual(testInput);
|
|
3805
|
+
expect25(inputs.onCreateInput).toEqual(testInput);
|
|
3671
3806
|
const existingActor = client.inputActor.getOrCreate(uniqueKey);
|
|
3672
3807
|
const existingInputs = await existingActor.getInputs();
|
|
3673
|
-
|
|
3674
|
-
|
|
3808
|
+
expect25(existingInputs.initialInput).toEqual(testInput);
|
|
3809
|
+
expect25(existingInputs.onCreateInput).toEqual(testInput);
|
|
3675
3810
|
});
|
|
3676
3811
|
});
|
|
3677
|
-
|
|
3678
|
-
|
|
3812
|
+
describe26("Key Matching", () => {
|
|
3813
|
+
test25("multi-part actor keys are passed through correctly", async (c) => {
|
|
3679
3814
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3680
3815
|
const multiPartKey = ["tenant/with/slash", "room"];
|
|
3681
3816
|
const counter = client.counter.getOrCreate(multiPartKey);
|
|
3682
|
-
|
|
3817
|
+
expect25(await counter.getKey()).toEqual(multiPartKey);
|
|
3683
3818
|
});
|
|
3684
|
-
|
|
3819
|
+
test25("matches actors only with exactly the same keys", async (c) => {
|
|
3685
3820
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3686
3821
|
const originalCounter = client.counter.getOrCreate([
|
|
3687
3822
|
"counter-match",
|
|
@@ -3695,20 +3830,20 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3695
3830
|
"us-east"
|
|
3696
3831
|
]);
|
|
3697
3832
|
const exactMatchCount = await exactMatchCounter.increment(0);
|
|
3698
|
-
|
|
3833
|
+
expect25(exactMatchCount).toBe(10);
|
|
3699
3834
|
const subsetMatchCounter = client.counter.getOrCreate([
|
|
3700
3835
|
"counter-match",
|
|
3701
3836
|
"test"
|
|
3702
3837
|
]);
|
|
3703
3838
|
const subsetMatchCount = await subsetMatchCounter.increment(0);
|
|
3704
|
-
|
|
3839
|
+
expect25(subsetMatchCount).toBe(0);
|
|
3705
3840
|
const singleKeyCounter = client.counter.getOrCreate([
|
|
3706
3841
|
"counter-match"
|
|
3707
3842
|
]);
|
|
3708
3843
|
const singleKeyCount = await singleKeyCounter.increment(0);
|
|
3709
|
-
|
|
3844
|
+
expect25(singleKeyCount).toBe(0);
|
|
3710
3845
|
});
|
|
3711
|
-
|
|
3846
|
+
test25("string key matches array with single string key", async (c) => {
|
|
3712
3847
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3713
3848
|
const stringKeyCounter = client.counter.getOrCreate("string-key-test");
|
|
3714
3849
|
await stringKeyCounter.increment(7);
|
|
@@ -3716,20 +3851,20 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3716
3851
|
"string-key-test"
|
|
3717
3852
|
]);
|
|
3718
3853
|
const count = await arrayKeyCounter.increment(0);
|
|
3719
|
-
|
|
3854
|
+
expect25(count).toBe(7);
|
|
3720
3855
|
});
|
|
3721
|
-
|
|
3856
|
+
test25("undefined key matches empty array key and no key", async (c) => {
|
|
3722
3857
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3723
3858
|
const undefinedKeyCounter = client.counter.getOrCreate(void 0);
|
|
3724
3859
|
await undefinedKeyCounter.increment(12);
|
|
3725
3860
|
const emptyArrayKeyCounter = client.counter.getOrCreate([]);
|
|
3726
3861
|
const emptyArrayCount = await emptyArrayKeyCounter.increment(0);
|
|
3727
|
-
|
|
3862
|
+
expect25(emptyArrayCount).toBe(12);
|
|
3728
3863
|
const noKeyCounter = client.counter.getOrCreate();
|
|
3729
3864
|
const noKeyCount = await noKeyCounter.increment(0);
|
|
3730
|
-
|
|
3865
|
+
expect25(noKeyCount).toBe(12);
|
|
3731
3866
|
});
|
|
3732
|
-
|
|
3867
|
+
test25("no keys does not match actors with keys", async (c) => {
|
|
3733
3868
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3734
3869
|
const keyedCounter = client.counter.getOrCreate([
|
|
3735
3870
|
"counter-with-keys",
|
|
@@ -3738,9 +3873,9 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3738
3873
|
await keyedCounter.increment(15);
|
|
3739
3874
|
const noKeysCounter = client.counter.getOrCreate();
|
|
3740
3875
|
const count = await noKeysCounter.increment(10);
|
|
3741
|
-
|
|
3876
|
+
expect25(count).toBe(10);
|
|
3742
3877
|
});
|
|
3743
|
-
|
|
3878
|
+
test25("actors with keys match actors with no keys", async (c) => {
|
|
3744
3879
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3745
3880
|
const noKeysCounter = client.counter.getOrCreate();
|
|
3746
3881
|
await noKeysCounter.increment(25);
|
|
@@ -3749,11 +3884,11 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3749
3884
|
"prod"
|
|
3750
3885
|
]);
|
|
3751
3886
|
const keyedCount = await keyedCounter.increment(0);
|
|
3752
|
-
|
|
3887
|
+
expect25(keyedCount).toBe(0);
|
|
3753
3888
|
});
|
|
3754
3889
|
});
|
|
3755
|
-
|
|
3756
|
-
|
|
3890
|
+
describe26("Multiple Actor Instances", () => {
|
|
3891
|
+
test25("creates multiple actor instances of the same type", async (c) => {
|
|
3757
3892
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3758
3893
|
const instance1 = client.counter.getOrCreate(["multi-1"]);
|
|
3759
3894
|
const instance2 = client.counter.getOrCreate(["multi-2"]);
|
|
@@ -3764,35 +3899,35 @@ function runManagerDriverTests(driverTestConfig) {
|
|
|
3764
3899
|
const retrieved1 = client.counter.getOrCreate(["multi-1"]);
|
|
3765
3900
|
const retrieved2 = client.counter.getOrCreate(["multi-2"]);
|
|
3766
3901
|
const retrieved3 = client.counter.getOrCreate(["multi-3"]);
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3902
|
+
expect25(await retrieved1.increment(0)).toBe(1);
|
|
3903
|
+
expect25(await retrieved2.increment(0)).toBe(2);
|
|
3904
|
+
expect25(await retrieved3.increment(0)).toBe(3);
|
|
3770
3905
|
});
|
|
3771
|
-
|
|
3906
|
+
test25("handles default instance with no explicit ID", async (c) => {
|
|
3772
3907
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3773
3908
|
const defaultCounter = client.counter.getOrCreate();
|
|
3774
3909
|
await defaultCounter.increment(5);
|
|
3775
3910
|
const sameDefaultCounter = client.counter.getOrCreate();
|
|
3776
3911
|
const count = await sameDefaultCounter.increment(0);
|
|
3777
|
-
|
|
3912
|
+
expect25(count).toBe(5);
|
|
3778
3913
|
});
|
|
3779
3914
|
});
|
|
3780
3915
|
});
|
|
3781
3916
|
}
|
|
3782
3917
|
|
|
3783
3918
|
// src/driver-test-suite/tests/raw-http.ts
|
|
3784
|
-
import { describe as
|
|
3919
|
+
import { describe as describe27, expect as expect26, test as test26 } from "vitest";
|
|
3785
3920
|
function runRawHttpTests(driverTestConfig) {
|
|
3786
|
-
|
|
3787
|
-
|
|
3921
|
+
describe27("raw http", () => {
|
|
3922
|
+
test26("should handle raw HTTP GET requests", async (c) => {
|
|
3788
3923
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3789
3924
|
const actor = client.rawHttpActor.getOrCreate(["test"]);
|
|
3790
3925
|
const helloResponse = await actor.fetch("api/hello");
|
|
3791
|
-
|
|
3926
|
+
expect26(helloResponse.ok).toBe(true);
|
|
3792
3927
|
const helloData = await helloResponse.json();
|
|
3793
|
-
|
|
3928
|
+
expect26(helloData).toEqual({ message: "Hello from actor!" });
|
|
3794
3929
|
});
|
|
3795
|
-
|
|
3930
|
+
test26("should handle raw HTTP POST requests with echo", async (c) => {
|
|
3796
3931
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3797
3932
|
const actor = client.rawHttpActor.getOrCreate(["test"]);
|
|
3798
3933
|
const testData = { test: "data", number: 123 };
|
|
@@ -3803,22 +3938,22 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
3803
3938
|
},
|
|
3804
3939
|
body: JSON.stringify(testData)
|
|
3805
3940
|
});
|
|
3806
|
-
|
|
3941
|
+
expect26(echoResponse.ok).toBe(true);
|
|
3807
3942
|
const echoData = await echoResponse.json();
|
|
3808
|
-
|
|
3943
|
+
expect26(echoData).toEqual(testData);
|
|
3809
3944
|
});
|
|
3810
|
-
|
|
3945
|
+
test26("should track state across raw HTTP requests", async (c) => {
|
|
3811
3946
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3812
3947
|
const actor = client.rawHttpActor.getOrCreate(["state-test"]);
|
|
3813
3948
|
await actor.fetch("api/hello");
|
|
3814
3949
|
await actor.fetch("api/hello");
|
|
3815
3950
|
await actor.fetch("api/state");
|
|
3816
3951
|
const stateResponse = await actor.fetch("api/state");
|
|
3817
|
-
|
|
3952
|
+
expect26(stateResponse.ok).toBe(true);
|
|
3818
3953
|
const stateData = await stateResponse.json();
|
|
3819
|
-
|
|
3954
|
+
expect26(stateData.requestCount).toBe(4);
|
|
3820
3955
|
});
|
|
3821
|
-
|
|
3956
|
+
test26("should pass headers correctly", async (c) => {
|
|
3822
3957
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3823
3958
|
const actor = client.rawHttpActor.getOrCreate(["headers-test"]);
|
|
3824
3959
|
const customHeaders = {
|
|
@@ -3828,44 +3963,44 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
3828
3963
|
const response = await actor.fetch("api/headers", {
|
|
3829
3964
|
headers: customHeaders
|
|
3830
3965
|
});
|
|
3831
|
-
|
|
3966
|
+
expect26(response.ok).toBe(true);
|
|
3832
3967
|
const headers = await response.json();
|
|
3833
|
-
|
|
3834
|
-
|
|
3968
|
+
expect26(headers["x-custom-header"]).toBe("test-value");
|
|
3969
|
+
expect26(headers["x-another-header"]).toBe("another-value");
|
|
3835
3970
|
});
|
|
3836
|
-
|
|
3971
|
+
test26("should return 404 for unhandled paths", async (c) => {
|
|
3837
3972
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3838
3973
|
const actor = client.rawHttpActor.getOrCreate(["404-test"]);
|
|
3839
3974
|
const response = await actor.fetch("api/nonexistent");
|
|
3840
|
-
|
|
3841
|
-
|
|
3975
|
+
expect26(response.ok).toBe(false);
|
|
3976
|
+
expect26(response.status).toBe(404);
|
|
3842
3977
|
});
|
|
3843
|
-
|
|
3978
|
+
test26("should return 404 when no onRequest handler defined", async (c) => {
|
|
3844
3979
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3845
3980
|
const actor = client.rawHttpNoHandlerActor.getOrCreate([
|
|
3846
3981
|
"no-handler"
|
|
3847
3982
|
]);
|
|
3848
3983
|
const response = await actor.fetch("api/anything");
|
|
3849
|
-
|
|
3850
|
-
|
|
3984
|
+
expect26(response.ok).toBe(false);
|
|
3985
|
+
expect26(response.status).toBe(404);
|
|
3851
3986
|
});
|
|
3852
|
-
|
|
3987
|
+
test26("should return 500 error when onRequest returns void", async (c) => {
|
|
3853
3988
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3854
3989
|
const actor = client.rawHttpVoidReturnActor.getOrCreate([
|
|
3855
3990
|
"void-return"
|
|
3856
3991
|
]);
|
|
3857
3992
|
const response = await actor.fetch("api/anything");
|
|
3858
|
-
|
|
3859
|
-
|
|
3993
|
+
expect26(response.ok).toBe(false);
|
|
3994
|
+
expect26(response.status).toBe(500);
|
|
3860
3995
|
try {
|
|
3861
3996
|
const errorData = await response.json();
|
|
3862
|
-
|
|
3997
|
+
expect26(errorData.message).toContain(
|
|
3863
3998
|
"onRequest handler must return a Response"
|
|
3864
3999
|
);
|
|
3865
4000
|
} catch {
|
|
3866
4001
|
}
|
|
3867
4002
|
});
|
|
3868
|
-
|
|
4003
|
+
test26("should handle different HTTP methods", async (c) => {
|
|
3869
4004
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3870
4005
|
const actor = client.rawHttpActor.getOrCreate(["methods-test"]);
|
|
3871
4006
|
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
@@ -3875,17 +4010,17 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
3875
4010
|
body: ["POST", "PUT", "PATCH"].includes(method) ? JSON.stringify({ method }) : void 0
|
|
3876
4011
|
});
|
|
3877
4012
|
if (method === "POST") {
|
|
3878
|
-
|
|
4013
|
+
expect26(response.ok).toBe(true);
|
|
3879
4014
|
const data = await response.json();
|
|
3880
|
-
|
|
4015
|
+
expect26(data).toEqual({ method });
|
|
3881
4016
|
} else if (method === "GET") {
|
|
3882
|
-
|
|
4017
|
+
expect26(response.status).toBe(404);
|
|
3883
4018
|
} else {
|
|
3884
|
-
|
|
4019
|
+
expect26(response.status).toBe(404);
|
|
3885
4020
|
}
|
|
3886
4021
|
}
|
|
3887
4022
|
});
|
|
3888
|
-
|
|
4023
|
+
test26("should handle binary data", async (c) => {
|
|
3889
4024
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3890
4025
|
const actor = client.rawHttpActor.getOrCreate(["binary-test"]);
|
|
3891
4026
|
const binaryData = new Uint8Array([1, 2, 3, 4, 5]);
|
|
@@ -3896,82 +4031,82 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
3896
4031
|
},
|
|
3897
4032
|
body: binaryData
|
|
3898
4033
|
});
|
|
3899
|
-
|
|
4034
|
+
expect26(response.ok).toBe(true);
|
|
3900
4035
|
const responseBuffer = await response.arrayBuffer();
|
|
3901
4036
|
const responseArray = new Uint8Array(responseBuffer);
|
|
3902
|
-
|
|
4037
|
+
expect26(Array.from(responseArray)).toEqual([1, 2, 3, 4, 5]);
|
|
3903
4038
|
});
|
|
3904
|
-
|
|
4039
|
+
test26("should work with Hono router using createVars", async (c) => {
|
|
3905
4040
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3906
4041
|
const actor = client.rawHttpHonoActor.getOrCreate(["hono-test"]);
|
|
3907
4042
|
const rootResponse = await actor.fetch("/");
|
|
3908
|
-
|
|
4043
|
+
expect26(rootResponse.ok).toBe(true);
|
|
3909
4044
|
const rootData = await rootResponse.json();
|
|
3910
|
-
|
|
4045
|
+
expect26(rootData).toEqual({ message: "Welcome to Hono actor!" });
|
|
3911
4046
|
const usersResponse = await actor.fetch("/users");
|
|
3912
|
-
|
|
4047
|
+
expect26(usersResponse.ok).toBe(true);
|
|
3913
4048
|
const users = await usersResponse.json();
|
|
3914
|
-
|
|
4049
|
+
expect26(users).toEqual([
|
|
3915
4050
|
{ id: 1, name: "Alice" },
|
|
3916
4051
|
{ id: 2, name: "Bob" }
|
|
3917
4052
|
]);
|
|
3918
4053
|
const userResponse = await actor.fetch("/users/1");
|
|
3919
|
-
|
|
4054
|
+
expect26(userResponse.ok).toBe(true);
|
|
3920
4055
|
const user = await userResponse.json();
|
|
3921
|
-
|
|
4056
|
+
expect26(user).toEqual({ id: 1, name: "Alice" });
|
|
3922
4057
|
const newUser = { name: "Charlie" };
|
|
3923
4058
|
const createResponse = await actor.fetch("/users", {
|
|
3924
4059
|
method: "POST",
|
|
3925
4060
|
headers: { "Content-Type": "application/json" },
|
|
3926
4061
|
body: JSON.stringify(newUser)
|
|
3927
4062
|
});
|
|
3928
|
-
|
|
3929
|
-
|
|
4063
|
+
expect26(createResponse.ok).toBe(true);
|
|
4064
|
+
expect26(createResponse.status).toBe(201);
|
|
3930
4065
|
const createdUser = await createResponse.json();
|
|
3931
|
-
|
|
4066
|
+
expect26(createdUser).toEqual({ id: 3, name: "Charlie" });
|
|
3932
4067
|
const updateData = { name: "Alice Updated" };
|
|
3933
4068
|
const updateResponse = await actor.fetch("/users/1", {
|
|
3934
4069
|
method: "PUT",
|
|
3935
4070
|
headers: { "Content-Type": "application/json" },
|
|
3936
4071
|
body: JSON.stringify(updateData)
|
|
3937
4072
|
});
|
|
3938
|
-
|
|
4073
|
+
expect26(updateResponse.ok).toBe(true);
|
|
3939
4074
|
const updatedUser = await updateResponse.json();
|
|
3940
|
-
|
|
4075
|
+
expect26(updatedUser).toEqual({ id: 1, name: "Alice Updated" });
|
|
3941
4076
|
const deleteResponse = await actor.fetch("/users/2", {
|
|
3942
4077
|
method: "DELETE"
|
|
3943
4078
|
});
|
|
3944
|
-
|
|
4079
|
+
expect26(deleteResponse.ok).toBe(true);
|
|
3945
4080
|
const deleteResult = await deleteResponse.json();
|
|
3946
|
-
|
|
4081
|
+
expect26(deleteResult).toEqual({ message: "User 2 deleted" });
|
|
3947
4082
|
const notFoundResponse = await actor.fetch("/api/unknown");
|
|
3948
|
-
|
|
3949
|
-
|
|
4083
|
+
expect26(notFoundResponse.ok).toBe(false);
|
|
4084
|
+
expect26(notFoundResponse.status).toBe(404);
|
|
3950
4085
|
});
|
|
3951
|
-
|
|
4086
|
+
test26("should handle paths with and without leading slashes", async (c) => {
|
|
3952
4087
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3953
4088
|
const actor = client.rawHttpActor.getOrCreate(["path-test"]);
|
|
3954
4089
|
const responseWithoutSlash = await actor.fetch("api/hello");
|
|
3955
|
-
|
|
4090
|
+
expect26(responseWithoutSlash.ok).toBe(true);
|
|
3956
4091
|
const dataWithoutSlash = await responseWithoutSlash.json();
|
|
3957
|
-
|
|
4092
|
+
expect26(dataWithoutSlash).toEqual({ message: "Hello from actor!" });
|
|
3958
4093
|
const responseWithSlash = await actor.fetch("/api/hello");
|
|
3959
|
-
|
|
4094
|
+
expect26(responseWithSlash.ok).toBe(true);
|
|
3960
4095
|
const dataWithSlash = await responseWithSlash.json();
|
|
3961
|
-
|
|
4096
|
+
expect26(dataWithSlash).toEqual({ message: "Hello from actor!" });
|
|
3962
4097
|
});
|
|
3963
|
-
|
|
4098
|
+
test26("should not create double slashes in request URLs", async (c) => {
|
|
3964
4099
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3965
4100
|
const actor = client.rawHttpHonoActor.getOrCreate(["url-test"]);
|
|
3966
4101
|
const response = await actor.fetch("/users");
|
|
3967
|
-
|
|
4102
|
+
expect26(response.ok).toBe(true);
|
|
3968
4103
|
const data = await response.json();
|
|
3969
|
-
|
|
4104
|
+
expect26(data).toEqual([
|
|
3970
4105
|
{ id: 1, name: "Alice" },
|
|
3971
4106
|
{ id: 2, name: "Bob" }
|
|
3972
4107
|
]);
|
|
3973
4108
|
});
|
|
3974
|
-
|
|
4109
|
+
test26("should handle forwarded requests correctly without double slashes", async (c) => {
|
|
3975
4110
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3976
4111
|
const actor = client.rawHttpHonoActor.getOrCreate(["forward-test"]);
|
|
3977
4112
|
const truncatedPath = "/users";
|
|
@@ -3983,14 +4118,14 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
3983
4118
|
truncatedPath,
|
|
3984
4119
|
newRequest
|
|
3985
4120
|
);
|
|
3986
|
-
|
|
4121
|
+
expect26(response.ok).toBe(true);
|
|
3987
4122
|
const users = await response.json();
|
|
3988
|
-
|
|
4123
|
+
expect26(users).toEqual([
|
|
3989
4124
|
{ id: 1, name: "Alice" },
|
|
3990
4125
|
{ id: 2, name: "Bob" }
|
|
3991
4126
|
]);
|
|
3992
4127
|
});
|
|
3993
|
-
|
|
4128
|
+
test26("example fix: should properly forward requests using just Request object", async (c) => {
|
|
3994
4129
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
3995
4130
|
const actor = client.rawHttpHonoActor.getOrCreate(["forward-fix"]);
|
|
3996
4131
|
const truncatedPath = "/users/1";
|
|
@@ -3999,11 +4134,11 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
3999
4134
|
method: "GET"
|
|
4000
4135
|
});
|
|
4001
4136
|
const response = await actor.fetch(newRequest);
|
|
4002
|
-
|
|
4137
|
+
expect26(response.ok).toBe(true);
|
|
4003
4138
|
const user = await response.json();
|
|
4004
|
-
|
|
4139
|
+
expect26(user).toEqual({ id: 1, name: "Alice" });
|
|
4005
4140
|
});
|
|
4006
|
-
|
|
4141
|
+
test26("should support standard fetch API with URL and Request objects", async (c) => {
|
|
4007
4142
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4008
4143
|
const actor = client.rawHttpActor.getOrCreate(["fetch-api-test"]);
|
|
4009
4144
|
const url = new URL("/api/echo", "http://example.com");
|
|
@@ -4012,18 +4147,18 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
4012
4147
|
headers: { "Content-Type": "application/json" },
|
|
4013
4148
|
body: JSON.stringify({ from: "URL object" })
|
|
4014
4149
|
});
|
|
4015
|
-
|
|
4150
|
+
expect26(urlResponse.ok).toBe(true);
|
|
4016
4151
|
const urlData = await urlResponse.json();
|
|
4017
|
-
|
|
4152
|
+
expect26(urlData).toEqual({ from: "URL object" });
|
|
4018
4153
|
const request = new Request("http://example.com/api/echo", {
|
|
4019
4154
|
method: "POST",
|
|
4020
4155
|
headers: { "Content-Type": "application/json" },
|
|
4021
4156
|
body: JSON.stringify({ from: "Request object" })
|
|
4022
4157
|
});
|
|
4023
4158
|
const requestResponse = await actor.fetch(request);
|
|
4024
|
-
|
|
4159
|
+
expect26(requestResponse.ok).toBe(true);
|
|
4025
4160
|
const requestData = await requestResponse.json();
|
|
4026
|
-
|
|
4161
|
+
expect26(requestData).toEqual({ from: "Request object" });
|
|
4027
4162
|
const request2 = new Request("http://example.com/api/headers", {
|
|
4028
4163
|
method: "GET",
|
|
4029
4164
|
headers: { "X-Original": "request-header" }
|
|
@@ -4031,19 +4166,19 @@ function runRawHttpTests(driverTestConfig) {
|
|
|
4031
4166
|
const overrideResponse = await actor.fetch(request2, {
|
|
4032
4167
|
headers: { "X-Override": "init-header" }
|
|
4033
4168
|
});
|
|
4034
|
-
|
|
4169
|
+
expect26(overrideResponse.ok).toBe(true);
|
|
4035
4170
|
const headers = await overrideResponse.json();
|
|
4036
|
-
|
|
4037
|
-
|
|
4171
|
+
expect26(headers["x-override"]).toBe("init-header");
|
|
4172
|
+
expect26(headers["x-original"]).toBe("request-header");
|
|
4038
4173
|
});
|
|
4039
4174
|
});
|
|
4040
4175
|
}
|
|
4041
4176
|
|
|
4042
4177
|
// src/driver-test-suite/tests/raw-http-request-properties.ts
|
|
4043
|
-
import { describe as
|
|
4178
|
+
import { describe as describe28, expect as expect27, test as test27 } from "vitest";
|
|
4044
4179
|
function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
4045
|
-
|
|
4046
|
-
|
|
4180
|
+
describe28("raw http request properties", () => {
|
|
4181
|
+
test27("should pass all Request properties correctly to onRequest", async (c) => {
|
|
4047
4182
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4048
4183
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4049
4184
|
"test"
|
|
@@ -4057,22 +4192,22 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4057
4192
|
},
|
|
4058
4193
|
body: JSON.stringify({ test: "data" })
|
|
4059
4194
|
});
|
|
4060
|
-
|
|
4195
|
+
expect27(response.ok).toBe(true);
|
|
4061
4196
|
const data = await response.json();
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4197
|
+
expect27(data.url).toContain("/test/path?foo=bar&baz=qux");
|
|
4198
|
+
expect27(data.pathname).toBe("/test/path");
|
|
4199
|
+
expect27(data.search).toBe("?foo=bar&baz=qux");
|
|
4200
|
+
expect27(data.searchParams).toEqual({
|
|
4066
4201
|
foo: "bar",
|
|
4067
4202
|
baz: "qux"
|
|
4068
4203
|
});
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4204
|
+
expect27(data.method).toBe("POST");
|
|
4205
|
+
expect27(data.headers["content-type"]).toBe("application/json");
|
|
4206
|
+
expect27(data.headers["x-custom-header"]).toBe("custom-value");
|
|
4207
|
+
expect27(data.headers["authorization"]).toBe("Bearer test-token");
|
|
4208
|
+
expect27(data.body).toEqual({ test: "data" });
|
|
4074
4209
|
});
|
|
4075
|
-
|
|
4210
|
+
test27("should handle GET requests with no body", async (c) => {
|
|
4076
4211
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4077
4212
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4078
4213
|
"test"
|
|
@@ -4080,12 +4215,12 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4080
4215
|
const response = await actor.fetch("test/get", {
|
|
4081
4216
|
method: "GET"
|
|
4082
4217
|
});
|
|
4083
|
-
|
|
4218
|
+
expect27(response.ok).toBe(true);
|
|
4084
4219
|
const data = await response.json();
|
|
4085
|
-
|
|
4086
|
-
|
|
4220
|
+
expect27(data.method).toBe("GET");
|
|
4221
|
+
expect27(data.body).toBeNull();
|
|
4087
4222
|
});
|
|
4088
|
-
|
|
4223
|
+
test27("should handle different content types", async (c) => {
|
|
4089
4224
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4090
4225
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4091
4226
|
"test"
|
|
@@ -4100,12 +4235,12 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4100
4235
|
},
|
|
4101
4236
|
body: formData.toString()
|
|
4102
4237
|
});
|
|
4103
|
-
|
|
4238
|
+
expect27(formResponse.ok).toBe(true);
|
|
4104
4239
|
const formResult = await formResponse.json();
|
|
4105
|
-
|
|
4240
|
+
expect27(formResult.headers["content-type"]).toBe(
|
|
4106
4241
|
"application/x-www-form-urlencoded"
|
|
4107
4242
|
);
|
|
4108
|
-
|
|
4243
|
+
expect27(formResult.bodyText).toBe("field1=value1&field2=value2");
|
|
4109
4244
|
const textResponse = await actor.fetch("test/text", {
|
|
4110
4245
|
method: "POST",
|
|
4111
4246
|
headers: {
|
|
@@ -4113,12 +4248,12 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4113
4248
|
},
|
|
4114
4249
|
body: "Hello, World!"
|
|
4115
4250
|
});
|
|
4116
|
-
|
|
4251
|
+
expect27(textResponse.ok).toBe(true);
|
|
4117
4252
|
const textResult = await textResponse.json();
|
|
4118
|
-
|
|
4119
|
-
|
|
4253
|
+
expect27(textResult.headers["content-type"]).toBe("text/plain");
|
|
4254
|
+
expect27(textResult.bodyText).toBe("Hello, World!");
|
|
4120
4255
|
});
|
|
4121
|
-
|
|
4256
|
+
test27("should preserve all header casing and values", async (c) => {
|
|
4122
4257
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4123
4258
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4124
4259
|
"test"
|
|
@@ -4132,38 +4267,38 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4132
4267
|
"X-Request-ID": "12345"
|
|
4133
4268
|
}
|
|
4134
4269
|
});
|
|
4135
|
-
|
|
4270
|
+
expect27(response.ok).toBe(true);
|
|
4136
4271
|
const data = await response.json();
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4272
|
+
expect27(data.headers["accept"]).toBe("application/json");
|
|
4273
|
+
expect27(data.headers["accept-language"]).toBe("en-US,en;q=0.9");
|
|
4274
|
+
expect27(data.headers["cache-control"]).toBe("no-cache");
|
|
4275
|
+
expect27(data.headers["user-agent"]).toBeTruthy();
|
|
4276
|
+
expect27(data.headers["x-request-id"]).toBe("12345");
|
|
4142
4277
|
});
|
|
4143
|
-
|
|
4278
|
+
test27("should handle empty and special URL paths", async (c) => {
|
|
4144
4279
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4145
4280
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4146
4281
|
"test"
|
|
4147
4282
|
]);
|
|
4148
4283
|
const rootResponse = await actor.fetch("");
|
|
4149
|
-
|
|
4284
|
+
expect27(rootResponse.ok).toBe(true);
|
|
4150
4285
|
const rootData = await rootResponse.json();
|
|
4151
|
-
|
|
4286
|
+
expect27(rootData.pathname).toBe("/");
|
|
4152
4287
|
const specialResponse = await actor.fetch(
|
|
4153
4288
|
"test/path%20with%20spaces/and%2Fslashes"
|
|
4154
4289
|
);
|
|
4155
|
-
|
|
4290
|
+
expect27(specialResponse.ok).toBe(true);
|
|
4156
4291
|
const specialData = await specialResponse.json();
|
|
4157
|
-
|
|
4292
|
+
expect27(specialData.pathname).toMatch(
|
|
4158
4293
|
/path.*with.*spaces.*and.*slashes/
|
|
4159
4294
|
);
|
|
4160
4295
|
const fragmentResponse = await actor.fetch("test/path#fragment");
|
|
4161
|
-
|
|
4296
|
+
expect27(fragmentResponse.ok).toBe(true);
|
|
4162
4297
|
const fragmentData = await fragmentResponse.json();
|
|
4163
|
-
|
|
4164
|
-
|
|
4298
|
+
expect27(fragmentData.pathname).toBe("/test/path");
|
|
4299
|
+
expect27(fragmentData.hash).toBe("");
|
|
4165
4300
|
});
|
|
4166
|
-
|
|
4301
|
+
test27("should handle request properties for all HTTP methods", async (c) => {
|
|
4167
4302
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4168
4303
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4169
4304
|
"test"
|
|
@@ -4187,21 +4322,21 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4187
4322
|
}
|
|
4188
4323
|
);
|
|
4189
4324
|
if (method === "HEAD") {
|
|
4190
|
-
|
|
4325
|
+
expect27(response.status).toBe(200);
|
|
4191
4326
|
const text = await response.text();
|
|
4192
|
-
|
|
4327
|
+
expect27(text).toBe("");
|
|
4193
4328
|
} else if (method === "OPTIONS") {
|
|
4194
|
-
|
|
4329
|
+
expect27(response.status).toBe(204);
|
|
4195
4330
|
const text = await response.text();
|
|
4196
|
-
|
|
4331
|
+
expect27(text).toBe("");
|
|
4197
4332
|
} else {
|
|
4198
|
-
|
|
4333
|
+
expect27(response.ok).toBe(true);
|
|
4199
4334
|
const data = await response.json();
|
|
4200
|
-
|
|
4335
|
+
expect27(data.method).toBe(method);
|
|
4201
4336
|
}
|
|
4202
4337
|
}
|
|
4203
4338
|
});
|
|
4204
|
-
|
|
4339
|
+
test27("should handle complex query parameters", async (c) => {
|
|
4205
4340
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4206
4341
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4207
4342
|
"test"
|
|
@@ -4209,13 +4344,13 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4209
4344
|
const response = await actor.fetch(
|
|
4210
4345
|
"test?key=value1&key=value2&array[]=1&array[]=2&nested[prop]=val"
|
|
4211
4346
|
);
|
|
4212
|
-
|
|
4347
|
+
expect27(response.ok).toBe(true);
|
|
4213
4348
|
const data = await response.json();
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4349
|
+
expect27(data.searchParams.key).toBe("value2");
|
|
4350
|
+
expect27(data.searchParams["array[]"]).toBe("2");
|
|
4351
|
+
expect27(data.searchParams["nested[prop]"]).toBe("val");
|
|
4217
4352
|
});
|
|
4218
|
-
|
|
4353
|
+
test27("should handle multipart form data", async (c) => {
|
|
4219
4354
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4220
4355
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4221
4356
|
"test"
|
|
@@ -4239,27 +4374,27 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4239
4374
|
},
|
|
4240
4375
|
body
|
|
4241
4376
|
});
|
|
4242
|
-
|
|
4377
|
+
expect27(response.ok).toBe(true);
|
|
4243
4378
|
const data = await response.json();
|
|
4244
|
-
|
|
4379
|
+
expect27(data.headers["content-type"]).toContain(
|
|
4245
4380
|
"multipart/form-data"
|
|
4246
4381
|
);
|
|
4247
|
-
|
|
4248
|
-
|
|
4382
|
+
expect27(data.bodyText).toContain("field1");
|
|
4383
|
+
expect27(data.bodyText).toContain("value1");
|
|
4249
4384
|
});
|
|
4250
|
-
|
|
4385
|
+
test27("should handle very long URLs", async (c) => {
|
|
4251
4386
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4252
4387
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4253
4388
|
"test"
|
|
4254
4389
|
]);
|
|
4255
4390
|
const longValue = "x".repeat(1e3);
|
|
4256
4391
|
const response = await actor.fetch(`test/long?param=${longValue}`);
|
|
4257
|
-
|
|
4392
|
+
expect27(response.ok).toBe(true);
|
|
4258
4393
|
const data = await response.json();
|
|
4259
|
-
|
|
4260
|
-
|
|
4394
|
+
expect27(data.searchParams.param).toBe(longValue);
|
|
4395
|
+
expect27(data.search.length).toBeGreaterThan(1e3);
|
|
4261
4396
|
});
|
|
4262
|
-
|
|
4397
|
+
test27.skip("should handle large request bodies", async (c) => {
|
|
4263
4398
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4264
4399
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4265
4400
|
"test"
|
|
@@ -4276,11 +4411,11 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4276
4411
|
},
|
|
4277
4412
|
body: JSON.stringify(largeArray)
|
|
4278
4413
|
});
|
|
4279
|
-
|
|
4414
|
+
expect27(response.ok).toBe(true);
|
|
4280
4415
|
const data = await response.json();
|
|
4281
|
-
|
|
4416
|
+
expect27(data.body).toHaveLength(1e4);
|
|
4282
4417
|
});
|
|
4283
|
-
|
|
4418
|
+
test27("should handle missing content-type header", async (c) => {
|
|
4284
4419
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4285
4420
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4286
4421
|
"test"
|
|
@@ -4289,11 +4424,11 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4289
4424
|
method: "POST",
|
|
4290
4425
|
body: "plain text without content-type"
|
|
4291
4426
|
});
|
|
4292
|
-
|
|
4427
|
+
expect27(response.ok).toBe(true);
|
|
4293
4428
|
const data = await response.json();
|
|
4294
|
-
|
|
4429
|
+
expect27(data.bodyText).toBe("plain text without content-type");
|
|
4295
4430
|
});
|
|
4296
|
-
|
|
4431
|
+
test27("should handle empty request body", async (c) => {
|
|
4297
4432
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4298
4433
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4299
4434
|
"test"
|
|
@@ -4305,9 +4440,9 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4305
4440
|
},
|
|
4306
4441
|
body: ""
|
|
4307
4442
|
});
|
|
4308
|
-
|
|
4443
|
+
expect27(response.ok).toBe(true);
|
|
4309
4444
|
});
|
|
4310
|
-
|
|
4445
|
+
test27("should handle custom HTTP methods", async (c) => {
|
|
4311
4446
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4312
4447
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4313
4448
|
"test"
|
|
@@ -4318,12 +4453,12 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4318
4453
|
});
|
|
4319
4454
|
if (response.ok) {
|
|
4320
4455
|
const data = await response.json();
|
|
4321
|
-
|
|
4456
|
+
expect27(data.method).toBe("CUSTOM");
|
|
4322
4457
|
}
|
|
4323
4458
|
} catch (error) {
|
|
4324
4459
|
}
|
|
4325
4460
|
});
|
|
4326
|
-
|
|
4461
|
+
test27("should handle cookies in headers", async (c) => {
|
|
4327
4462
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4328
4463
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4329
4464
|
"test"
|
|
@@ -4333,13 +4468,13 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4333
4468
|
Cookie: "session=abc123; user=test; preferences=dark_mode"
|
|
4334
4469
|
}
|
|
4335
4470
|
});
|
|
4336
|
-
|
|
4471
|
+
expect27(response.ok).toBe(true);
|
|
4337
4472
|
const data = await response.json();
|
|
4338
|
-
|
|
4473
|
+
expect27(data.headers.cookie).toBe(
|
|
4339
4474
|
"session=abc123; user=test; preferences=dark_mode"
|
|
4340
4475
|
);
|
|
4341
4476
|
});
|
|
4342
|
-
|
|
4477
|
+
test27("should handle URL encoding properly", async (c) => {
|
|
4343
4478
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4344
4479
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4345
4480
|
"test"
|
|
@@ -4347,13 +4482,13 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4347
4482
|
const response = await actor.fetch(
|
|
4348
4483
|
"test/encoded?special=%20%21%40%23%24%25%5E%26&unicode=%E2%9C%93&email=test%40example.com"
|
|
4349
4484
|
);
|
|
4350
|
-
|
|
4485
|
+
expect27(response.ok).toBe(true);
|
|
4351
4486
|
const data = await response.json();
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4487
|
+
expect27(data.searchParams.special).toBe(" !@#$%^&");
|
|
4488
|
+
expect27(data.searchParams.unicode).toBe("\u2713");
|
|
4489
|
+
expect27(data.searchParams.email).toBe("test@example.com");
|
|
4355
4490
|
});
|
|
4356
|
-
|
|
4491
|
+
test27("should handle concurrent requests maintaining separate contexts", async (c) => {
|
|
4357
4492
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4358
4493
|
const actor = client.rawHttpRequestPropertiesActor.getOrCreate([
|
|
4359
4494
|
"test"
|
|
@@ -4377,24 +4512,24 @@ function runRawHttpRequestPropertiesTests(driverTestConfig) {
|
|
|
4377
4512
|
const results = await Promise.all(
|
|
4378
4513
|
responses.map((r) => r.json())
|
|
4379
4514
|
);
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4515
|
+
expect27(results[0].searchParams.id).toBe("1");
|
|
4516
|
+
expect27(results[0].method).toBe("POST");
|
|
4517
|
+
expect27(results[0].body).toEqual({ request: 1 });
|
|
4518
|
+
expect27(results[1].searchParams.id).toBe("2");
|
|
4519
|
+
expect27(results[1].method).toBe("PUT");
|
|
4520
|
+
expect27(results[1].body).toEqual({ request: 2 });
|
|
4521
|
+
expect27(results[2].searchParams.id).toBe("3");
|
|
4522
|
+
expect27(results[2].method).toBe("DELETE");
|
|
4523
|
+
expect27(results[2].body).toBeNull();
|
|
4389
4524
|
});
|
|
4390
4525
|
});
|
|
4391
4526
|
}
|
|
4392
4527
|
|
|
4393
4528
|
// src/driver-test-suite/tests/raw-websocket.ts
|
|
4394
|
-
import { describe as
|
|
4529
|
+
import { describe as describe29, expect as expect28, test as test28 } from "vitest";
|
|
4395
4530
|
function runRawWebSocketTests(driverTestConfig) {
|
|
4396
|
-
|
|
4397
|
-
|
|
4531
|
+
describe29("raw websocket", () => {
|
|
4532
|
+
test28("should establish raw WebSocket connection", async (c) => {
|
|
4398
4533
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4399
4534
|
const actor = client.rawWebSocketActor.getOrCreate(["basic"]);
|
|
4400
4535
|
const ws = await actor.webSocket();
|
|
@@ -4421,11 +4556,11 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4421
4556
|
);
|
|
4422
4557
|
ws.addEventListener("close", reject);
|
|
4423
4558
|
});
|
|
4424
|
-
|
|
4425
|
-
|
|
4559
|
+
expect28(welcomeMessage.type).toBe("welcome");
|
|
4560
|
+
expect28(welcomeMessage.connectionCount).toBe(1);
|
|
4426
4561
|
ws.close();
|
|
4427
4562
|
});
|
|
4428
|
-
|
|
4563
|
+
test28("should echo messages", async (c) => {
|
|
4429
4564
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4430
4565
|
const actor = client.rawWebSocketActor.getOrCreate(["echo"]);
|
|
4431
4566
|
const ws = await actor.webSocket();
|
|
@@ -4453,10 +4588,10 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4453
4588
|
);
|
|
4454
4589
|
ws.addEventListener("close", reject);
|
|
4455
4590
|
});
|
|
4456
|
-
|
|
4591
|
+
expect28(echoMessage).toEqual(testMessage);
|
|
4457
4592
|
ws.close();
|
|
4458
4593
|
});
|
|
4459
|
-
|
|
4594
|
+
test28("should handle ping/pong protocol", async (c) => {
|
|
4460
4595
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4461
4596
|
const actor = client.rawWebSocketActor.getOrCreate(["ping"]);
|
|
4462
4597
|
const ws = await actor.webSocket();
|
|
@@ -4482,11 +4617,11 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4482
4617
|
});
|
|
4483
4618
|
ws.addEventListener("close", reject);
|
|
4484
4619
|
});
|
|
4485
|
-
|
|
4486
|
-
|
|
4620
|
+
expect28(pongMessage.type).toBe("pong");
|
|
4621
|
+
expect28(pongMessage.timestamp).toBeDefined();
|
|
4487
4622
|
ws.close();
|
|
4488
4623
|
});
|
|
4489
|
-
|
|
4624
|
+
test28("should track stats across connections", async (c) => {
|
|
4490
4625
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4491
4626
|
const actor1 = client.rawWebSocketActor.getOrCreate(["stats"]);
|
|
4492
4627
|
const ws1 = await actor1.webSocket();
|
|
@@ -4530,15 +4665,15 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4530
4665
|
});
|
|
4531
4666
|
ws1.send(JSON.stringify({ type: "getStats" }));
|
|
4532
4667
|
const stats = await statsPromise;
|
|
4533
|
-
|
|
4534
|
-
|
|
4668
|
+
expect28(stats.connectionCount).toBe(2);
|
|
4669
|
+
expect28(stats.messageCount).toBe(4);
|
|
4535
4670
|
const actionStats = await actor1.getStats();
|
|
4536
|
-
|
|
4537
|
-
|
|
4671
|
+
expect28(actionStats.connectionCount).toBe(2);
|
|
4672
|
+
expect28(actionStats.messageCount).toBe(4);
|
|
4538
4673
|
ws1.close();
|
|
4539
4674
|
ws2.close();
|
|
4540
4675
|
});
|
|
4541
|
-
|
|
4676
|
+
test28("should handle binary data", async (c) => {
|
|
4542
4677
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4543
4678
|
const actor = client.rawWebSocketBinaryActor.getOrCreate([
|
|
4544
4679
|
"binary"
|
|
@@ -4571,7 +4706,7 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4571
4706
|
const smallData = new Uint8Array([1, 2, 3, 4, 5]);
|
|
4572
4707
|
ws.send(smallData);
|
|
4573
4708
|
const smallReversed = await receiveBinaryMessage();
|
|
4574
|
-
|
|
4709
|
+
expect28(Array.from(smallReversed)).toEqual([5, 4, 3, 2, 1]);
|
|
4575
4710
|
const largeData = new Uint8Array(1024);
|
|
4576
4711
|
for (let i = 0; i < largeData.length; i++) {
|
|
4577
4712
|
largeData[i] = i % 256;
|
|
@@ -4579,13 +4714,13 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4579
4714
|
ws.send(largeData);
|
|
4580
4715
|
const largeReversed = await receiveBinaryMessage();
|
|
4581
4716
|
for (let i = 0; i < largeData.length; i++) {
|
|
4582
|
-
|
|
4717
|
+
expect28(largeReversed[i]).toBe(
|
|
4583
4718
|
largeData[largeData.length - 1 - i]
|
|
4584
4719
|
);
|
|
4585
4720
|
}
|
|
4586
4721
|
ws.close();
|
|
4587
4722
|
});
|
|
4588
|
-
|
|
4723
|
+
test28("should work with custom paths", async (c) => {
|
|
4589
4724
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4590
4725
|
const actor = client.rawWebSocketActor.getOrCreate(["paths"]);
|
|
4591
4726
|
const ws = await actor.webSocket("custom/path");
|
|
@@ -4605,10 +4740,10 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4605
4740
|
{ once: true }
|
|
4606
4741
|
);
|
|
4607
4742
|
});
|
|
4608
|
-
|
|
4743
|
+
expect28(welcomeMessage.type).toBe("welcome");
|
|
4609
4744
|
ws.close();
|
|
4610
4745
|
});
|
|
4611
|
-
|
|
4746
|
+
test28("should handle connection close properly", async (c) => {
|
|
4612
4747
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4613
4748
|
const actor = client.rawWebSocketActor.getOrCreate(["close-test"]);
|
|
4614
4749
|
const ws = await actor.webSocket();
|
|
@@ -4621,7 +4756,7 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4621
4756
|
});
|
|
4622
4757
|
}
|
|
4623
4758
|
const initialStats = await actor.getStats();
|
|
4624
|
-
|
|
4759
|
+
expect28(initialStats.connectionCount).toBe(1);
|
|
4625
4760
|
const closePromise = new Promise((resolve) => {
|
|
4626
4761
|
ws.addEventListener("close", () => resolve(), { once: true });
|
|
4627
4762
|
});
|
|
@@ -4635,9 +4770,9 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4635
4770
|
}
|
|
4636
4771
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
4637
4772
|
}
|
|
4638
|
-
|
|
4773
|
+
expect28(finalStats == null ? void 0 : finalStats.connectionCount).toBe(0);
|
|
4639
4774
|
});
|
|
4640
|
-
|
|
4775
|
+
test28("should properly handle onWebSocket open and close events", async (c) => {
|
|
4641
4776
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4642
4777
|
const actor = client.rawWebSocketActor.getOrCreate([
|
|
4643
4778
|
"open-close-test"
|
|
@@ -4657,8 +4792,8 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4657
4792
|
);
|
|
4658
4793
|
ws1.addEventListener("close", reject);
|
|
4659
4794
|
});
|
|
4660
|
-
|
|
4661
|
-
|
|
4795
|
+
expect28(welcome1.type).toBe("welcome");
|
|
4796
|
+
expect28(welcome1.connectionCount).toBe(1);
|
|
4662
4797
|
const ws2 = await actor.webSocket();
|
|
4663
4798
|
await new Promise((resolve, reject) => {
|
|
4664
4799
|
ws2.addEventListener("open", () => resolve(), { once: true });
|
|
@@ -4674,10 +4809,10 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4674
4809
|
);
|
|
4675
4810
|
ws2.addEventListener("close", reject);
|
|
4676
4811
|
});
|
|
4677
|
-
|
|
4678
|
-
|
|
4812
|
+
expect28(welcome2.type).toBe("welcome");
|
|
4813
|
+
expect28(welcome2.connectionCount).toBe(2);
|
|
4679
4814
|
const midStats = await actor.getStats();
|
|
4680
|
-
|
|
4815
|
+
expect28(midStats.connectionCount).toBe(2);
|
|
4681
4816
|
ws1.close();
|
|
4682
4817
|
await new Promise((resolve) => {
|
|
4683
4818
|
ws1.addEventListener("close", () => resolve(), { once: true });
|
|
@@ -4690,7 +4825,7 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4690
4825
|
}
|
|
4691
4826
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
4692
4827
|
}
|
|
4693
|
-
|
|
4828
|
+
expect28(afterFirstClose == null ? void 0 : afterFirstClose.connectionCount).toBe(1);
|
|
4694
4829
|
ws2.close();
|
|
4695
4830
|
await new Promise((resolve) => {
|
|
4696
4831
|
ws2.addEventListener("close", () => resolve(), { once: true });
|
|
@@ -4703,9 +4838,9 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4703
4838
|
}
|
|
4704
4839
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
4705
4840
|
}
|
|
4706
|
-
|
|
4841
|
+
expect28(finalStats == null ? void 0 : finalStats.connectionCount).toBe(0);
|
|
4707
4842
|
});
|
|
4708
|
-
|
|
4843
|
+
test28("should handle query parameters in websocket paths", async (c) => {
|
|
4709
4844
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4710
4845
|
const actor = client.rawWebSocketActor.getOrCreate([
|
|
4711
4846
|
"query-params"
|
|
@@ -4728,12 +4863,12 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4728
4863
|
});
|
|
4729
4864
|
ws.send(JSON.stringify({ type: "getRequestInfo" }));
|
|
4730
4865
|
const requestInfo = await requestInfoPromise;
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4866
|
+
expect28(requestInfo.url).toContain("api/v1/stream");
|
|
4867
|
+
expect28(requestInfo.url).toContain("token=abc123");
|
|
4868
|
+
expect28(requestInfo.url).toContain("user=test");
|
|
4734
4869
|
ws.close();
|
|
4735
4870
|
});
|
|
4736
|
-
|
|
4871
|
+
test28("should handle query parameters on base websocket path (no subpath)", async (c) => {
|
|
4737
4872
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4738
4873
|
const actor = client.rawWebSocketActor.getOrCreate([
|
|
4739
4874
|
"base-path-query-params"
|
|
@@ -4757,18 +4892,18 @@ function runRawWebSocketTests(driverTestConfig) {
|
|
|
4757
4892
|
});
|
|
4758
4893
|
ws.send(JSON.stringify({ type: "getRequestInfo" }));
|
|
4759
4894
|
const requestInfo = await requestInfoPromise;
|
|
4760
|
-
|
|
4761
|
-
|
|
4895
|
+
expect28(requestInfo.url).toContain("token=secret");
|
|
4896
|
+
expect28(requestInfo.url).toContain("session=123");
|
|
4762
4897
|
ws.close();
|
|
4763
4898
|
});
|
|
4764
4899
|
});
|
|
4765
4900
|
}
|
|
4766
4901
|
|
|
4767
4902
|
// src/driver-test-suite/tests/request-access.ts
|
|
4768
|
-
import { describe as
|
|
4903
|
+
import { describe as describe30, expect as expect29, test as test29 } from "vitest";
|
|
4769
4904
|
function runRequestAccessTests(driverTestConfig) {
|
|
4770
|
-
|
|
4771
|
-
|
|
4905
|
+
describe30("Request Access in Lifecycle Hooks", () => {
|
|
4906
|
+
test29("should have access to request object in onBeforeConnect and createConnState", async (c) => {
|
|
4772
4907
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4773
4908
|
const handle = client.requestAccessActor.getOrCreate(
|
|
4774
4909
|
["test-request"],
|
|
@@ -4779,23 +4914,23 @@ function runRequestAccessTests(driverTestConfig) {
|
|
|
4779
4914
|
const connection = handle.connect();
|
|
4780
4915
|
const requestInfo = await connection.getRequestInfo();
|
|
4781
4916
|
if (driverTestConfig.clientType === "http") {
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4917
|
+
expect29(requestInfo.onBeforeConnect.hasRequest).toBe(true);
|
|
4918
|
+
expect29(requestInfo.onBeforeConnect.requestUrl).toBeDefined();
|
|
4919
|
+
expect29(requestInfo.onBeforeConnect.requestMethod).toBeDefined();
|
|
4920
|
+
expect29(
|
|
4786
4921
|
requestInfo.onBeforeConnect.requestHeaders
|
|
4787
4922
|
).toBeDefined();
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4923
|
+
expect29(requestInfo.createConnState.hasRequest).toBe(true);
|
|
4924
|
+
expect29(requestInfo.createConnState.requestUrl).toBeDefined();
|
|
4925
|
+
expect29(requestInfo.createConnState.requestMethod).toBeDefined();
|
|
4926
|
+
expect29(
|
|
4792
4927
|
requestInfo.createConnState.requestHeaders
|
|
4793
4928
|
).toBeDefined();
|
|
4794
4929
|
} else {
|
|
4795
4930
|
}
|
|
4796
4931
|
await connection.dispose();
|
|
4797
4932
|
});
|
|
4798
|
-
|
|
4933
|
+
test29("should not have request when trackRequest is false", async (c) => {
|
|
4799
4934
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4800
4935
|
const handle = client.requestAccessActor.getOrCreate(
|
|
4801
4936
|
["test-no-request"],
|
|
@@ -4805,21 +4940,21 @@ function runRequestAccessTests(driverTestConfig) {
|
|
|
4805
4940
|
);
|
|
4806
4941
|
const connection = handle.connect();
|
|
4807
4942
|
const requestInfo = await connection.getRequestInfo();
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4943
|
+
expect29(requestInfo.onBeforeConnect.hasRequest).toBe(false);
|
|
4944
|
+
expect29(requestInfo.onBeforeConnect.requestUrl).toBeNull();
|
|
4945
|
+
expect29(requestInfo.onBeforeConnect.requestMethod).toBeNull();
|
|
4946
|
+
expect29(
|
|
4812
4947
|
Object.keys(requestInfo.onBeforeConnect.requestHeaders)
|
|
4813
4948
|
).toHaveLength(0);
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4949
|
+
expect29(requestInfo.createConnState.hasRequest).toBe(false);
|
|
4950
|
+
expect29(requestInfo.createConnState.requestUrl).toBeNull();
|
|
4951
|
+
expect29(requestInfo.createConnState.requestMethod).toBeNull();
|
|
4952
|
+
expect29(
|
|
4818
4953
|
Object.keys(requestInfo.createConnState.requestHeaders)
|
|
4819
4954
|
).toHaveLength(0);
|
|
4820
4955
|
await connection.dispose();
|
|
4821
4956
|
});
|
|
4822
|
-
|
|
4957
|
+
test29("should capture request headers and method", async (c) => {
|
|
4823
4958
|
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
4824
4959
|
const handle = client.requestAccessActor.getOrCreate(
|
|
4825
4960
|
["test-headers"],
|
|
@@ -4830,18 +4965,18 @@ function runRequestAccessTests(driverTestConfig) {
|
|
|
4830
4965
|
const connection = handle.connect();
|
|
4831
4966
|
const requestInfo = await connection.getRequestInfo();
|
|
4832
4967
|
if (driverTestConfig.clientType === "http") {
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4968
|
+
expect29(requestInfo.onBeforeConnect.hasRequest).toBe(true);
|
|
4969
|
+
expect29(requestInfo.onBeforeConnect.requestMethod).toBeTruthy();
|
|
4970
|
+
expect29(requestInfo.onBeforeConnect.requestUrl).toBeTruthy();
|
|
4971
|
+
expect29(requestInfo.onBeforeConnect.requestHeaders).toBeTruthy();
|
|
4972
|
+
expect29(typeof requestInfo.onBeforeConnect.requestHeaders).toBe(
|
|
4838
4973
|
"object"
|
|
4839
4974
|
);
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4975
|
+
expect29(requestInfo.createConnState.hasRequest).toBe(true);
|
|
4976
|
+
expect29(requestInfo.createConnState.requestMethod).toBeTruthy();
|
|
4977
|
+
expect29(requestInfo.createConnState.requestUrl).toBeTruthy();
|
|
4978
|
+
expect29(requestInfo.createConnState.requestHeaders).toBeTruthy();
|
|
4979
|
+
expect29(typeof requestInfo.createConnState.requestHeaders).toBe(
|
|
4845
4980
|
"object"
|
|
4846
4981
|
);
|
|
4847
4982
|
} else {
|
|
@@ -4853,14 +4988,14 @@ function runRequestAccessTests(driverTestConfig) {
|
|
|
4853
4988
|
|
|
4854
4989
|
// src/driver-test-suite/mod.ts
|
|
4855
4990
|
function runDriverTests(driverTestConfigPartial) {
|
|
4856
|
-
|
|
4991
|
+
describe31("Driver Tests", () => {
|
|
4857
4992
|
var _a;
|
|
4858
4993
|
const clientTypes = ((_a = driverTestConfigPartial.skip) == null ? void 0 : _a.inline) ? ["http"] : ["http", "inline"];
|
|
4859
4994
|
for (const clientType of clientTypes) {
|
|
4860
|
-
|
|
4995
|
+
describe31(`client type (${clientType})`, () => {
|
|
4861
4996
|
const encodings = ["bare", "cbor", "json"];
|
|
4862
4997
|
for (const encoding of encodings) {
|
|
4863
|
-
|
|
4998
|
+
describe31(`encoding (${encoding})`, () => {
|
|
4864
4999
|
const driverTestConfig = {
|
|
4865
5000
|
...driverTestConfigPartial,
|
|
4866
5001
|
clientType,
|
|
@@ -4871,6 +5006,7 @@ function runDriverTests(driverTestConfigPartial) {
|
|
|
4871
5006
|
runActorConnTests(driverTestConfig);
|
|
4872
5007
|
runActorConnStateTests(driverTestConfig);
|
|
4873
5008
|
runActorConnHibernationTests(driverTestConfig);
|
|
5009
|
+
runConnErrorSerializationTests(driverTestConfig);
|
|
4874
5010
|
runActorDbTests(driverTestConfig);
|
|
4875
5011
|
runActorDestroyTests(driverTestConfig);
|
|
4876
5012
|
runRequestAccessTests(driverTestConfig);
|