From 1714376ab1177f84148c0f403357dc2f9ceb4126 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Tue, 11 Feb 2025 07:06:55 -0800 Subject: [PATCH 1/4] chore(test): add additional success condition to SIGINT asset save test --- tests/library/inspector/cli-codegen-2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/library/inspector/cli-codegen-2.spec.ts b/tests/library/inspector/cli-codegen-2.spec.ts index 6419a6999c..e87e242bfd 100644 --- a/tests/library/inspector/cli-codegen-2.spec.ts +++ b/tests/library/inspector/cli-codegen-2.spec.ts @@ -464,7 +464,7 @@ await page1.GotoAsync("about:blank?foo");`); expect(exitCode).toBe(130); } else { // If the runner is slow enough, the process will be forcibly terminated by the signal - expect(signal).toBe('SIGINT'); + expect(signal === 'SIGINT' || signal === 'SIGTERM').toBeTruthy(); } expect(fs.existsSync(storageFileName)).toBeTruthy(); expect(fs.existsSync(harFileName)).toBeTruthy(); From fc1ec40bdeee1983fc2ac21e5db9d874f00d859f Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Tue, 11 Feb 2025 08:10:45 -0800 Subject: [PATCH 2/4] Switch to regex match --- tests/library/inspector/cli-codegen-2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/library/inspector/cli-codegen-2.spec.ts b/tests/library/inspector/cli-codegen-2.spec.ts index e87e242bfd..255daea979 100644 --- a/tests/library/inspector/cli-codegen-2.spec.ts +++ b/tests/library/inspector/cli-codegen-2.spec.ts @@ -464,7 +464,7 @@ await page1.GotoAsync("about:blank?foo");`); expect(exitCode).toBe(130); } else { // If the runner is slow enough, the process will be forcibly terminated by the signal - expect(signal === 'SIGINT' || signal === 'SIGTERM').toBeTruthy(); + expect(signal).toMatch(/SIGINT|SIGTERM/); } expect(fs.existsSync(storageFileName)).toBeTruthy(); expect(fs.existsSync(harFileName)).toBeTruthy(); From 2d2cc6384007324176cc0368301295686a10c255 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Tue, 11 Feb 2025 09:49:01 -0800 Subject: [PATCH 3/4] SIGKILL not SIGTERM --- tests/library/inspector/cli-codegen-2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/library/inspector/cli-codegen-2.spec.ts b/tests/library/inspector/cli-codegen-2.spec.ts index 255daea979..2e3b52cacc 100644 --- a/tests/library/inspector/cli-codegen-2.spec.ts +++ b/tests/library/inspector/cli-codegen-2.spec.ts @@ -464,7 +464,7 @@ await page1.GotoAsync("about:blank?foo");`); expect(exitCode).toBe(130); } else { // If the runner is slow enough, the process will be forcibly terminated by the signal - expect(signal).toMatch(/SIGINT|SIGTERM/); + expect(signal).toMatch(/SIGINT|SIGKILL/); } expect(fs.existsSync(storageFileName)).toBeTruthy(); expect(fs.existsSync(harFileName)).toBeTruthy(); From cb7233ee5b6c0896f917c1be9bca277fee9ec720 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Thu, 13 Feb 2025 10:14:59 -0800 Subject: [PATCH 4/4] Test logging --- packages/playwright-core/src/cli/driver.ts | 1 + packages/playwright-core/src/cli/program.ts | 1 + packages/playwright/src/common/process.ts | 8 ++++++-- packages/playwright/src/runner/sigIntWatcher.ts | 1 + tests/library/inspector/cli-codegen-2.spec.ts | 3 +++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/cli/driver.ts b/packages/playwright-core/src/cli/driver.ts index cb7ade9d7a..291706d6f7 100644 --- a/packages/playwright-core/src/cli/driver.ts +++ b/packages/playwright-core/src/cli/driver.ts @@ -57,6 +57,7 @@ export function runDriver() { // We still will destruct everything (close browsers and exit) when the transport pipe closes. process.on('SIGINT', () => { // Keep the process running. + console.log('SIGINT received'); }); } diff --git a/packages/playwright-core/src/cli/program.ts b/packages/playwright-core/src/cli/program.ts index 38b3072f3a..a399d4a88f 100644 --- a/packages/playwright-core/src/cli/program.ts +++ b/packages/playwright-core/src/cli/program.ts @@ -527,6 +527,7 @@ async function launchContext(options: Options, extraOptions: LaunchOptions): Pro }); }); process.on('SIGINT', async () => { + console.log('SIGINT received, closing browser...'); await closeBrowser(); gracefullyProcessExitDoNotHang(130); }); diff --git a/packages/playwright/src/common/process.ts b/packages/playwright/src/common/process.ts index 54dd2fe991..b46f68b32f 100644 --- a/packages/playwright/src/common/process.ts +++ b/packages/playwright/src/common/process.ts @@ -51,8 +51,12 @@ let forceExitInitiated = false; sendMessageToParent({ method: 'ready' }); process.on('disconnect', () => gracefullyCloseAndExit(true)); -process.on('SIGINT', () => {}); -process.on('SIGTERM', () => {}); +process.on('SIGINT', () => { + console.log('SIGINT received'); +}); +process.on('SIGTERM', () => { + console.log('SIGTERM received'); +}); // Clear execArgv immediately, so that the user-code does not inherit our loader. process.execArgv = execArgvWithoutExperimentalLoaderOptions(); diff --git a/packages/playwright/src/runner/sigIntWatcher.ts b/packages/playwright/src/runner/sigIntWatcher.ts index c9d29d86e9..a4844fb3b0 100644 --- a/packages/playwright/src/runner/sigIntWatcher.ts +++ b/packages/playwright/src/runner/sigIntWatcher.ts @@ -49,6 +49,7 @@ class FixedNodeSIGINTHandler { private static _handlerInstalled = false; static _dispatch = () => { + console.log('SIGINT received'); if (this._ignoreNextSIGINTs) return; diff --git a/tests/library/inspector/cli-codegen-2.spec.ts b/tests/library/inspector/cli-codegen-2.spec.ts index 2e3b52cacc..ebd22e524f 100644 --- a/tests/library/inspector/cli-codegen-2.spec.ts +++ b/tests/library/inspector/cli-codegen-2.spec.ts @@ -458,6 +458,9 @@ await page1.GotoAsync("about:blank?foo");`); const harFileName = testInfo.outputPath('har.har'); const cli = runCLI([`--save-storage=${storageFileName}`, `--save-har=${harFileName}`]); await cli.waitFor(`import { test, expect } from '@playwright/test'`); + cli.process.process.on('SIGINT', () => { + console.log('Local SIGINT'); + }); await cli.process.kill('SIGINT'); const { exitCode, signal } = await cli.process.exited; if (exitCode !== null) {