Skip to content

Commit

Permalink
More logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
taeold committed Nov 1, 2023
1 parent 3edb000 commit 9af4a18
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
51 changes: 29 additions & 22 deletions scripts/bin-test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface Testcase {
}

async function retryUntil(
name: string,
fn: () => Promise<boolean>,
timeoutMs: number,
sleepMs: number = TIMEOUT_S
Expand All @@ -77,7 +78,7 @@ async function retryUntil(
};
const timedOut = new Promise<never>((resolve, reject) => {
setTimeout(() => {
reject(new Error("retry timeout"));
reject(new Error(`retry timeout ${name}`));
}, timeoutMs);
});
const retry = (async () => {
Expand Down Expand Up @@ -122,32 +123,39 @@ async function startBin(
});
}

await retryUntil(async () => {
try {
await fetch(`http://localhost:${port}/__/functions.yaml`);
} catch (e) {
if (e?.code === "ECONNREFUSED") {
return false;
await retryUntil(
"functions.yaml",
async () => {
try {
await fetch(`http://localhost:${port}/__/functions.yaml`);
} catch (e) {
if (e?.code === "ECONNREFUSED") {
return false;
}
throw e;
}
throw e;
}
return true;
}, TIMEOUT_L);
return true;
},
TIMEOUT_L
);

return {
port,
cleanup: async () => {
process.kill(proc.pid, 9);
await retryUntil(() => {
try {
process.kill(proc.pid, 0);
} catch {
// process.kill w/ signal 0 will throw an error if the pid no longer exists.
console.log("Cleaned up admin server");
return Promise.resolve(true);
}
return Promise.resolve(false);
}, TIMEOUT_S);
await retryUntil(
"turndown",
() => {
try {
process.kill(proc.pid, 0);
} catch {
// process.kill w/ signal 0 will throw an error if the pid no longer exists.
return Promise.resolve(true);
}
return Promise.resolve(false);
},
TIMEOUT_S
);
},
};
}
Expand All @@ -164,7 +172,6 @@ describe("functions.yaml", () => {
});

after(async () => {
console.log("Turning down admin server");
if (cleanup) {
await cleanup();
}
Expand Down
3 changes: 0 additions & 3 deletions src/bin/firebase-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ app.post("/__/quitquitquit", handleQuitquitquit);

if (process.env.FUNCTIONS_CONTROL_API === "true") {
app.get("/__/functions.yaml", async (req, res) => {
console.log("received request at /--/functions.yaml");
try {
const stack = await loadStack(functionsDir);
res.setHeader("content-type", "text/yaml");
res.send(JSON.stringify(stackToWire(stack)));
console.log("sent response back at /--/functions.yaml");
} catch (e) {
console.error(e);
res.status(400).send(`Failed to generate manifest from function source: ${e}`);
Expand Down

0 comments on commit 9af4a18

Please sign in to comment.