Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][mt] Run all tests #97270

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ jobs:
# Always run for runtime-wasm because tests are not run in runtime
alwaysRun: ${{ parameters.isWasmOnlyBuild }}

# NOTE - Since threading is experimental, we don't want to block mainline work
shouldContinueOnError: true
scenarios:
- WasmTestOnBrowser
#- WasmTestOnNodeJS - this is not supported yet, https://github.com/dotnet/runtime/issues/85592
Expand Down
21 changes: 18 additions & 3 deletions src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static async Task<int> Main(string[] args)
var includedClasses = new List<string>();
var includedMethods = new List<string>();
var backgroundExec = false;
var untilFailed = false;

for (int i = 1; i < args.Length; i++)
{
Expand Down Expand Up @@ -53,6 +54,9 @@ public static async Task<int> Main(string[] args)
case "-backgroundExec":
backgroundExec = true;
break;
case "-untilFailed":
untilFailed = true;
break;
default:
throw new ArgumentException($"Invalid argument '{option}'.");
}
Expand All @@ -72,10 +76,21 @@ public static async Task<int> Main(string[] args)
{
await Task.Yield();
}
if (backgroundExec)

var res = 0;
do
{
return await Task.Run(() => runner.Run());
if (backgroundExec)
{
res = await Task.Run(() => runner.Run());
}
else
{
res = await runner.Run();
}
}
return await runner.Run();
while(res == 0 && untilFailed);

return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,43 @@ protected string GetMessage(List<ConsoleContext> contexts)
return string.Join("", contexts.Select(c => c.Message));
}

internal static (ConsoleLogger Logger, ConsoleSink Sink, ConsoleSink ErrorSink, Func<LogLevel, string> GetLevelPrefix, int WritesPerMsg) SetUp(
internal class SetupDisposeHelper : IDisposable
{
public ConsoleLogger Logger;
public ConsoleSink Sink;
public ConsoleSink ErrorSink;
public Func<LogLevel, string> GetLevelPrefix;
public int WritesPerMsg;
public TestLoggerProcessor LoggerProcessor;
public SetupDisposeHelper(ConsoleLogger logger, ConsoleSink sink, ConsoleSink errorSink, Func<LogLevel, string> getLevelPrefix, int writesPerMsg, TestLoggerProcessor loggerProcessor)
{
Logger = logger;
Sink = sink;
ErrorSink = errorSink;
GetLevelPrefix = getLevelPrefix;
WritesPerMsg = writesPerMsg;
LoggerProcessor = loggerProcessor;
}

private bool _isDisposed;

protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
{
LoggerProcessor.Dispose();
_isDisposed = true;
}
}

public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}

internal static SetupDisposeHelper SetUp(
ConsoleLoggerOptions options = null,
SimpleConsoleFormatterOptions simpleOptions = null,
ConsoleFormatterOptions systemdOptions = null,
Expand Down Expand Up @@ -70,16 +106,15 @@ internal static (ConsoleLogger Logger, ConsoleSink Sink, ConsoleSink ErrorSink,
}
var logger = new ConsoleLogger(_loggerName, consoleLoggerProcessor, formatter, new LoggerExternalScopeProvider(), loggerOptions);

return (logger, sink, errorSink, levelAsString, writesPerMsg);
return new SetupDisposeHelper(logger, sink, errorSink, levelAsString, writesPerMsg, consoleLoggerProcessor);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
public void ConsoleLoggerOptions_TimeStampFormat_IsReloaded()
{
// Arrange
var monitor = new TestOptionsMonitor(new ConsoleLoggerOptions() { FormatterName = "NonExistentFormatter" });
var loggerProvider = new ConsoleLoggerProvider(monitor, ConsoleLoggerTest.GetFormatters());
using var loggerProvider = new ConsoleLoggerProvider(monitor, ConsoleLoggerTest.GetFormatters());
var logger = (ConsoleLogger)loggerProvider.CreateLogger("Name");

// Act & Assert
Expand All @@ -88,12 +123,11 @@ public void ConsoleLoggerOptions_TimeStampFormat_IsReloaded()
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
[MemberData(nameof(FormatterNames))]
public void InvalidLogLevel_Throws(string formatterName)
{
// Arrange
var t = SetUp(
using var t = SetUp(
new ConsoleLoggerOptions { FormatterName = formatterName }
);
var logger = (ILogger)t.Logger;
Expand All @@ -103,12 +137,11 @@ public void InvalidLogLevel_Throws(string formatterName)
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
[MemberData(nameof(FormatterNamesAndLevels))]
public void NoMessageOrException_Noop(string formatterName, LogLevel level)
{
// Arrange
var t = SetUp(new ConsoleLoggerOptions { FormatterName = formatterName });
using var t = SetUp(new ConsoleLoggerOptions { FormatterName = formatterName });
var levelPrefix = t.GetLevelPrefix(level);
var logger = t.Logger;
var sink = t.Sink;
Expand All @@ -123,12 +156,11 @@ public void NoMessageOrException_Noop(string formatterName, LogLevel level)
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/91538", typeof(PlatformDetection), nameof(PlatformDetection.IsWasmThreadingSupported))]
[MemberData(nameof(FormatterNamesAndLevels))]
public void Log_LogsCorrectTimestamp(string formatterName, LogLevel level)
{
// Arrange
var t = SetUp(
using var t = SetUp(
new ConsoleLoggerOptions { FormatterName = formatterName },
new SimpleConsoleFormatterOptions { TimestampFormat = "yyyy-MM-ddTHH:mm:sszz ", UseUtcTimestamp = false, ColorBehavior = LoggerColorBehavior.Enabled },
new ConsoleFormatterOptions { TimestampFormat = "yyyy-MM-ddTHH:mm:sszz ", UseUtcTimestamp = false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void LogAfterDisposeWritesLog()
// Arrange
var sink = new ConsoleSink();
var console = new TestConsole(sink);
var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);
using var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);

var logger = new ConsoleLogger(_loggerName, loggerProcessor: processor,
new SimpleConsoleFormatter(new TestFormatterOptionsMonitor<SimpleConsoleFormatterOptions>(new SimpleConsoleFormatterOptions())),
Expand All @@ -42,7 +42,7 @@ public void LogsFlushedAfterDispose()
// Arrange
var sink = new ConsoleSink();
var console = new TestConsole(sink);
var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);
using var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);

var logger = new ConsoleLogger(_loggerName, loggerProcessor: processor,
new SimpleConsoleFormatter(new TestFormatterOptionsMonitor<SimpleConsoleFormatterOptions>(new SimpleConsoleFormatterOptions())),
Expand Down Expand Up @@ -70,7 +70,7 @@ public static void MaxQueueLength_SetInvalid_Throws(int invalidMaxQueueLength)
// Arrange
var sink = new ConsoleSink();
var console = new TestConsole(sink);
var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);
using var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);

// Act & Assert
Assert.Throws<ArgumentOutOfRangeException>(() => processor.MaxQueueLength = invalidMaxQueueLength);
Expand All @@ -82,7 +82,7 @@ public static void FullMode_SetInvalid_Throws()
// Arrange
var sink = new ConsoleSink();
var console = new TestConsole(sink);
var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);
using var processor = new ConsoleLoggerProcessor(console, null!, ConsoleLoggerQueueFullMode.Wait, 1024);

// Act & Assert
Assert.Throws<ArgumentOutOfRangeException>(() => processor.FullMode = (ConsoleLoggerQueueFullMode)10);
Expand All @@ -100,7 +100,7 @@ public void CheckForNotificationWhenQueueIsFull(bool okToDrop)
var errorConsole = new TimesWriteCalledConsole();
string queueName = nameof(CheckForNotificationWhenQueueIsFull) + (okToDrop ? "InDropWriteMode" : "InWaitMode");
var fullMode = okToDrop ? ConsoleLoggerQueueFullMode.DropWrite : ConsoleLoggerQueueFullMode.Wait;
var processor = new ConsoleLoggerProcessor(console, errorConsole, fullMode, maxQueueLength: 1);
using var processor = new ConsoleLoggerProcessor(console, errorConsole, fullMode, maxQueueLength: 1);
var formatter = new SimpleConsoleFormatter(new TestFormatterOptionsMonitor<SimpleConsoleFormatterOptions>(
new SimpleConsoleFormatterOptions()));

Expand Down Expand Up @@ -150,7 +150,7 @@ public void ThrowDuringProcessLog_ShutsDownGracefully()
{
var console = new TimesWriteCalledConsole();
var writeThrowingConsole = new WriteThrowingConsole();
var processor = new ConsoleLoggerProcessor(
using var processor = new ConsoleLoggerProcessor(
console,
writeThrowingConsole,
ConsoleLoggerQueueFullMode.Wait,
Expand Down
Loading
Loading