[wasm] Wasm.Build.Tests - fixes for tests failing on CI (#70704)
authorAnkit Jain <radical@gmail.com>
Thu, 30 Jun 2022 10:13:41 +0000 (06:13 -0400)
committerGitHub <noreply@github.com>
Thu, 30 Jun 2022 10:13:41 +0000 (06:13 -0400)
commitce6d3dffe7570b39d98c43f988a58f6bcfd2b0bb
tree86d959e917c9a80f5ed42b67cfd93c41bde7fae6
parent9e703be988f0277f3a63432bc91ac5344f46cd03
[wasm] Wasm.Build.Tests - fixes for tests failing on CI (#70704)

* [wasm][nodejs] Ensure that stdout/stderr have been flushed out before exiting

When the results xml is large, and we are writing the base64
representation in one line, `node` can exit before all the output gets
flushed out. This results in xharness getting an incomplete
`STARTRESULTXML <len> <base64> ... ` with missing `ENDRESULTXML`, thus
no `testResults.xml` is generated.

This can be seen in the case of `Microsoft.Extensions.Primitives.Tests`
which has xml ~140KB, and `System.Memory.Tests` which has a xml ~13MB.

So, wait for the two streams to be flushed out, with a timeout of 3secs.

* [wasm] Wasm.Build.Tests: improve reading output from processes

- Fix to call `WaitForExit()` once `WaitForExit(int)` returns, which
  ensures that all the async handlers have been run.

- Also, for non-browser xharness runs use the emitted `wasm-console.log`
  as the output, so we don't depend on xharness' stdout.

* Wasm.Build.Tests: Run the crypto test only with browser. Other cases are covered in library tests

* Enable WasmTemplateTests.ConsolePublishAndRun

Fixes https://github.com/dotnet/runtime/issues/70675

* Wasm.Build.Tests: avoid unncessary copy when building locally

Copy sdk for testing workloads only on CI.

* Address feedback from @kg

* Remove timeout on flushing stdout/stderr streams, for console templates, IOW, user apps
src/mono/wasm/templates/templates/console/app-support.mjs
src/mono/wasm/test-main.js
src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
src/tests/BuildWasmApps/Wasm.Build.Tests/NativeLibraryTests.cs
src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs
src/tests/BuildWasmApps/Wasm.Build.Tests/data/RunScriptTemplate.cmd
src/tests/BuildWasmApps/Wasm.Build.Tests/data/RunScriptTemplate.sh