Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

test(e2e): insert the plan statement atomically; SIGKILL a server that ignores SIGTERM

zchpeterf381f829834e
diff --git a/frontend/tests/e2e/framework/mode-start-new-bytebase.ts b/frontend/tests/e2e/framework/mode-start-new-bytebase.ts
index 5038848b24..b5c7b6bfb1 100644
--- a/frontend/tests/e2e/framework/mode-start-new-bytebase.ts
+++ b/frontend/tests/e2e/framework/mode-start-new-bytebase.ts
@@ -315,25 +315,36 @@ export async function stopServer(): Promise<void> {
// the metadata-Postgres socket (/tmp/.s.PGSQL.<PORT+2>) behind, which then
// 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();
+ // would only ever see a zombie and run to its deadline. Bounded (ref'd
+ // timers keep the loop alive): a server that ignores SIGTERM for 15 s is
+ // SIGKILLed as a group and given a short grace so the directory is never
+ // deleted under a live Postgres.
+ const exited = () => child.exitCode !== null || child.signalCode !== null;
+ const waitExit = (ms: number) =>
+ new Promise<void>((resolve) => {
+ if (exited()) {
+ resolve();
+ return;
+ }
+ const timer = setTimeout(resolve, ms);
+ child.once("exit", () => {
+ clearTimeout(timer);
+ resolve();
+ });
});
+ const signalGroup = (signal: NodeJS.Signals) => {
try {
- process.kill(-child.pid!, "SIGTERM");
+ process.kill(-child.pid!, signal);
} catch {
- clearTimeout(timer);
- resolve(); // already dead
+ /* already dead */
}
- });
+ };
+ signalGroup("SIGTERM");
+ await waitExit(15_000);
+ if (!exited()) {
+ signalGroup("SIGKILL");
+ await waitExit(5_000);
+ }
}
if (tempDir && fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
diff --git a/frontend/tests/e2e/framework/ui-create-plan.ts b/frontend/tests/e2e/framework/ui-create-plan.ts
index 171f5a0f85..29c9159a61 100644
--- a/frontend/tests/e2e/framework/ui-create-plan.ts
+++ b/frontend/tests/e2e/framework/ui-create-plan.ts
@@ -41,8 +41,19 @@ export async function createDatabaseChangePlanViaUI(
await page.goto(
`${opts.baseURL}/projects/${opts.projectId}/plans/create/specs/placeholder?${q.toString()}`,
);
- await page.locator(".monaco-editor").first().click();
- await page.keyboard.type(opts.sql);
+ // Enter the statement atomically: `keyboard.type` feeds Monaco one key at a
+ // time and drops keystrokes on a loaded worker (this suite has observed
+ // first-character loss), while Create only requires NON-EMPTY SQL — a damaged
+ // statement would still be created and fail later, far from its cause.
+ // `insertText` paints the whole string in one input event, and the editor is
+ // checked to show it before Create is pressed.
+ const editor = page.locator(".monaco-editor").first();
+ await editor.click();
+ await page.keyboard.insertText(opts.sql);
+ await expect(editor.locator(".view-lines")).toContainText(
+ opts.sql.split("\n")[0].trim(),
+ { timeout: 10_000 },
+ );
const createBtn = page.getByRole("button", { name: "Create", exact: true });
await expect(createBtn).toBeEnabled({ timeout: 15_000 });
await createBtn.click();