Skip to content

Commit c5d61c6

Browse files
committed
chore: move test suite to actor-core package
1 parent 6d54739 commit c5d61c6

33 files changed

+173
-264
lines changed

packages/actor-core/package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
"name": "actor-core",
33
"version": "0.8.0",
44
"license": "Apache-2.0",
5-
"files": [
6-
"dist",
7-
"src",
8-
"deno.json",
9-
"bun.json",
10-
"package.json"
11-
],
5+
"files": ["dist", "src", "deno.json", "bun.json", "package.json"],
126
"type": "module",
137
"bin": "./dist/cli/mod.cjs",
148
"exports": {
@@ -72,6 +66,16 @@
7266
"default": "./dist/driver-helpers/mod.cjs"
7367
}
7468
},
69+
"./driver-test-suite": {
70+
"import": {
71+
"types": "./dist/driver-test-suite/mod.d.ts",
72+
"default": "./dist/driver-test-suite/mod.js"
73+
},
74+
"require": {
75+
"types": "./dist/driver-test-suite/mod.d.cts",
76+
"default": "./dist/driver-test-suite/mod.cjs"
77+
}
78+
},
7579
"./topologies/coordinate": {
7680
"import": {
7781
"types": "./dist/topologies/coordinate/mod.d.ts",
@@ -159,7 +163,7 @@
159163
"sideEffects": false,
160164
"scripts": {
161165
"dev": "yarn build --watch",
162-
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/cli/mod.ts src/actor/protocol/inspector/mod.ts src/actor/protocol/http/rpc.ts src/test/mod.ts src/inspector/protocol/actor/mod.ts src/inspector/protocol/manager/mod.ts src/inspector/mod.ts",
166+
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/cli/mod.ts src/actor/protocol/inspector/mod.ts src/actor/protocol/http/rpc.ts src/test/mod.ts src/inspector/protocol/actor/mod.ts src/inspector/protocol/manager/mod.ts src/inspector/mod.ts",
163167
"check-types": "tsc --noEmit",
164168
"boop": "tsc --outDir dist/test -d",
165169
"test": "vitest run",
@@ -181,7 +185,10 @@
181185
"tsup": "^8.4.0",
182186
"typescript": "^5.7.3",
183187
"vitest": "^3.1.1",
184-
"ws": "^8.18.1"
188+
"ws": "^8.18.1",
189+
"@hono/node-server": "^1.14.0",
190+
"@hono/node-ws": "^1.1.1",
191+
"bundle-require": "^5.1.0"
185192
},
186193
"peerDependencies": {
187194
"eventsource": "^3.0.5",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getLogger } from "@/common/log";
2+
3+
export const LOGGER_NAME = "test-suite";
4+
5+
export function logger() {
6+
return getLogger(LOGGER_NAME);
7+
}

packages/misc/driver-test-suite/src/mod.ts renamed to packages/actor-core/src/driver-test-suite/mod.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import {
44
CoordinateDriver,
55
DriverConfig,
66
ManagerDriver,
7-
} from "actor-core/driver-helpers";
7+
} from "@/driver-helpers/mod";
88
import { runActorDriverTests, waitFor } from "./tests/actor-driver";
99
import { runManagerDriverTests } from "./tests/manager-driver";
1010
import { describe } from "vitest";
1111
import {
1212
type ActorCoreApp,
1313
CoordinateTopology,
1414
StandaloneTopology,
15-
} from "actor-core";
15+
} from "@/mod";
1616
import { createNodeWebSocket, type NodeWebSocket } from "@hono/node-ws";
1717
import invariant from "invariant";
1818
import { bundleRequire } from "bundle-require";
19-
import { getPort } from "actor-core/test";
20-
import { Transport } from "actor-core/client";
19+
import { getPort } from "@/test/mod";
20+
import { Transport } from "@/client/mod";
2121

2222
export interface DriverTestConfig {
2323
/** Deploys an app and returns the connection endpoint. */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { resolve } from "node:path";
2+
3+
export type { App as CounterApp } from "../../fixtures/driver-test-suite/counter";
4+
export type { App as ScheduledApp } from "../../fixtures/driver-test-suite/scheduled";
5+
6+
export const COUNTER_APP_PATH = resolve(
7+
__dirname,
8+
"../../fixtures/driver-test-suite/counter.ts",
9+
);
10+
export const SCHEDULED_APP_PATH = resolve(
11+
__dirname,
12+
"../../fixtures/driver-test-suite/scheduled.ts",
13+
);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { describe, test, expect, vi } from "vitest";
2-
import type { DriverTestConfig, DriverTestConfigWithTransport } from "@/mod";
3-
import { setupDriverTest } from "@/utils";
4-
import { resolve } from "node:path";
5-
import type { App as CounterApp } from "../../fixtures/apps/counter";
6-
import type { App as ScheduledApp } from "../../fixtures/apps/scheduled";
2+
import type { DriverTestConfig, DriverTestConfigWithTransport } from "../mod";
3+
import { setupDriverTest } from "../utils";
4+
import {
5+
COUNTER_APP_PATH,
6+
SCHEDULED_APP_PATH,
7+
type CounterApp,
8+
type ScheduledApp,
9+
} from "../test-apps";
710

811
/**
912
* Waits for the specified time, using either real setTimeout or vi.advanceTimersByTime
@@ -20,14 +23,16 @@ export async function waitFor(
2023
return Promise.resolve();
2124
}
2225
}
23-
export function runActorDriverTests(driverTestConfig: DriverTestConfigWithTransport) {
26+
export function runActorDriverTests(
27+
driverTestConfig: DriverTestConfigWithTransport,
28+
) {
2429
describe("Actor Driver Tests", () => {
2530
describe("State Persistence", () => {
2631
test("persists state between actor instances", async (c) => {
2732
const { client } = await setupDriverTest<CounterApp>(
2833
c,
2934
driverTestConfig,
30-
resolve(__dirname, "../fixtures/apps/counter.ts"),
35+
COUNTER_APP_PATH,
3136
);
3237

3338
// Create instance and increment
@@ -45,13 +50,13 @@ export function runActorDriverTests(driverTestConfig: DriverTestConfigWithTransp
4550
const { client } = await setupDriverTest<CounterApp>(
4651
c,
4752
driverTestConfig,
48-
resolve(__dirname, "../fixtures/apps/counter.ts"),
53+
COUNTER_APP_PATH,
4954
);
5055

5156
// Create actor and set initial state
5257
const counterInstance = client.counter.getOrCreate();
5358
await counterInstance.increment(5);
54-
59+
5560
// Reconnect to the same actor
5661
const reconnectedInstance = client.counter.getOrCreate();
5762
const persistedCount = await reconnectedInstance.increment(0);
@@ -62,17 +67,17 @@ export function runActorDriverTests(driverTestConfig: DriverTestConfigWithTransp
6267
const { client } = await setupDriverTest<CounterApp>(
6368
c,
6469
driverTestConfig,
65-
resolve(__dirname, "../fixtures/apps/counter.ts"),
70+
COUNTER_APP_PATH,
6671
);
6772

6873
// Create first counter with specific key
6974
const counterA = client.counter.getOrCreate(["counter-a"]);
7075
await counterA.increment(5);
71-
76+
7277
// Create second counter with different key
7378
const counterB = client.counter.getOrCreate(["counter-b"]);
7479
await counterB.increment(10);
75-
80+
7681
// Verify state is separate
7782
const countA = await counterA.increment(0);
7883
const countB = await counterB.increment(0);
@@ -86,74 +91,59 @@ export function runActorDriverTests(driverTestConfig: DriverTestConfigWithTransp
8691
const { client } = await setupDriverTest<ScheduledApp>(
8792
c,
8893
driverTestConfig,
89-
resolve(__dirname, "../fixtures/apps/scheduled.ts"),
94+
SCHEDULED_APP_PATH,
9095
);
9196

9297
// Create instance
9398
const alarmInstance = client.scheduled.getOrCreate();
94-
99+
95100
// Schedule a task to run in 100ms
96101
await alarmInstance.scheduleTask(100);
97-
102+
98103
// Wait for longer than the scheduled time
99104
await waitFor(driverTestConfig, 150);
100-
105+
101106
// Verify the scheduled task ran
102107
const lastRun = await alarmInstance.getLastRun();
103108
const scheduledCount = await alarmInstance.getScheduledCount();
104-
109+
105110
expect(lastRun).toBeGreaterThan(0);
106111
expect(scheduledCount).toBe(1);
107112
});
108113
});
109-
114+
110115
describe("Actor Handle", () => {
111116
test("stateless handle can perform RPC calls", async (c) => {
112117
const { client } = await setupDriverTest<CounterApp>(
113118
c,
114119
driverTestConfig,
115-
resolve(__dirname, "../fixtures/apps/counter.ts"),
120+
COUNTER_APP_PATH,
116121
);
117-
122+
118123
// Get a handle to an actor
119124
const counterHandle = client.counter.getOrCreate("test-handle");
120125
await counterHandle.increment(1);
121126
await counterHandle.increment(2);
122127
const count = await counterHandle.getCount();
123128
expect(count).toBe(3);
124129
});
125-
130+
126131
test("stateless handles to same actor share state", async (c) => {
127132
const { client } = await setupDriverTest<CounterApp>(
128133
c,
129134
driverTestConfig,
130-
resolve(__dirname, "../fixtures/apps/counter.ts"),
135+
COUNTER_APP_PATH,
131136
);
132-
137+
133138
// Get a handle to an actor
134139
const handle1 = client.counter.getOrCreate("test-handle-shared");
135140
await handle1.increment(5);
136-
141+
137142
// Get another handle to same actor
138143
const handle2 = client.counter.getOrCreate("test-handle-shared");
139144
const count = await handle2.getCount();
140145
expect(count).toBe(5);
141146
});
142-
143-
// TODO: Fix this
144-
//test("create new actor with handle", async (c) => {
145-
// const { client } = await setupDriverTest<CounterApp>(
146-
// c,
147-
// driverTestConfig,
148-
// resolve(__dirname, "../fixtures/apps/counter.ts"),
149-
// );
150-
//
151-
// // Create a new actor with handle
152-
// const createdHandle = client.counter.create("test-handle-create");
153-
// await createdHandle.increment(5);
154-
// const count = await createdHandle.getCount();
155-
// expect(count).toBe(5);
156-
//});
157147
});
158148
});
159149
}

0 commit comments

Comments
 (0)