Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e302f0cd80 | ||
|
|
195f3e51af | ||
|
|
c27e8194d3 | ||
|
|
e9ac6dccc9 |
@@ -288,28 +288,13 @@ public sealed class SchedulerTests
|
|||||||
await Assert.ThrowsAsync<OperationCanceledException>(() => loop).ConfigureAwait(false);
|
await Assert.ThrowsAsync<OperationCanceledException>(() => loop).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
[TestCategory(Category.Unit)]
|
|
||||||
public async Task AStateSeenOnceIsEnoughForTheWait()
|
|
||||||
{
|
|
||||||
// A state that holds for an instant (CI run 586): the wait judges the reading it saw, it does not ask again.
|
|
||||||
var readings = 0;
|
|
||||||
await WaitUntil(() => Interlocked.Increment(ref readings) == 2).ConfigureAwait(false);
|
|
||||||
Assert.AreEqual(2, readings);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static async Task WaitUntil(Func<bool> condition)
|
internal static async Task WaitUntil(Func<bool> condition)
|
||||||
{
|
{
|
||||||
// One reading per round, and the reading seen is the one judged. Asking again for the assertion failed the test
|
for (var i = 0; i < 500 && !condition(); i++)
|
||||||
// when the state held only for an instant: the scheduler's first round registers a wait on the clock and drops it
|
|
||||||
// at once, because the job added before RunAsync has already signalled a change.
|
|
||||||
var met = condition();
|
|
||||||
for (var i = 0; i < 500 && !met; i++)
|
|
||||||
{
|
{
|
||||||
await Task.Delay(10).ConfigureAwait(false);
|
await Task.Delay(10).ConfigureAwait(false);
|
||||||
met = condition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.IsTrue(met, "condizione non raggiunta in tempo");
|
Assert.IsTrue(condition(), "condizione non raggiunta in tempo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user