Skip to content

Commit

Permalink
[wasm-browser][tests] Fix issue with some tests exiting with no output (
Browse files Browse the repository at this point in the history
#300)

The problem here is that these tests run very quickly, writing to the
console.log very fast, and selenium seems to not return the logs during
that time. So, when the tests are done, which is indicated by an html
element being set, we stop listening for more log messages.
And exit with the test exit code, but no output messages from the test
run.

Eg: `System.Data.Common`
  • Loading branch information
radical committed Aug 24, 2020
1 parent 43e9aa0 commit 1ff8172
Showing 1 changed file with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ internal class WasmBrowserTestRunner
// Eg. `foo` becomes `http://localhost:8000/xyz.js 0:12 "foo"
static readonly Regex s_consoleLogRegex = new Regex(@"^\s*[a-z]*://[^\s]+\s+\d+:\d+\s+""(.*)""\s*$", RegexOptions.Compiled);

private bool _endResultXmlStringSeen = false;

public WasmBrowserTestRunner(WasmTestBrowserCommandArguments arguments, IEnumerable<string> passThroughArguments,
Action<string> processLogMessage, ILogger logger)
{
Expand Down Expand Up @@ -81,12 +83,19 @@ public async Task<ExitCode> RunTestsWithWebDriver(IWebDriver driver)
throw logPumpingTask.Exception!;
}

// WebDriverWait could return before we could get all
// the messages, so pump any remaining ones
PumpLogMessages(driver);

if (task == testsDoneTask && testsDoneTask.IsCompletedSuccessfully)
{
// WebDriverWait could return before we could get all
// the messages, so pump any remaining ones.
// This can also be a bit delayed, if the console is very
// frequently being written to, in the browser
int count = 0;
do
{
await Task.Delay(500);
PumpLogMessages(driver);
} while (count < 5 && !_endResultXmlStringSeen);

var elem = testsDoneTask.Result;
if (int.TryParse(elem.Text, out var code))
{
Expand All @@ -96,6 +105,17 @@ public async Task<ExitCode> RunTestsWithWebDriver(IWebDriver driver)
return ExitCode.RETURN_CODE_NOT_SET;
}

if (task.IsFaulted)
{
_logger.LogDebug(task.Exception!, "Waiting for tests failed");
throw task.Exception!;
}

// WebDriverWait could return before we could get all
// the messages, so pump any remaining ones.
await Task.Delay(1000);
PumpLogMessages(driver);

return ExitCode.TIMED_OUT;
}
finally
Expand Down Expand Up @@ -148,6 +168,14 @@ private void PumpLogMessages(IWebDriver driver)
msg += Environment.NewLine;

_processLogMessage(msg);

// the test runner writes this as the last line,
// after the tests have run, and the xml results file
// has been written to the console
if (msg.Contains("ENDRESULTXML"))
{
_endResultXmlStringSeen = true;
}
}
}

Expand Down

0 comments on commit 1ff8172

Please sign in to comment.