Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"os": ["darwin", "linux", "win32"],
"packageManager": "pnpm@12.25.1",
"scripts": {
"test": "node --test --test-concurrency=1 --test-force-exit --test-timeout=300000 \"tests/*.test.mjs\"",
"test": "node --test --test-concurrency=8 --test-force-exit --test-timeout=300000 \"tests/*.test.mjs\"",
"check": "node scripts/check.mjs"
},
"dependencies": {
Expand Down
5 changes: 3 additions & 2 deletions scripts/check.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// The repo's whole check, the same on macOS, Linux and Windows: a syntax pass over every
// module, then the test suite (fake gcloud, fake Google APIs, fake Ollama; nothing reaches Google).
// module, then the test suite (fake gcloud, fake Google APIs, fake Ollama; nothing reaches Google),
// with the test files running in parallel.
// pnpm check
import { readdirSync } from "node:fs";
import { join, dirname } from "node:path";
Expand All @@ -25,5 +26,5 @@ for (const f of files) {
console.log(`syntax: ${files.length - bad}/${files.length} files ok`);
if (bad) process.exit(1);

const t = spawnSync(process.execPath, ["--test", "--test-concurrency=1", "--test-force-exit", "--test-timeout=300000", "tests/*.test.mjs"], { stdio: "inherit", cwd: root });
const t = spawnSync(process.execPath, ["--test", "--test-concurrency=8", "--test-force-exit", "--test-timeout=300000", "tests/*.test.mjs"], { stdio: "inherit", cwd: root });
process.exit(t.status ?? 1);
4 changes: 2 additions & 2 deletions src/cloud.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function deleteEverything(s) {
regions = await serviceRegions(s);
} catch {
warn(`Could not list Cloud Run services (attempt ${attempt} of 5); retrying.`);
await sleep(10);
await sleep(10 * s.timeScale);
continue;
}
if (!regions.length) return true;
Expand All @@ -61,7 +61,7 @@ export async function deleteEverything(s) {
const r = await gcloud(s, ["run", "services", "delete", s.service, `--region=${region}`]);
if (r.code !== 0) {
warn(`Delete in ${region} failed (attempt ${attempt} of 5); retrying.`); // e.g. a deploy still in progress
await sleep(10);
await sleep(10 * s.timeScale);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export function loadSettings() {
currency: get("CURRENCY", "USD"), // the billing account's currency (setup detects it)
freeTier: get("FREE_TIER", "1") !== "0", // off if other Cloud Run use on the account takes it
allowPaid: get("ALLOW_PAID", "0") === "1", // lets a run without a keyboard go past the credit
// For tests: where Google's APIs are, and keys typed through a pipe count as a keyboard.
// For tests: shorter waits, where Google's APIs are, and keys typed through a pipe count as a keyboard.
timeScale: num("TIME_SCALE", 1), // multiplies the retry gaps and the length of a minute for the timers
monitoringApi: get("MONITORING_API", "https://monitoring.googleapis.com"),
billingApi: get("BILLING_API", "https://cloudbilling.googleapis.com"),
interactive: process.stdin.isTTY === true || env.RUNCODER_INTERACTIVE === "1",
Expand Down
6 changes: 3 additions & 3 deletions src/session.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function keepAlive(s, tunnel, region) {
// One failed check is not enough: a tunnel hiccup ("connection reset") looks the same for a moment.
for (let i = 0; i < 3; i++) {
if (await modelReady(s)) return;
await sleep(5);
await sleep(5 * s.timeScale);
}
const code = await httpCode(s, "/api/tags");
if (code === 200) {
Expand Down Expand Up @@ -124,7 +124,7 @@ async function session(s, workdir, tunnel, region) {
qwenGoneAt = 0;
}
await keepAlive(s, tunnel, region);
const minutes = Math.floor((Date.now() - started) / 60e3);
const minutes = Math.floor((Date.now() - started) / (60e3 * s.timeScale));

if (qwenAlive()) {
qwenSeen = true;
Expand All @@ -134,7 +134,7 @@ async function session(s, workdir, tunnel, region) {
say(`Qwen Code was closed. Press q to delete everything, or r to reopen it where you left off. Shutting down by itself in ${s.qwenIdleMinutes} minutes.`);
notify("Qwen Code closed: press q in the runcoder window to delete everything");
}
if (qwenGoneAt && Date.now() - qwenGoneAt >= s.qwenIdleMinutes * 60e3) {
if (qwenGoneAt && Date.now() - qwenGoneAt >= s.qwenIdleMinutes * 60e3 * s.timeScale) {
say(`Qwen Code has been closed for ${s.qwenIdleMinutes} minutes; shutting down.`);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tunnel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function pullProgress(s, region) {
}

export async function waitForModel(s, region, tunnel, costSoFar) {
const deadline = Date.now() + s.pullTimeoutMinutes * 60e3;
const deadline = Date.now() + s.pullTimeoutMinutes * 60e3 * s.timeScale;
let last = "";
say(`Downloading ${s.model} to the server (about 10 minutes for 30 GB)...`);
while (!(await modelReady(s))) {
Expand Down
8 changes: 5 additions & 3 deletions tests/2-recovery.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test("the server lost the model: detected after retries, downloaded again", asyn
const ctx = sandbox("t6");
const r = start(ctx);
assert.ok(await r.waitFor("Press q here", 60), r.out());
setReady(ctx, 40); // the restarted fake stays empty longer than the three retries
setReady(ctx, 10); // the restarted fake stays empty longer than the three retries (1s apart in tests)
await killProxy(ctx);
assert.ok(await r.waitFor("lost the model", 40), r.out());
assert.ok(await r.waitFor("runcoder is ready again", 90), r.out());
Expand All @@ -48,10 +48,12 @@ test("a brief hiccup is not reported as a lost model", async () => {
const ctx = sandbox("t24");
const r = start(ctx);
assert.ok(await r.waitFor("Press q here", 60), r.out());
// In tests the keep-alive checks every half second and retries 1s apart: an empty model for 1.5s
// is seen, but is back before the third retry, and a lost model would be reported within 4s.
touch(ctx, "empty");
await sleep(7);
await sleep(1.5);
rmSync(fake(ctx, "empty"));
await sleep(12);
await sleep(5);
assert.ok(!r.has("lost the model"), r.out());
r.press("q");
await r.done();
Expand Down
12 changes: 9 additions & 3 deletions tests/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import { spawn } from "node:child_process";
import { createServer } from "node:http";
import { mkdirSync, rmSync, writeFileSync, readFileSync, existsSync } from "node:fs";
import { join, delimiter, dirname } from "node:path";
import { join, delimiter, dirname, basename } from "node:path";
import { fileURLToPath } from "node:url";
import { killTree } from "../src/proc.mjs";

export const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
export const BIN = join(ROOT, "bin", "runcoder.mjs");
export const PORT = 18435;
// The test files run in parallel, each in its own process, so each has its own two local ports
// (PORT and PORT + 1) from the number its name starts with: 1-run.test.mjs gets 18437 and 18438.
const fileNumber = Number(basename(process.argv[1] ?? "").match(/^(\d+)-/)?.[1] ?? 0);
export const PORT = 18435 + 2 * fileNumber;
export const windows = process.platform === "win32";
const TMP = join(ROOT, "tests", "tmp");

Expand Down Expand Up @@ -82,7 +85,10 @@ export function sandbox(name, { config = true, billed = [], googleDown = false,
XDG_STATE_HOME: join(dir, "state"),
XDG_DATA_HOME: join(dir, "data"),
RUNCODER_PORT: String(PORT),
RUNCODER_TICK: "2",
// A keep-alive check every half second, its retries 1s apart (5s by default), deletes retried
// 2s apart (10s), and a minute of 12s for the idle, time-limit and download timers.
RUNCODER_TICK: "0.5",
RUNCODER_TIME_SCALE: "0.2",
RUNCODER_OPEN: "none",
RUNCODER_MONITORING_API: google.url,
RUNCODER_BILLING_API: google.url,
Expand Down
Loading