From 30153a9de616f81c6b9ce18bc1490b9f938cdc7c Mon Sep 17 00:00:00 2001 From: davemfish Date: Wed, 2 Aug 2023 13:35:44 -0400 Subject: [PATCH 1/5] close all pages before closing browser. #1362 --- workbench/tests/binary_tests/puppet.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/workbench/tests/binary_tests/puppet.test.js b/workbench/tests/binary_tests/puppet.test.js index 05fb96b8eb..f853c4425c 100644 --- a/workbench/tests/binary_tests/puppet.test.js +++ b/workbench/tests/binary_tests/puppet.test.js @@ -133,13 +133,16 @@ beforeEach(() => { afterEach(async () => { try { + const pages = await BROWSER.pages(); + await Promise.all(pages.map(page => page.close())); await BROWSER.close(); } catch (error) { console.log(BINARY_PATH); console.error(error); + } finally { + ELECTRON_PROCESS.removeAllListeners(); + ELECTRON_PROCESS.kill(); } - ELECTRON_PROCESS.removeAllListeners(); - ELECTRON_PROCESS.kill(); }); test('Run a real invest model', async () => { From fafd7eeab97f077f144d34bd7c103c08014cacfa Mon Sep 17 00:00:00 2001 From: davemfish Date: Wed, 2 Aug 2023 14:12:46 -0400 Subject: [PATCH 2/5] wait before clicking in a few places. #1362 --- workbench/tests/binary_tests/puppet.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workbench/tests/binary_tests/puppet.test.js b/workbench/tests/binary_tests/puppet.test.js index f853c4425c..fc99946507 100644 --- a/workbench/tests/binary_tests/puppet.test.js +++ b/workbench/tests/binary_tests/puppet.test.js @@ -167,6 +167,7 @@ test('Run a real invest model', async () => { const downloadModal = await page.waitForSelector('.modal-dialog'); const downloadModalCancel = await downloadModal.waitForSelector( 'aria/[name="Cancel"][role="button"]'); + await page.waitForTimeout(300); // waiting for click handler to be ready await downloadModalCancel.click(); // We need to get the modelButton from w/in this list-group because there // are buttons with the same name in the Recent Jobs container. @@ -235,11 +236,13 @@ test('Check local userguide links', async () => { const downloadModal = await page.waitForSelector('.modal-dialog'); const downloadModalCancel = await downloadModal.waitForSelector( 'aria/[name="Cancel"][role="button"]'); + await page.waitForTimeout(500); // waiting for click handler to be ready await downloadModalCancel.click(); const investList = await page.waitForSelector('.invest-list-group'); const modelButtons = await investList.$$('aria/[role="button"]'); + await page.waitForTimeout(300); // first btn click does not register w/o this pause for (const btn of modelButtons) { await btn.click(); const link = await page.waitForSelector('text/User\'s Guide'); From f04cd1d7934fd34bdb5535f67047b5c6d9d67e15 Mon Sep 17 00:00:00 2001 From: davemfish Date: Mon, 7 Aug 2023 09:02:24 -0400 Subject: [PATCH 3/5] use synchronous taskkill to shutdown child process. #1362 --- .../src/main/createPythonFlaskProcess.js | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/workbench/src/main/createPythonFlaskProcess.js b/workbench/src/main/createPythonFlaskProcess.js index 4ccd8a87bc..7e5cb863f4 100644 --- a/workbench/src/main/createPythonFlaskProcess.js +++ b/workbench/src/main/createPythonFlaskProcess.js @@ -1,4 +1,4 @@ -import { spawn, exec } from 'child_process'; +import { spawn, execSync } from 'child_process'; import fetch from 'node-fetch'; @@ -88,26 +88,12 @@ export async function shutdownPythonProcess(subprocess) { subprocess.kill(); } else { const { pid } = subprocess; - exec(`taskkill /pid ${pid} /t /f`); + execSync(`taskkill /pid ${pid} /t /f`); } } catch (error) { // if the process was already killed by some other means logger.debug(error); + } finally { + Promise.resolve(); } - - // If we return too quickly, it seems the electron app is allowed - // to quit before the subprocess is killed, and the subprocess remains - // open. Here we poll a flask endpoint and resolve only when it - // gives ECONNREFUSED. - return fetch(`${HOSTNAME}:${process.env.PORT}/ready`, { - method: 'get', - }) - .then(async () => { - await new Promise((resolve) => setTimeout(resolve, 300)); - return shutdownPythonProcess(subprocess); - }) - .catch(() => { - logger.debug('flask server is closed'); - return Promise.resolve(); - }); } From 18a356e75c5b5bf858c2f5e04df9128dfbd21039 Mon Sep 17 00:00:00 2001 From: davemfish Date: Mon, 7 Aug 2023 10:49:45 -0400 Subject: [PATCH 4/5] prefer BROWSER.close for ending the electron process. #1362 --- workbench/tests/binary_tests/puppet.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/workbench/tests/binary_tests/puppet.test.js b/workbench/tests/binary_tests/puppet.test.js index fc99946507..fa42fa18cb 100644 --- a/workbench/tests/binary_tests/puppet.test.js +++ b/workbench/tests/binary_tests/puppet.test.js @@ -139,8 +139,7 @@ afterEach(async () => { } catch (error) { console.log(BINARY_PATH); console.error(error); - } finally { - ELECTRON_PROCESS.removeAllListeners(); + // Normally BROWSER.close() will kill this process ELECTRON_PROCESS.kill(); } }); From 864a29ebe9be518853435b35198cfbed237ac38c Mon Sep 17 00:00:00 2001 From: davemfish Date: Thu, 10 Aug 2023 11:18:46 -0400 Subject: [PATCH 5/5] a variable to hold a constant. #1362 --- workbench/tests/binary_tests/puppet.test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/workbench/tests/binary_tests/puppet.test.js b/workbench/tests/binary_tests/puppet.test.js index fa42fa18cb..1a6175a09e 100644 --- a/workbench/tests/binary_tests/puppet.test.js +++ b/workbench/tests/binary_tests/puppet.test.js @@ -16,6 +16,7 @@ import { APP_HAS_RUN_TOKEN } from '../../src/main/setupCheckFirstRun'; jest.setTimeout(240000); const PORT = 9009; +const WAIT_TO_CLICK = 300; // ms let ELECTRON_PROCESS; let BROWSER; @@ -166,7 +167,7 @@ test('Run a real invest model', async () => { const downloadModal = await page.waitForSelector('.modal-dialog'); const downloadModalCancel = await downloadModal.waitForSelector( 'aria/[name="Cancel"][role="button"]'); - await page.waitForTimeout(300); // waiting for click handler to be ready + await page.waitForTimeout(WAIT_TO_CLICK); // waiting for click handler to be ready await downloadModalCancel.click(); // We need to get the modelButton from w/in this list-group because there // are buttons with the same name in the Recent Jobs container. @@ -235,17 +236,17 @@ test('Check local userguide links', async () => { const downloadModal = await page.waitForSelector('.modal-dialog'); const downloadModalCancel = await downloadModal.waitForSelector( 'aria/[name="Cancel"][role="button"]'); - await page.waitForTimeout(500); // waiting for click handler to be ready + await page.waitForTimeout(WAIT_TO_CLICK); // waiting for click handler to be ready await downloadModalCancel.click(); const investList = await page.waitForSelector('.invest-list-group'); const modelButtons = await investList.$$('aria/[role="button"]'); - await page.waitForTimeout(300); // first btn click does not register w/o this pause + await page.waitForTimeout(WAIT_TO_CLICK); // first btn click does not register w/o this pause for (const btn of modelButtons) { await btn.click(); const link = await page.waitForSelector('text/User\'s Guide'); - await page.waitForTimeout(300); // link.click() not working w/o this pause + await page.waitForTimeout(WAIT_TO_CLICK); // link.click() not working w/o this pause const hrefHandle = await link.getProperty('href'); const hrefValue = await hrefHandle.jsonValue(); await link.click();