Skip to content

Commit

Permalink
Improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jul 18, 2024
1 parent ea26d13 commit 7daacb1
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions src/DotNext.Tests/Threading/AsyncEventHubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void WaitOne()
Equal(3, hub.Count);

True(hub.Pulse(0));
True(hub.WaitOneAsync(0).IsCompletedSuccessfully);
True(hub.WaitOneAsync(0, DefaultTimeout).IsCompletedSuccessfully);
False(hub.WaitOneAsync(1).IsCompleted);
}

Expand All @@ -30,8 +30,8 @@ public static async Task WaitAny()
hub.Pulse(indexes, flags);
True(flags[0]);

Equal(0, await hub.WaitAnyAsync());
Equal(0, await hub.WaitAnyAsync(new int[] { 0, 1 }));
Equal(0, await hub.WaitAnyAsync(DefaultTimeout));
Equal(0, await hub.WaitAnyAsync([0, 1]));
}

[Fact]
Expand All @@ -45,7 +45,30 @@ public static async Task WaitAny2()
True(flags[0]);

Equal(0, await hub.WaitAnyAsync());
Equal(0, await hub.WaitAnyAsync(new int[] { 0, 1 }));
Equal(0, await hub.WaitAnyAsync([0, 1], DefaultTimeout));
}

[Fact]
public static async Task WaitAny3()
{
var hub = new AsyncEventHub(3);

int[] indexes = { 0 };
Equal(1, hub.ResetAndPulse(indexes));

Equal(0, await hub.WaitAnyAsync());
Equal(0, await hub.WaitAnyAsync([0, 1], DefaultTimeout));
}

[Fact]
public static async Task WaitAny4()
{
var hub = new AsyncEventHub(3);

True(hub.ResetAndPulse(0));

Equal(0, await hub.WaitAnyAsync());
Equal(0, await hub.WaitAnyAsync([0, 1], DefaultTimeout));
}

[Fact]
Expand All @@ -55,7 +78,7 @@ public static async Task WaitAll()

Equal(3, hub.PulseAll());

await hub.WaitAllAsync(new int[] { 0, 1 });
await hub.WaitAllAsync([0, 1], DefaultTimeout);
await hub.WaitAllAsync();
}

Expand All @@ -70,8 +93,8 @@ public static async Task WaitAll2()
True(flags[1]);
True(flags[2]);

await hub.WaitAllAsync(new int[] { 0, 1 });
await hub.WaitAllAsync();
await hub.WaitAllAsync([0, 1]);
await hub.WaitAllAsync(DefaultTimeout);
}

[Fact]
Expand All @@ -88,4 +111,16 @@ public static void CaptureState()
hub.CaptureState(state);
Equal(1, state.IndexOf(true));
}

[Fact]
public static async Task CancelPendingTasks()
{
var hub = new AsyncEventHub(3);
var task1 = hub.WaitOneAsync(0);
var task2 = hub.WaitOneAsync(1);

hub.CancelSuspendedCallers(new(canceled: true));
await ThrowsAsync<TaskCanceledException>(Func.Constant(task1));
await ThrowsAsync<TaskCanceledException>(Func.Constant(task2));
}
}

0 comments on commit 7daacb1

Please sign in to comment.