Skip to content

Commit 53bfc5d

Browse files
committed
make a test compatible with runtime async.
1 parent 8b1621a commit 53bfc5d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/System.Runtime.CompilerServices/AsyncTaskMethodBuilderTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,12 @@ public void AsyncTaskMethodBuilder_Completed_RemovedFromTracking()
670670
t.Wait();
671671
}
672672

673-
int activeCount = ((dynamic)typeof(Task).GetField("s_currentActiveTasks", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null)).Count;
674-
Assert.InRange(activeCount, 0, 10); // some other tasks may be created by the runtime, so this is just using a reasonably small upper bound
673+
object activeTasks = typeof(Task).GetField("s_currentActiveTasks", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
674+
if (activeTasks is not null)
675+
{
676+
int activeCount = (dynamic)activeTasks.Count;
677+
Assert.InRange(activeCount, 0, 10); // some other tasks may be created by the runtime, so this is just using a reasonably small upper bound
678+
}
675679
}).Dispose();
676680
}
677681

0 commit comments

Comments
 (0)