mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-03 09:39:25 +00:00
fix: avoid mock-server port races in concurrent tests (#150492)
Prevent startup port collisions in concurrent mock OpenAI tests by acquiring the port in the server process.
This commit is contained in:
parent
e3e3a349b9
commit
b30dc1e626
1 changed files with 5 additions and 3 deletions
|
|
@ -173,7 +173,7 @@ async function withMockServer(
|
|||
},
|
||||
) => Promise<void>,
|
||||
) {
|
||||
const port = env.MOCK_PORT === undefined ? await getFreePort() : Number(env.MOCK_PORT);
|
||||
const port = Number(env.MOCK_PORT ?? "0");
|
||||
let stderr = "";
|
||||
let stdout = "";
|
||||
const child = spawn(process.execPath, [scriptPath], {
|
||||
|
|
@ -1148,8 +1148,9 @@ describe("mock OpenAI response markers", () => {
|
|||
});
|
||||
|
||||
describe("e2e mock and config helper numeric limits", () => {
|
||||
it("reports the actual OS-assigned port for MOCK_PORT=0", async () => {
|
||||
await withMockServer(mockOpenAiPath, { MOCK_PORT: "0" }, async (baseUrl, output) => {
|
||||
it.each([undefined, "0"])("reports the bound port for MOCK_PORT=%s", async (port) => {
|
||||
const env: Record<string, string> = port === undefined ? {} : { MOCK_PORT: port };
|
||||
await withMockServer(mockOpenAiPath, env, async (baseUrl, output) => {
|
||||
expect(Number(new URL(baseUrl).port)).toBeGreaterThan(0);
|
||||
expect(output.stdout()).not.toContain("mock-openai listening on 0\n");
|
||||
const response = await fetch(`${baseUrl}/v1/responses`, {
|
||||
|
|
@ -1274,6 +1275,7 @@ describe("e2e mock and config helper numeric limits", () => {
|
|||
await withMockServer(
|
||||
webSearchMockPath,
|
||||
{
|
||||
MOCK_PORT: String(await getFreePort()),
|
||||
MOCK_REQUEST_LOG: requestLogDirectory,
|
||||
RAW_SCHEMA_ERROR: "400 schema rejected",
|
||||
SUCCESS_MARKER: "OPENCLAW_SCHEMA_E2E_OK",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue