Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions tests/Core/Utilities/DebounceActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,29 @@ public async Task Debounce_MultipleCalls_Async()
var actionNextCalled = string.Empty;

// Act: simulate two async calls
_ = Task.Run(async () =>
var t1 = Task.Run(async () =>
{
await debounce.RunAsync(50, async () =>
try
{
actionCalled = "Step1";
actionCalledCount++;
await Task.CompletedTask;
});

actionNextCalled = "Next1";
actionNextCount++;
await debounce.RunAsync(50, async () =>
{
actionCalled = "Step1";
actionCalledCount++;
await Task.CompletedTask;
});

actionNextCalled = "Next1";
actionNextCount++;
}
catch (OperationCanceledException)
{
// Task cancelled
}
});

await Task.Delay(5); // To ensure the second call is made after the first one
await Task.Delay(15); // Wait for the first task to start

_ = Task.Run(async () =>
var t2 = Task.Run(async () =>
{
await debounce.RunAsync(40, async () =>
{
Expand All @@ -114,7 +121,7 @@ await debounce.RunAsync(40, async () =>
actionNextCount++;
});

await Task.Delay(100); // Wait for the debounce to complete
await Task.WhenAll(t1, t2);

// Assert
Assert.Equal("Step2", actionCalled);
Expand Down