Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
test(e2e): await the server's exit in stopServer instead of a blocking poll
zchpeterf476f0dfe2ea
diff --git a/frontend/tests/e2e/framework/global-setup.ts b/frontend/tests/e2e/framework/global-setup.tsindex 7851c7e502..075160ab34 100644--- a/frontend/tests/e2e/framework/global-setup.ts+++ b/frontend/tests/e2e/framework/global-setup.ts@@ -36,7 +36,7 @@ async function globalSetup() {// Playwright does NOT run globalTeardown when globalSetup throws, so tear// the half-started server down here — otherwise a failed boot orphans a// process group and temp dir that starve every subsequent run's boot.- stopServer();+ await stopServer();throw err;}diff --git a/frontend/tests/e2e/framework/global-teardown.ts b/frontend/tests/e2e/framework/global-teardown.tsindex d49f431728..17278f079b 100644--- a/frontend/tests/e2e/framework/global-teardown.ts+++ b/frontend/tests/e2e/framework/global-teardown.ts@@ -2,7 +2,7 @@ import { cleanupEnvFile } from "./env";import { stopServer } from "./mode-start-new-bytebase";async function globalTeardown() {- stopServer();+ await stopServer();cleanupEnvFile();}diff --git a/frontend/tests/e2e/framework/mode-start-new-bytebase.ts b/frontend/tests/e2e/framework/mode-start-new-bytebase.tsindex d8721b0e29..5038848b24 100644--- a/frontend/tests/e2e/framework/mode-start-new-bytebase.ts+++ b/frontend/tests/e2e/framework/mode-start-new-bytebase.ts@@ -305,30 +305,35 @@ export async function startServer(): Promise<{};}-export function stopServer(): void {+export async function stopServer(): Promise<void> {if (serverProcess?.pid) {- const pid = serverProcess.pid;- try {- process.kill(-pid, "SIGTERM");- } catch {- /* already dead */- }- // Wait for the process group to actually exit before removing its data+ const child = serverProcess;+ serverProcess = undefined;+ // Wait for the server to actually exit before removing its data// directory. Deleting it while the embedded Postgres is still shutting down// makes the checkpointer PANIC ("could not fsync pg_xact/0000") and leaves// the metadata-Postgres socket (/tmp/.s.PGSQL.<PORT+2>) behind, which then- // trips the next boot's port probe. Bounded so a wedged server can't block- // teardown forever.- const deadline = Date.now() + 15_000;- while (Date.now() < deadline) {+ // trips the next boot's port probe. The wait must be asynchronous: Node+ // reaps the child on the event loop, so a blocking poll of `kill(pid, 0)`+ // would only ever see a zombie and run to its deadline. Bounded (a ref'd+ // timer keeps the loop alive) so a wedged server can't block teardown.+ await new Promise<void>((resolve) => {+ if (child.exitCode !== null || child.signalCode !== null) {+ resolve();+ return;+ }+ const timer = setTimeout(resolve, 15_000);+ child.once("exit", () => {+ clearTimeout(timer);+ resolve();+ });try {- process.kill(pid, 0); // throws once the process is gone+ process.kill(-child.pid!, "SIGTERM");} catch {- break;+ clearTimeout(timer);+ resolve(); // already dead}- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);- }- serverProcess = undefined;+ });}if (tempDir && fs.existsSync(tempDir)) {fs.rmSync(tempDir, { recursive: true, force: true });