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
2 changes: 1 addition & 1 deletion scripts/dev/supervisor/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Child {
if (this.spec.readiness.kind === "log") {
const pattern = this.spec.readiness.pattern;
const offset = this.logOffset;
const seen = bestEffortValue(() => readFileSync(this.logFile(), "utf8").slice(offset).includes(pattern));
const seen = bestEffortValue(() => readFileSync(this.logFile()).includes(pattern, offset));
if (seen) return { ok: true };
} else {
const url = this.spec.readiness.url;
Expand Down
24 changes: 23 additions & 1 deletion test/dev-supervisor-child.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { mkdtempSync, rmSync, statSync, writeFileSync } from "node:fs";
import { createServer } from "node:net";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand Down Expand Up @@ -34,6 +34,28 @@ function spec(lock: string, port: number, extraArgs: string[] = []): ChildSpec {
};
}

test("child finds log readiness after existing multibyte UTF-8 content", async () => {
const lock = mkdtempSync(join(tmpdir(), "qm-child-"));
const port = await freeTcpPort();
const child = new Child(
spec(lock, port),
lock,
() => {},
() => {},
);
const prefix = "以前の起動\n";
writeFileSync(child.logFile(), prefix);
assert.equal(statSync(child.logFile()).size, Buffer.byteLength(prefix));

try {
const res = await child.start();
assert.equal(res.ok, true, res.detail);
} finally {
await child.stop();
rmSync(lock, { recursive: true, force: true });
}
});

test("child starts, reports ready via log pattern, and stops with the port released", async () => {
const lock = mkdtempSync(join(tmpdir(), "qm-child-"));
const port = await freeTcpPort();
Expand Down