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
34 changes: 30 additions & 4 deletions engine/sdks/typescript/test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const RIVET_RUNNER_TOTAL_SLOTS = process.env.RIVET_RUNNER_TOTAL_SLOTS
: 10000;
const RIVET_ENDPOINT = process.env.RIVET_ENDPOINT ?? "http://127.0.0.1:6420";
const RIVET_TOKEN = process.env.RIVET_TOKEN ?? "dev";
const AUTOSTART_SERVER = process.env.NO_AUTOSTART_SERVER === undefined;
const AUTOSTART_RUNNER = process.env.NO_AUTOSTART_RUNNER === undefined;
const AUTOSTART_SERVER = process.env.DISABLE_SERVER === undefined;
const AUTOSTART_RUNNER = process.env.AUTOSTART_RUNNER !== undefined;

const runnerStarted = Promise.withResolvers<Runner>();
const runnerStopped = Promise.withResolvers<Runner>();
Expand Down Expand Up @@ -78,7 +78,9 @@ app.get("/shutdown", async (c) => {

app.get("/start", async (c) => {
return streamSSE(c, async (stream) => {
runner = await startRunner(runnerStarted, runnerStopped);
const runnerStarted = Promise.withResolvers<Runner>();
const runnerStopped = Promise.withResolvers<Runner>();
const runner = await startRunner(runnerStarted, runnerStopped);

c.req.raw.signal.addEventListener("abort", () => {
getLogger().debug("SSE aborted, shutting down runner");
Expand All @@ -93,6 +95,13 @@ app.get("/start", async (c) => {
});
});

app.get("/metadata", async (c) => {
return c.json({
runtime: "test-runner",
version: "1",
});
});

if (AUTOSTART_SERVER) {
serve({
fetch: app.fetch,
Expand All @@ -107,7 +116,24 @@ if (AUTOSTART_RUNNER) {
runner = await startRunner(runnerStarted, runnerStopped);
} else await autoConfigureServerless();

process.on("SIGTERM", async () => {
getLogger().debug("received SIGTERM, force exiting in 3s");

await new Promise(res => setTimeout(res, 3000));

process.exit(0);
});
process.on("SIGINT", async () => {
getLogger().debug("received SIGTERM, force exiting in 3s");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste error in SIGINT handler log message. It says "received SIGTERM" but should say "received SIGINT".

getLogger().debug("received SIGINT, force exiting in 3s");
Suggested change
getLogger().debug("received SIGTERM, force exiting in 3s");
getLogger().debug("received SIGINT, force exiting in 3s");

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


await new Promise(res => setTimeout(res, 3000));

process.exit(0);
});
Comment on lines +119 to +132
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These signal handlers contain unhandled promises. Since Node.js event handlers don't wait for async functions to complete, these create 'floating promises'. Fix by either removing the async keyword and using setTimeout with a callback, or add .catch() handlers to properly handle errors.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


async function autoConfigureServerless() {
getLogger().info("Configuring serverless");

const res = await fetch(
`http://127.0.0.1:6420/runner-configs/${RIVET_RUNNER_NAME}?namespace=${RIVET_NAMESPACE}`,
{
Expand Down Expand Up @@ -158,7 +184,7 @@ async function startRunner(
onConnected: () => {
runnerStarted.resolve(runner);
},
onDisconnected: () => {},
onDisconnected: () => { },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent formatting with extra space after the empty function body. This should be formatted as 'onDisconnected: () => {}' to match the code style used elsewhere.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

onShutdown: () => {
runnerStopped.resolve(runner);
},
Expand Down
22 changes: 4 additions & 18 deletions engine/sdks/typescript/test-runner/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@ import {
export type { Logger } from "pino";

let baseLogger: Logger | undefined;
let configuredLogLevel: Level | undefined;

/** Cache of child loggers by logger name. */
const loggerCache = new Map<string, Logger>();

export function getPinoLevel(logLevel?: Level): LevelWithSilent {
// Priority: provided > configured > env > default
if (logLevel) {
return logLevel;
}

if (configuredLogLevel) {
return configuredLogLevel;
}

export function getPinoLevel(): LevelWithSilent {
// Priority: env > default
return (process.env["LOG_LEVEL"] || "warn")
.toString()
.toLowerCase() as LevelWithSilent;
Expand Down Expand Up @@ -90,14 +81,9 @@ function customWrite(level: string, o: any) {
/**
* Configure the default logger with optional log level.
*/
export async function configureDefaultLogger(logLevel?: Level): Promise<void> {
// Store the configured log level
if (logLevel) {
configuredLogLevel = logLevel;
}

export async function configureDefaultLogger(): Promise<void> {
baseLogger = pino({
level: getPinoLevel(logLevel),
level: getPinoLevel(),
messageKey: "msg",
// Do not include pid/hostname in output
base: {},
Expand Down
28 changes: 0 additions & 28 deletions engine/tests/load/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions engine/tests/load/actor-lifecycle/README.md

This file was deleted.

41 changes: 0 additions & 41 deletions engine/tests/load/actor-lifecycle/actor.ts

This file was deleted.

14 changes: 0 additions & 14 deletions engine/tests/load/actor-lifecycle/config.ts

This file was deleted.

62 changes: 0 additions & 62 deletions engine/tests/load/actor-lifecycle/index.ts

This file was deleted.

Loading
Loading