From ec48b3088bcf87d54c9e37faa4df4ce3126a9bda Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Wed, 6 Jul 2022 21:40:02 -0600 Subject: [PATCH] Create and reuse one puppeteer browser, see https://github.com/phetsims/aqua/issues/150 --- js/server/QuickServer.js | 44 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/js/server/QuickServer.js b/js/server/QuickServer.js index bb22122..890e9c8 100644 --- a/js/server/QuickServer.js +++ b/js/server/QuickServer.js @@ -24,6 +24,7 @@ const _ = require( 'lodash' ); // eslint-disable-line const path = require( 'path' ); const url = require( 'url' ); const winston = require( 'winston' ); +const puppeteer = require( 'puppeteer' ); const sendSlackMessage = require( './sendSlackMessage' ); const ctqType = { @@ -74,6 +75,29 @@ class QuickServer { let forceTests = true; let count = 0; + // Launch the browser once and reuse it to generate new pages in puppeteerLoad + const browser = await puppeteer.launch( { + + // With this flag, temp files are written to /tmp/ on bayes, which caused https://github.com/phetsims/aqua/issues/145 + // /dev/shm/ is much bigger + ignoreDefaultArgs: [ '--disable-dev-shm-usage' ], + + // Command line arguments passed to the chrome instance, + args: [ + '--enable-precise-memory-info', + + // To prevent filling up `/tmp`, see https://github.com/phetsims/aqua/issues/145 + `--user-data-dir=${process.cwd()}/../tmp/puppeteerUserData/` + ] + } ); + + const puppeteerOptions = { + waitAfterLoad: 10000, + allowedTimeToLoad: 120000, + puppeteerTimeout: 120000, + browser: browser + }; + while ( true ) { // eslint-disable-line try { @@ -136,26 +160,6 @@ class QuickServer { winston.info( 'QuickServer: sim fuzz' ); - const puppeteerOptions = { - waitAfterLoad: 10000, - allowedTimeToLoad: 120000, - puppeteerTimeout: 120000, - launchOptions: { - - // With this flag, temp files are written to /tmp/ on bayes, which caused https://github.com/phetsims/aqua/issues/145 - // /dev/shm/ is much bigger - ignoreDefaultArgs: [ '--disable-dev-shm-usage' ], - - // Command line arguments passed to the chrome instance, - args: [ - '--enable-precise-memory-info', - - // To prevent filling up `/tmp`, see https://github.com/phetsims/aqua/issues/145 - `--user-data-dir=${process.cwd()}/../tmp/puppeteerUserData/` - ] - } - }; - let simFuzz = null; try { await withServer( async port => {