Skip to content

Commit

Permalink
[browser] Run tests in parallel (dotnet#98492)
Browse files Browse the repository at this point in the history
Co-authored-by: Larry Ewing <lewing@microsoft.com>
Co-authored-by: Pavel Savara <pavel.savara@gmail.com>
  • Loading branch information
3 people authored and matouskozak committed Apr 30, 2024
1 parent b280b60 commit d1fd532
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions eng/testing/tests.browser.targets
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<WasmXHarnessMonoArgs Condition="'$(XunitShowProgress)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=XHARNESS_LOG_TEST_START=true</WasmXHarnessMonoArgs>
<!-- help unit test with PlatformDetection.IsThreadingSupported via IsBrowserThreadingSupported env variable -->
<WasmXHarnessMonoArgs Condition="'$(WasmEnableThreads)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=IsBrowserThreadingSupported=true</WasmXHarnessMonoArgs>
<WasmXHarnessMaxParallelThreads Condition="'$(WasmEnableThreads)' == 'true' and '$(WasmXHarnessMaxParallelThreads)' == ''">8</WasmXHarnessMaxParallelThreads>
</PropertyGroup>

<PropertyGroup Condition="'$(RunScriptCommand)' == ''">
Expand All @@ -112,6 +113,7 @@
<_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)</_XHarnessArgs>

<_AppArgs Condition="'$(WasmEnableThreads)' == 'true'">$(_AppArgs) -threads</_AppArgs>
<_AppArgs Condition="'$(WasmXHarnessMaxParallelThreads)' != ''">$(_AppArgs) -parallelThreads $(WasmXHarnessMaxParallelThreads)</_AppArgs>
<!-- There are two flavors of WasmXHarnessArgs and WasmXHarnessMonoArgs, one is MSBuild property and the other is environment variable -->
<RunScriptCommand Condition="'$(OS)' != 'Windows_NT'">$HARNESS_RUNNER $(_XHarnessArgs) %24XHARNESS_ARGS %24WasmXHarnessArgs -- $(WasmXHarnessMonoArgs) %24WasmXHarnessMonoArgs $(_AppArgs) %24WasmTestAppArgs</RunScriptCommand>
<RunScriptCommand Condition="'$(OS)' == 'Windows_NT'">%HARNESS_RUNNER% $(_XHarnessArgs) %XHARNESS_ARGS% %WasmXHarnessArgs% -- $(WasmXHarnessMonoArgs) %WasmXHarnessMonoArgs% $(_AppArgs) %WasmTestAppArgs%</RunScriptCommand>
Expand Down
20 changes: 15 additions & 5 deletions src/libraries/Common/tests/WasmTestRunner/WasmTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

public class WasmTestRunner : WasmApplicationEntryPoint
{
// TODO: Set max threads for run in parallel
// protected override int? MaxParallelThreads => RunInParallel ? 8 : base.MaxParallelThreads;
protected int MaxParallelThreadsFromArg { get; set; }
protected override int? MaxParallelThreads => RunInParallel ? MaxParallelThreadsFromArg : base.MaxParallelThreads;

public static async Task<int> Main(string[] args)
{
Expand Down Expand Up @@ -65,9 +65,11 @@ public static async Task<int> Main(string[] args)
break;
case "-threads":
runner.IsThreadless = false;
// TODO: Enable run in parallel
// runner.RunInParallel = true;
// Console.WriteLine($"Running in parallel with {runner.MaxParallelThreads} threads.");
break;
case "-parallelThreads":
runner.MaxParallelThreadsFromArg = Math.Max(1, int.Parse(args[i + 1]));
runner.RunInParallel = runner.MaxParallelThreadsFromArg > 1;
i++;
break;
case "-verbosity":
runner.MinimumLogLevel = Enum.Parse<MinimumLogLevel>(args[i + 1]);
Expand Down Expand Up @@ -105,4 +107,12 @@ public static async Task<int> Main(string[] args)

return res;
}

public override Task RunAsync()
{
if (RunInParallel)
Console.WriteLine($"Running in parallel with {MaxParallelThreads} threads.");

return base.RunAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<!-- This WASM test is problematic and slow right now. This sets the xharness timeout but there is also override in sendtohelix-browser.targets -->
<WasmXHarnessTestsTimeout>01:15:00</WasmXHarnessTestsTimeout>
<WasmXHarnessMaxParallelThreads>1</WasmXHarnessMaxParallelThreads>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<!-- to see timing and which test aborted the runtime -->
<XunitShowProgress>true</XunitShowProgress>
<WasmXHarnessMaxParallelThreads>1</WasmXHarnessMaxParallelThreads>
</PropertyGroup>
<!-- Make debugging easier -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetOS)' == 'browser'">
<WasmXHarnessMaxParallelThreads>1</WasmXHarnessMaxParallelThreads>
</PropertyGroup>
<ItemGroup>
<Compile Include="ArrayPool\ArrayPoolTest.cs" />
<Compile Include="ArrayPool\CollectionTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<XunitShowProgress>true</XunitShowProgress>
<!-- This WASM test is problematic and slow right now. This sets the xharness timeout but there is also override in sendtohelix-browser.targets -->
<WasmXHarnessTestsTimeout>01:15:00</WasmXHarnessTestsTimeout>
<WasmXHarnessMaxParallelThreads>1</WasmXHarnessMaxParallelThreads>
</PropertyGroup>
<ItemGroup Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<HighAotMemoryUsageAssembly Include="System.Text.Json.Tests.dll" />
Expand Down

0 comments on commit d1fd532

Please sign in to comment.