Skip to content

Commit ab2eee6

Browse files
authored
Wasm make *.Run async (#345)
Make the Run in the threadless runner and WasmApplicationEntry point async so that it can yield back to js to resolve promises correctly. Depends on dotnet/runtime#44045, helps with dotnet/runtime#43958
1 parent 62a3c2f commit ab2eee6

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/Microsoft.DotNet.XHarness.TestRunners.Xunit/ThreadlessXunitTestRunner.cs

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Linq;
1010
using System.Reflection;
1111
using System.Threading;
12+
using System.Threading.Tasks;
1213
using System.Xml.Linq;
1314

1415
using Xunit;
@@ -18,7 +19,7 @@ namespace Microsoft.DotNet.XHarness.TestRunners.Xunit
1819
{
1920
internal class ThreadlessXunitTestRunner
2021
{
21-
public int Run(string assemblyFileName, bool printXml, XunitFilters filters)
22+
public async Task<int> Run(string assemblyFileName, bool printXml, XunitFilters filters)
2223
{
2324
var configuration = new TestAssemblyConfiguration() { ShadowCopy = false, ParallelizeAssembly = false, ParallelizeTestCollections = false, MaxParallelThreads = 1, PreEnumerateTheories = false };
2425
var discoveryOptions = TestFrameworkOptions.ForDiscovery(configuration);
@@ -57,20 +58,10 @@ public int Run(string assemblyFileName, bool printXml, XunitFilters filters)
5758
testSink.Execution.TestAssemblyFinishedEvent += args => { Console.WriteLine($"Finished: {assemblyFileName}"); };
5859

5960
controller.RunTests(testCasesToRun, resultsSink, testOptions);
60-
var threadpoolPump = typeof(ThreadPool).GetMethod("PumpThreadPool", BindingFlags.NonPublic | BindingFlags.Static);
61-
var timerPump = Type.GetType("System.Threading.TimerQueue")?.GetMethod("PumpTimerQueue", BindingFlags.NonPublic | BindingFlags.Static);
6261

63-
if (threadpoolPump != null && timerPump != null)
62+
while (!resultsSink.Finished.WaitOne(0))
6463
{
65-
while (!resultsSink.Finished.WaitOne(0))
66-
{
67-
threadpoolPump.Invoke(this, null);
68-
timerPump.Invoke(this, null);
69-
}
70-
}
71-
else
72-
{
73-
resultsSink.Finished.WaitOne();
64+
await Task.Delay(1);
7465
}
7566

7667
if (printXml)

src/Microsoft.DotNet.XHarness.TestRunners.Xunit/WasmApplicationEntryPoint.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using System.Collections.Generic;
9+
using System.Threading.Tasks;
910
using Xunit;
1011

1112
namespace Microsoft.DotNet.XHarness.TestRunners.Xunit
@@ -19,7 +20,7 @@ public abstract class WasmApplicationEntryPoint
1920
protected virtual IEnumerable<string> IncludedMethods { get; set; } = Array.Empty<string>();
2021
protected virtual IEnumerable<string> IncludedNamespaces { get; set; } = Array.Empty<string>();
2122

22-
public int Run()
23+
public async Task<int> Run()
2324
{
2425
var testRunner = new ThreadlessXunitTestRunner();
2526
var filters = new XunitFilters();
@@ -30,7 +31,7 @@ public int Run()
3031
foreach (var cl in IncludedClasses) filters.IncludedClasses.Add(cl);
3132
foreach (var me in IncludedMethods) filters.IncludedMethods.Add(me);
3233

33-
var result = testRunner.Run(TestAssembly, printXml: true, filters);
34+
var result = await testRunner.Run(TestAssembly, printXml: true, filters);
3435

3536
return result;
3637
}

0 commit comments

Comments
 (0)