diff --git a/src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs b/src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs index 46a942a0f9cde1..0dfd8efb63eebc 100644 --- a/src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs +++ b/src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Microsoft.DotNet.XHarness.TestRunners.Xunit; @@ -58,6 +59,23 @@ public static async Task Main(string[] args) IncludedMethods = includedMethods }; - return await runner.Run(); + int result = await runner.Run(); + + // if the execution doesn't finish on the main thread, the test runner + // doesn't exit correctly and the test time outs + await SwitchToMainThreadAsync(); + + return result; + } + + private static async Task SwitchToMainThreadAsync() + { + // TODO: is there a better way to do this? this works but it feels very hacky... + // it would be best to ensure switching threads in the mono driver so that it works for _all_ + // WASM programs running on Mono + while (Thread.CurrentThread.IsBackground) + { + await Task.Delay(1); + } } } diff --git a/src/mono/wasm/runtime/debug.ts b/src/mono/wasm/runtime/debug.ts index 40ab3a4201743b..006610befbcaa5 100644 --- a/src/mono/wasm/runtime/debug.ts +++ b/src/mono/wasm/runtime/debug.ts @@ -480,6 +480,9 @@ export function mono_wasm_trace_logger(log_domain_ptr: CharPtr, log_level_ptr: C } export function setup_proxy_console(id: string, originalConsole: Console, origin: string): void { + const originalConsoleLog = originalConsole.log; + const originalConsoleError = originalConsole.error; + function proxyConsoleMethod(prefix: string, func: any, asJson: boolean) { return function (...args: any[]) { try { @@ -525,21 +528,20 @@ export function setup_proxy_console(id: string, originalConsole: Console, origin const consoleWebSocket = new WebSocket(consoleUrl); consoleWebSocket.onopen = function () { - originalConsole.log(`browser: [${id}] Console websocket connected.`); + originalConsoleLog(`browser: [${id}] Console websocket connected.`); }; consoleWebSocket.onerror = function (event) { - originalConsole.error(`[${id}] websocket error: ${event}`, event); + originalConsoleError(`[${id}] websocket error: ${event}`, event); }; consoleWebSocket.onclose = function (event) { - originalConsole.error(`[${id}] websocket closed: ${event}`, event); + originalConsoleError(`[${id}] websocket closed: ${event}`, event); }; const send = (msg: string) => { if (consoleWebSocket.readyState === WebSocket.OPEN) { consoleWebSocket.send(msg); - } - else { - originalConsole.log(msg); + } else { + originalConsoleLog(msg); } }; diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 994f849f171cf7..25424a6127085a 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -126,8 +126,7 @@ <_EmccCommonFlags Condition="'$(WasmEnableSIMD)' == 'true'" Include="-msimd128" /> <_EmccCommonFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s USE_PTHREADS=1" /> <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" /> - <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=4" /> - <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=2" /> + <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=32" />