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
12 changes: 12 additions & 0 deletions tests/SquidStd.Tests/Services/Core/JobSystemServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public async Task ScheduleAsync_Action_RunsAndCompletes()
await system.ScheduleAsync(() => called = true);

Assert.True(called);
await WaitForCompletedAsync(system, 1);
Assert.Equal(1, system.CompletedCount);
}

Expand Down Expand Up @@ -60,6 +61,7 @@ public async Task ScheduleAsync_ManyJobs_AllComplete()
await Task.WhenAll(tasks);

Assert.Equal(5050, sum);
await WaitForCompletedAsync(system, 100);
Assert.Equal(100, system.CompletedCount);
}

Expand Down Expand Up @@ -173,4 +175,14 @@ private static JobSystemService NewService(int workerCount)
ShutdownTimeoutSeconds = 1.0
}
);

// CompletedCount is incremented by the worker after the scheduled task's completion fires, so
// awaiting ScheduleAsync does not guarantee the counter is updated yet. Wait for it (bounded).
private static async Task WaitForCompletedAsync(IJobSystem system, long expected)
{
for (var i = 0; i < 200 && system.CompletedCount < expected; i++)
{
await Task.Delay(10);
}
}
}