Skip to content

Commit 116802d

Browse files
authored
Merge pull request #4804 from nunit/fix-value-task-awaiter
Use default blocking strategy for valuetasks
2 parents 5c0ae90 + 2b6b6e7 commit 116802d

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/NUnitFramework/framework/Internal/ValueTaskAwaitAdapter.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static AwaitAdapter Create(ValueTask task)
2727
return null;
2828
}
2929

30-
private sealed class NonGenericAdapter : AwaitAdapter
30+
private sealed class NonGenericAdapter : DefaultBlockingAwaitAdapter
3131
{
3232
private readonly ValueTaskAwaiter _awaiter;
3333

@@ -40,17 +40,14 @@ public NonGenericAdapter(ValueTask task)
4040

4141
public override void OnCompleted(Action action) => _awaiter.UnsafeOnCompleted(action);
4242

43-
// Assumption that GetResult blocks until complete is only valid for System.Threading.Tasks.ValueTask.
44-
public override void BlockUntilCompleted() => _awaiter.GetResult();
45-
4643
public override object? GetResult()
4744
{
4845
_awaiter.GetResult(); // Throws exceptions, if any
4946
return null;
5047
}
5148
}
5249

53-
private sealed class GenericAdapter<T> : AwaitAdapter
50+
private sealed class GenericAdapter<T> : DefaultBlockingAwaitAdapter
5451
{
5552
private readonly ValueTaskAwaiter<T> _awaiter;
5653

@@ -63,9 +60,6 @@ public GenericAdapter(ValueTask<T> task)
6360

6461
public override void OnCompleted(Action action) => _awaiter.UnsafeOnCompleted(action);
6562

66-
// Assumption that GetResult blocks until complete is only valid for System.Threading.Tasks.ValueTask.
67-
public override void BlockUntilCompleted() => _awaiter.GetResult();
68-
6963
public override object? GetResult()
7064
{
7165
return _awaiter.GetResult(); // Throws exceptions, if any

src/NUnitFramework/tests/Attributes/TestCaseSourceTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,21 @@ private static IEnumerable ExceptionSource
741741
}
742742
}
743743
#endregion
744+
745+
[TestCaseSource(nameof(AsyncEnumerableTestCases))]
746+
public async Task TestAsyncEnumerable(int expected, int actual)
747+
{
748+
await Task.Delay(100); // Simulate an asynchronous operation
749+
Assert.That(actual, Is.EqualTo(expected));
750+
}
751+
752+
private static async IAsyncEnumerable<TestCaseData> AsyncEnumerableTestCases()
753+
{
754+
await Task.Delay(100); // Simulate an asynchronous operation
755+
yield return new TestCaseData(42, 42);
756+
await Task.Delay(100); // Simulate another asynchronous operation
757+
yield return new TestCaseData(51, 51);
758+
}
744759
}
745760

746761
public class TestSourceMayBeInherited

0 commit comments

Comments
 (0)