Skip to content

Commit cde3b9d

Browse files
committed
[test] Kill and restart browser on test failure
1 parent 3b86c18 commit cde3b9d

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ jobs:
840840
EMTEST_SKIP_SIMD: "1"
841841
EMTEST_SKIP_SCONS: "1"
842842
EMTEST_SKIP_NODE_CANARY: "1"
843+
EMTEST_BROWSER: "0"
843844
steps:
844845
- checkout
845846
- run:

test/common.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,29 +1875,27 @@ class BrowserCore(RunnerCore):
18751875
def __init__(self, *args, **kwargs):
18761876
super().__init__(*args, **kwargs)
18771877

1878-
@staticmethod
1879-
def browser_open(url):
1880-
if not EMTEST_BROWSER:
1881-
logger.info('Using default system browser')
1882-
webbrowser.open_new(url)
1883-
return
1878+
@classmethod
1879+
def browser_restart(cls):
1880+
# Kill existing browser
1881+
logger.info("Restarting browser process")
1882+
cls.browser_proc.terminate()
1883+
try:
1884+
cls.browser_proc.wait(1)
1885+
except subprocess.TimeoutExpired:
1886+
cls.browser_proc.kill()
1887+
cls.browser_proc.wait()
1888+
cls.browser_open(cls.harness_url)
18841889

1890+
@classmethod
1891+
def browser_open(cls, url):
1892+
global EMTEST_BROWSER
1893+
if not EMTEST_BROWSER:
1894+
logger.info('No EMTEST_BROWSER set. Defaulting to `chrome`')
1895+
EMTEST_BROWSER = 'chrome'
18851896
browser_args = shlex.split(EMTEST_BROWSER)
1886-
# If the given browser is a scalar, treat it like one of the possible types
1887-
# from https://docs.python.org/2/library/webbrowser.html
1888-
if len(browser_args) == 1:
1889-
try:
1890-
# This throws if the type of browser isn't available
1891-
webbrowser.get(browser_args[0]).open_new(url)
1892-
logger.info('Using Emscripten browser: %s', browser_args[0])
1893-
return
1894-
except webbrowser.Error:
1895-
# Ignore the exception and fallback to the custom command logic
1896-
pass
1897-
# Else assume the given browser is a specific program with additional
1898-
# parameters and delegate to that
1899-
logger.info('Using Emscripten browser: %s', str(browser_args))
1900-
subprocess.Popen(browser_args + [url])
1897+
logger.info('Launching browser: %s', str(browser_args))
1898+
cls.browser_proc = subprocess.Popen(browser_args + [url])
19011899

19021900
@classmethod
19031901
def setUpClass(cls):
@@ -1912,7 +1910,8 @@ def setUpClass(cls):
19121910
cls.harness_server = multiprocessing.Process(target=harness_server_func, args=(cls.harness_in_queue, cls.harness_out_queue, cls.port))
19131911
cls.harness_server.start()
19141912
print('[Browser harness server on process %d]' % cls.harness_server.pid)
1915-
cls.browser_open('http://localhost:%s/run_harness' % cls.port)
1913+
cls.harness_url = 'http://localhost:%s/run_harness' % cls.port
1914+
cls.browser_open(cls.harness_url)
19161915

19171916
@classmethod
19181917
def tearDownClass(cls):
@@ -1944,7 +1943,7 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
19441943
if not has_browser():
19451944
return
19461945
if BrowserCore.unresponsive_tests >= BrowserCore.MAX_UNRESPONSIVE_TESTS:
1947-
self.skipTest('too many unresponsive tests, skipping browser launch - check your setup!')
1946+
self.skipTest('too many unresponsive tests, skipping remaining tests')
19481947
self.assert_out_queue_empty('previous test')
19491948
if DEBUG:
19501949
print('[browser launch:', html_file, ']')
@@ -1969,6 +1968,7 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
19691968
if not received_output:
19701969
BrowserCore.unresponsive_tests += 1
19711970
print('[unresponsive tests: %d]' % BrowserCore.unresponsive_tests)
1971+
self.browser_restart()
19721972
if output is None:
19731973
# the browser harness reported an error already, and sent a None to tell
19741974
# us to also fail the test

0 commit comments

Comments
 (0)