Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { db } from "../../src/db/mod";
import { actor, event, queue, setup, UserError } from "../../src/mod";
import { buildNativeRegistry } from "../../src/registry/native";

const textDecoder = new TextDecoder();
const fixtureDir = dirname(fileURLToPath(import.meta.url));
const repoEngineBinary = resolve(
fixtureDir,
Expand Down Expand Up @@ -79,9 +78,10 @@ const integrationActor = actor({
await c.db.execute(
"CREATE TABLE IF NOT EXISTS increments (value INTEGER NOT NULL)",
);
await c.db.execute("INSERT INTO increments (value) VALUES (?)", [
await c.db.execute(
"INSERT INTO increments (value) VALUES (?)",
c.state.count,
]);
);

const rows = await c.db.execute<{ value: number }>(
"SELECT value FROM increments ORDER BY rowid ASC",
Expand All @@ -102,7 +102,7 @@ const integrationActor = actor({

return {
count: c.state.count,
kvCount: kvValue ? Number(textDecoder.decode(kvValue)) : null,
kvCount: kvValue ? Number(kvValue) : null,
sqliteValues: rows.map(({ value }) => Number(value)),
};
},
Expand All @@ -117,12 +117,14 @@ const integrationActor = actor({
const kvValue = await c.kv.get("count");
return {
count: c.state.count,
kvCount: kvValue ? Number(textDecoder.decode(kvValue)) : null,
kvCount: kvValue ? Number(kvValue) : null,
};
},
getCountViaClient: async (c) => {
const client = c.client<any>();
return await client.integrationActor.getForId(c.actorId).getCount();
return await client.integrationActor
.getForId(c.actorId, { params: c.conn.params })
.getCount();
},
throwTypedError: async () => {
throw new UserError("native typed error", {
Expand Down Expand Up @@ -159,4 +161,20 @@ const { registry: nativeRegistry, serveConfig } = await buildNativeRegistry(
);
serveConfig.engineBinaryPath = resolveEngineBinaryPath();

await nativeRegistry.serve(serveConfig);
const shutdown = new Promise<"signal">((resolve) => {
process.once("SIGINT", () => resolve("signal"));
});
const serving = nativeRegistry.serve(serveConfig);

await nativeRegistry.waitReady();
const stopReason = await Promise.race([
shutdown,
serving.then(() => "registry" as const),
]);
if (stopReason === "registry") {
throw new Error(
"native registry stopped before the test requested shutdown",
);
}
await nativeRegistry.shutdown();
await serving;
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ describe.sequential("native NAPI runtime integration", () => {

const handle = await waitForActorReady(
() =>
client.integrationActor.create([
`napi-runtime-${crypto.randomUUID()}`,
]),
client.integrationActor.create(
[`napi-runtime-${crypto.randomUUID()}`],
{ params: { userId: "native-integration-test" } },
),
30_000,
);
const actorId = await handle.resolve();
Expand Down Expand Up @@ -384,7 +385,7 @@ describe.sequential("native NAPI runtime integration", () => {
},
});
await expect(handle.throwUntypedError()).rejects.toMatchObject({
group: "core",
group: "rivetkit",
code: "internal_error",
message: "An internal error occurred",
});
Expand Down