Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix Unit Test
  • Loading branch information
dvoituron committed Sep 18, 2024
commit 4d77faf4c05206ec0f0c0484015b2455940cff83
31 changes: 19 additions & 12 deletions tests/Core/Utilities/DebounceTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,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(20); // 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 @@ -112,7 +119,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