Skip to content

Commit 11f5908

Browse files
authored
Add EMTEST_RESTART_BROWSER_EVERY_N_TESTS feature (#25589)
Add EMTEST_RESTART_BROWSER_EVERY_N_TESTS feature that allows restarting the browser after every N tests. Allows working around https://bugzilla.mozilla.org/show_bug.cgi?id=1992558
1 parent c7625b1 commit 11f5908

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/common.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@
9090
if 'EM_BUILD_VERBOSE' in os.environ:
9191
exit_with_error('EM_BUILD_VERBOSE has been renamed to EMTEST_BUILD_VERBOSE')
9292

93+
# Triggers the browser to restart after every given number of tests.
94+
# 0: Disabled (reuse the browser instance to run all tests. Default)
95+
# 1: Restart a fresh browser instance for every browser test.
96+
# 2,3,...: Restart a fresh browser instance after given number of tests have been run in it.
97+
# Helps with e.g. https://bugzil.la/1992558
98+
EMTEST_RESTART_BROWSER_EVERY_N_TESTS = int(os.getenv('EMTEST_RESTART_BROWSER_EVERY_N_TESTS', '0'))
99+
93100
# If we are drawing a parallel swimlane graph of test output, we need to use a temp
94101
# file to track which tests were flaky so they can be graphed in orange color to
95102
# visually stand out.
@@ -2569,6 +2576,7 @@ class BrowserCore(RunnerCore):
25692576
BROWSER_TIMEOUT = 60
25702577

25712578
unresponsive_tests = 0
2579+
num_tests_ran = 0
25722580

25732581
def __init__(self, *args, **kwargs):
25742582
self.capture_stdio = EMTEST_CAPTURE_STDIO
@@ -2585,6 +2593,7 @@ def browser_restart(cls):
25852593
logger.info('Restarting browser process')
25862594
cls.browser_terminate()
25872595
cls.browser_open(cls.HARNESS_URL)
2596+
BrowserCore.num_tests_ran = 0
25882597

25892598
@classmethod
25902599
def browser_open(cls, url):
@@ -2652,7 +2661,7 @@ def launch_browser_harness_with_proc_snapshot_workaround(cls, parallel_harness,
26522661
# Give the browser time to spawn its subprocesses. Use an increasing
26532662
# timeout as a crude way to account for system load.
26542663
if parallel_harness or is_safari():
2655-
time.sleep(2 + count * 0.3)
2664+
time.sleep(min(2 + count * 0.3, 10))
26562665
procs_after = list_processes_by_name(config.executable_name)
26572666

26582667
# Take a snapshot again to find which processes exist after launching
@@ -2736,6 +2745,12 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
27362745
self.skipTest('skipping test execution: ' + self.skip_exec)
27372746
if BrowserCore.unresponsive_tests >= BrowserCore.MAX_UNRESPONSIVE_TESTS:
27382747
self.skipTest('too many unresponsive tests, skipping remaining tests')
2748+
2749+
if EMTEST_RESTART_BROWSER_EVERY_N_TESTS and BrowserCore.num_tests_ran >= EMTEST_RESTART_BROWSER_EVERY_N_TESTS:
2750+
logger.warning(f'[EMTEST_RESTART_BROWSER_EVERY_N_TESTS={EMTEST_RESTART_BROWSER_EVERY_N_TESTS} workaround: restarting browser]')
2751+
self.browser_restart()
2752+
BrowserCore.num_tests_ran += 1
2753+
27392754
self.assert_out_queue_empty('previous test')
27402755
if DEBUG:
27412756
print('[browser launch:', html_file, ']')

0 commit comments

Comments
 (0)