Skip to content

test: test both websockets & sse in drivers #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions packages/misc/driver-test-suite/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { createNodeWebSocket, type NodeWebSocket } from "@hono/node-ws";
import invariant from "invariant";
import { bundleRequire } from "bundle-require";
import { getPort } from "actor-core/test";
import { Transport } from "actor-core/client";

export interface DriverTestConfig {
/** Deploys an app and returns the connection endpoint. */
Expand All @@ -32,6 +33,10 @@ export interface DriverTestConfig {
HACK_skipCleanupNet?: boolean;
}

export interface DriverTestConfigWithTransport extends DriverTestConfig {
transport: Transport;
}

export interface DriverDeployOutput {
endpoint: string;

Expand All @@ -41,10 +46,18 @@ export interface DriverDeployOutput {

/** Runs all Vitest tests against the provided drivers. */
export function runDriverTests(driverTestConfig: DriverTestConfig) {
describe("driver tests", () => {
runActorDriverTests(driverTestConfig);
runManagerDriverTests(driverTestConfig);
});
for (const transport of ["websocket", "sse"] as Transport[]) {
describe(`driver tests (${transport})`, () => {
runActorDriverTests({
...driverTestConfig,
transport,
});
runManagerDriverTests({
...driverTestConfig,
transport,
});
});
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/misc/driver-test-suite/src/tests/actor-driver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect, vi } from "vitest";
import type { DriverTestConfig } from "@/mod";
import type { DriverTestConfig, DriverTestConfigWithTransport } from "@/mod";
import { setupDriverTest } from "@/utils";
import { resolve } from "node:path";
import type { App as CounterApp } from "../../fixtures/apps/counter";
Expand All @@ -20,7 +20,7 @@ export async function waitFor(
return Promise.resolve();
}
}
export function runActorDriverTests(driverTestConfig: DriverTestConfig) {
export function runActorDriverTests(driverTestConfig: DriverTestConfigWithTransport) {
describe("Actor Driver Tests", () => {
describe("State Persistence", () => {
test("persists state between actor instances", async (c) => {
Expand Down Expand Up @@ -110,4 +110,4 @@ export function runActorDriverTests(driverTestConfig: DriverTestConfig) {
});
});
});
}
}
4 changes: 2 additions & 2 deletions packages/misc/driver-test-suite/src/tests/manager-driver.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, test, expect, vi } from "vitest";
import { waitFor, type DriverTestConfig } from "@/mod";
import { DriverTestConfigWithTransport, waitFor, type DriverTestConfig } from "@/mod";
import { setupDriverTest } from "@/utils";
import { resolve } from "node:path";
import type { App as CounterApp } from "../../fixtures/apps/counter";
import { ConnectionError } from "actor-core/client";

export function runManagerDriverTests(driverTestConfig: DriverTestConfig) {
export function runManagerDriverTests(driverTestConfig: DriverTestConfigWithTransport) {
describe("Manager Driver Tests", () => {
describe("Client Connection Methods", () => {
test("connect() - finds or creates an actor", async (c) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/misc/driver-test-suite/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ActorCoreApp } from "actor-core";
import { type TestContext, vi } from "vitest";
import { createClient, type Client } from "actor-core/client";
import type { DriverTestConfig } from "./mod";
import { createClient, Transport, type Client } from "actor-core/client";
import type { DriverTestConfig, DriverTestConfigWithTransport } from "./mod";

// Must use `TestContext` since global hooks do not work when running concurrently
export async function setupDriverTest<A extends ActorCoreApp<any>>(
c: TestContext,
driverTestConfig: DriverTestConfig,
driverTestConfig: DriverTestConfigWithTransport,
appPath: string,
): Promise<{
client: Client<A>;
Expand All @@ -20,7 +20,9 @@ export async function setupDriverTest<A extends ActorCoreApp<any>>(
c.onTestFinished(cleanup);

// Create client
const client = createClient<A>(endpoint);
const client = createClient<A>(endpoint, {
transport: driverTestConfig.transport,
});
if (!driverTestConfig.HACK_skipCleanupNet) {
c.onTestFinished(async () => await client.dispose());
}
Expand Down
Loading