diff --git a/site/source/docs/porting/files/Synchronous-Virtual-XHR-Backed-File-System-Usage.rst b/site/source/docs/porting/files/Synchronous-Virtual-XHR-Backed-File-System-Usage.rst index c8904f3f530e1..af5f07b372dfa 100644 --- a/site/source/docs/porting/files/Synchronous-Virtual-XHR-Backed-File-System-Usage.rst +++ b/site/source/docs/porting/files/Synchronous-Virtual-XHR-Backed-File-System-Usage.rst @@ -63,6 +63,6 @@ Instructions .. include:: ../../../../../test/test_browser.py :literal: - :start-after: create_file('main.html', - :end-before: """ % (worker_filename, self.port)) + :start-after: create_file('main.html', ''' + :end-before: ''' % self.PORT) :code: html diff --git a/test/browser_reporting.js b/test/browser_reporting.js index f651b8b1092ea..603c29f9b0907 100644 --- a/test/browser_reporting.js +++ b/test/browser_reporting.js @@ -1,10 +1,8 @@ var hasModule = typeof Module === 'object' && Module; -/** - * @param {number=} port - */ -function reportResultToServer(result, port) { - port = port || 8888; +var reportingURL = 'http://localhost:8888/'; + +function reportResultToServer(result) { if (reportResultToServer.reported) { // Only report one result per test, even if the test misbehaves and tries to report more. reportErrorToServer(`excessive reported results, sending ${result}, test will fail`); @@ -14,7 +12,7 @@ function reportResultToServer(result, port) { out(`RESULT: ${result}`); } else { let doFetch = typeof origFetch != 'undefined' ? origFetch : fetch; - doFetch(`http://localhost:${port}/report_result?${encodeURIComponent(result)}`).then(() => { + doFetch(`${reportingURL}/report_result?${encodeURIComponent(result)}`).then(() => { if (typeof window === 'object' && window && hasModule && !Module['pageThrewException']) { /* for easy debugging, don't close window on failure */ window.close(); @@ -24,26 +22,24 @@ function reportResultToServer(result, port) { } function sendFileToServer(filename, contents) { - fetch(`http://localhost:8888/?file=${encodeURIComponent(filename)}`, {method: "POST", body: contents}); + fetch(`${reportingURL}/?file=${encodeURIComponent(filename)}`, {method: "POST", body: contents}); } -/** - * @param {number=} port - */ -function maybeReportResultToServer(result, port) { - if (reportResultToServer.reported) return; - reportResultToServer(result, port); +function maybeReportResultToServer(result) { + if (!reportResultToServer.reported) { + reportResultToServer(result); + } } function reportErrorToServer(message) { if (typeof ENVIRONMENT_IS_NODE !== 'undefined' && ENVIRONMENT_IS_NODE) { err(message); } else { - fetch(`http://localhost:8888?stderr=${encodeURIComponent(message)}`); + fetch(`${reportingURL}?stderr=${encodeURIComponent(message)}`); } } -function report_error(e) { +function reportTopLevelError(e) { // MINIMAL_RUNTIME doesn't handle exit or call the below onExit handler // so we detect the exit by parsing the uncaught exception message. var message = e.message || e; @@ -68,9 +64,9 @@ function report_error(e) { if (typeof window === 'object' && window) { window.addEventListener('error', event => { - report_error(event.error || event) + reportTopLevelError(event.error || event) }); - window.addEventListener('unhandledrejection', event => report_error(event.reason)); + window.addEventListener('unhandledrejection', event => reportTopLevelError(event.reason)); } if (hasModule) { diff --git a/test/common.py b/test/common.py index 95fd4116068e6..b6e958af77107 100644 --- a/test/common.py +++ b/test/common.py @@ -2072,6 +2072,9 @@ class BrowserCore(RunnerCore): # suite early, as otherwise we will wait for the timeout on every # single test (hundreds of minutes) MAX_UNRESPONSIVE_TESTS = 10 + PORT = 8888 + HARNESS_URL = 'http://localhost:%s/run_harness' % PORT + BROWSER_TIMEOUT = 60 unresponsive_tests = 0 @@ -2091,7 +2094,7 @@ def browser_restart(cls): logger.info('Browser did not respond to `terminate`. Using `kill`') cls.browser_proc.kill() cls.browser_proc.wait() - cls.browser_open(cls.harness_url) + cls.browser_open(cls.HARNESS_URL) @classmethod def browser_open(cls, url): @@ -2106,17 +2109,14 @@ def browser_open(cls, url): @classmethod def setUpClass(cls): super().setUpClass() - cls.port = int(os.getenv('EMTEST_BROWSER_PORT', '8888')) if not has_browser() or EMTEST_BROWSER == 'node': return - cls.browser_timeout = 60 cls.harness_in_queue = multiprocessing.Queue() cls.harness_out_queue = multiprocessing.Queue() - cls.harness_server = multiprocessing.Process(target=harness_server_func, args=(cls.harness_in_queue, cls.harness_out_queue, cls.port)) + cls.harness_server = multiprocessing.Process(target=harness_server_func, args=(cls.harness_in_queue, cls.harness_out_queue, cls.PORT)) cls.harness_server.start() print('[Browser harness server on process %d]' % cls.harness_server.pid) - cls.harness_url = 'http://localhost:%s/run_harness' % cls.port - cls.browser_open(cls.harness_url) + cls.browser_open(cls.HARNESS_URL) @classmethod def tearDownClass(cls): @@ -2158,11 +2158,11 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr if expected is not None: try: self.harness_in_queue.put(( - 'http://localhost:%s/%s' % (self.port, html_file), + 'http://localhost:%s/%s' % (self.PORT, html_file), self.get_dir() )) if timeout is None: - timeout = self.browser_timeout + timeout = self.BROWSER_TIMEOUT try: output = self.harness_out_queue.get(block=True, timeout=timeout) except queue.Empty: @@ -2213,7 +2213,6 @@ def compile_btest(self, filename, args, reporting=Reporting.FULL): # If C reporting (i.e. the REPORT_RESULT macro) is required we # also include report_result.c and force-include report_result.h self.run_process([EMCC, '-c', '-I' + TEST_ROOT, - '-DEMTEST_PORT_NUMBER=%d' % self.port, test_file('report_result.c')] + self.get_emcc_args(compile_only=True) + (['-fPIC'] if '-fPIC' in args else [])) args += ['report_result.o', '-include', test_file('report_result.h')] if EMTEST_BROWSER == 'node': diff --git a/test/report_result.c b/test/report_result.c index a7a33f012f0cb..7cf7952b33661 100644 --- a/test/report_result.c +++ b/test/report_result.c @@ -20,20 +20,13 @@ extern "C" { #endif #if defined __EMSCRIPTEN__ && !defined EMTEST_NODE -#ifndef EMTEST_PORT_NUMBER -#error "EMTEST_PORT_NUMBER not defined" -#endif void EMSCRIPTEN_KEEPALIVE _ReportResult(int result) { - EM_ASM({ - reportResultToServer($0, $1); - }, result, EMTEST_PORT_NUMBER); + EM_ASM(reportResultToServer($0), result); } void EMSCRIPTEN_KEEPALIVE _MaybeReportResult(int result) { - EM_ASM({ - maybeReportResultToServer($0, $1); - }, result, EMTEST_PORT_NUMBER); + EM_ASM(maybeReportResultToServer($0), result); } #else diff --git a/test/test_browser.py b/test/test_browser.py index b5a6b97d93611..d905658c007fc 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -1608,7 +1608,7 @@ def test_hello_world_worker(self, file_data): - ''' % self.port) + ''' % self.PORT) cmd = [EMCC, test_file('hello_world_worker.c'), '-o', 'worker.js'] + self.get_emcc_args() if file_data: @@ -1671,7 +1671,7 @@ def test_chunked_synchronous_xhr(self): - """ % (worker_filename, self.port)) + """ % (worker_filename, self.PORT)) create_file('worker_prejs.js', r""" Module.arguments = ["/bigfile"]; @@ -1688,7 +1688,7 @@ def test_chunked_synchronous_xhr(self): data = os.urandom(10 * chunkSize + 1) # 10 full chunks and one 1 byte chunk checksum = zlib.adler32(data) & 0xffffffff # Python 2 compatibility: force bigint - server = multiprocessing.Process(target=test_chunked_synchronous_xhr_server, args=(True, chunkSize, data, checksum, self.port)) + server = multiprocessing.Process(target=test_chunked_synchronous_xhr_server, args=(True, chunkSize, data, checksum, self.PORT)) server.start() # block until the server is actually ready @@ -2422,7 +2422,7 @@ def test_runtime_misuse(self): doCwrapCall(200); doDirectCall(300); } - ''' % self.port + ''' % self.PORT create_file('pre_runtime.js', r''' Module.onRuntimeInitialized = myJSCallback; @@ -2569,7 +2569,7 @@ def test_html5_core(self, opts): window.disableErrorReporting = true; window.addEventListener('error', (event) => { if (!event.message.includes('exception:fullscreen error')) { - report_error(event); + reportTopLevelError(event); } }); ''')