From c03a89ffb6bc9cffbe8ffb8cf77b67093b43cd85 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Tue, 23 Nov 2021 11:43:10 +0100 Subject: [PATCH] [wasm] workaround test results corruption (#61841) * xharness bump * more logging in unit test --- .config/dotnet-tools.json | 2 +- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 4 ++-- src/mono/wasm/test-main.js | 40 +++++++++++++++++++++++--------------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 3ab3433285362..18f4e3da0e9c3 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,7 +15,7 @@ ] }, "microsoft.dotnet.xharness.cli": { - "version": "1.0.0-prerelease.21561.1", + "version": "1.0.0-prerelease.21572.4", "commands": [ "xharness" ] diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 9365e67fda4b5..e0ab2225feecc 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -202,13 +202,13 @@ https://github.com/dotnet/linker f2dd65f51f6096f25e00e0d1e4c6af0e85d41865 - + https://github.com/dotnet/xharness - 42da0d206c22393c081abc4b6a48a181e17bb372 + 7aa4d338b58a2b21974933802bd731a64c36c1d8 - + https://github.com/dotnet/xharness - 42da0d206c22393c081abc4b6a48a181e17bb372 + 7aa4d338b58a2b21974933802bd731a64c36c1d8 https://github.com/dotnet/arcade diff --git a/eng/Versions.props b/eng/Versions.props index 4fbee001c46cc..74ab5f99c3ce7 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -154,8 +154,8 @@ 1.0.1-prerelease-00006 16.9.0-preview-20201201-01 - 1.0.0-prerelease.21561.1 - 1.0.0-prerelease.21561.1 + 1.0.0-prerelease.21572.4 + 1.0.0-prerelease.21572.4 1.0.2-alpha.0.21558.2 2.4.2-pre.9 2.4.2 diff --git a/src/mono/wasm/test-main.js b/src/mono/wasm/test-main.js index cf7b7e39f349f..8ef7f699b10ea 100644 --- a/src/mono/wasm/test-main.js +++ b/src/mono/wasm/test-main.js @@ -23,6 +23,7 @@ const originalConsole = { }; let isXUnitDoneCheck = false; +let isXmlDoneCheck = false; function proxyMethod(prefix, func, asJson) { return function () { @@ -42,7 +43,12 @@ function proxyMethod(prefix, func, asJson) { isXUnitDoneCheck = true; } - if (asJson) { + if (payload.startsWith("STARTRESULTXML")) { + originalConsole.log('Sending RESULTXML') + isXmlDoneCheck = true; + func(payload); + } + else if (asJson) { func(JSON.stringify({ method: prefix, payload: payload, @@ -66,10 +72,12 @@ function proxyJson(func) { console[m] = proxyMethod(`console.${m}`, func, true); } +let consoleWebSocket; + if (is_browser) { const consoleUrl = `${window.location.origin}/console`.replace('http://', 'ws://'); - let consoleWebSocket = new WebSocket(consoleUrl); + consoleWebSocket = new WebSocket(consoleUrl); // redirect output so that when emscripten starts it's already redirected proxyJson(function (msg) { if (consoleWebSocket.readyState === WebSocket.OPEN) { @@ -238,7 +246,7 @@ function set_exit_code(exit_code, reason) { } if (is_browser) { const stack = (new Error()).stack.replace(/\n/g, "").replace(/[ ]*at/g, " at").replace(/https?:\/\/[0-9.:]*/g, "").replace("Error", ""); - const messsage = `Exit called with ${exit_code} when isXUnitDoneCheck=${isXUnitDoneCheck} ${stack}.`; + const messsage = `Exit called with ${exit_code} when isXUnitDoneCheck=${isXUnitDoneCheck} isXmlDoneCheck=${isXmlDoneCheck} WS.bufferedAmount=${consoleWebSocket.bufferedAmount} ${stack}.`; // Notify the selenium script Module.exit_code = exit_code; @@ -249,20 +257,20 @@ function set_exit_code(exit_code, reason) { tests_done_elem.innerHTML = exit_code.toString(); document.body.appendChild(tests_done_elem); - // need to flush streams (stdout/stderr) - for (const stream of Module.FS.streams) { - if (stream && stream.stream_ops && stream.stream_ops.flush) { - stream.stream_ops.flush(stream); + console.log('WS: ' + messsage); + originalConsole.log('CDP: ' + messsage); + const stop_when_ws_buffer_empty = () => { + if (consoleWebSocket.bufferedAmount == 0) { + // tell xharness WasmTestMessagesProcessor we are done. + // note this sends last few bytes into the same WS + console.log("WASM EXIT " + exit_code); } - } - console.log("Flushed stdout!"); - - console.log('1 ' + messsage); - setTimeout(() => { - originalConsole.log('2 ' + messsage); - // tell xharness WasmTestMessagesProcessor we are done. - console.log("WASM EXIT " + exit_code); - }, 100); + else { + setTimeout(stop_when_ws_buffer_empty, 100); + } + }; + stop_when_ws_buffer_empty(); + } else if (INTERNAL) { INTERNAL.mono_wasm_exit(exit_code); }