Skip to content

Commit

Permalink
test: fix some times happening race condition 'Collection was modifie…
Browse files Browse the repository at this point in the history
…d; enumeration operation may not execute.'
  • Loading branch information
skwasjer committed Sep 2, 2023
1 parent a385205 commit 14fec9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/Hangfire.Correlate.Tests/HangfireIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ private async Task WaitUntilJobCompletedAsync(string jobId, int maxWaitInMillise
IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();

var sw = Stopwatch.StartNew();
JobDetailsDto? jobDetails = null;
StateHistoryDto[] jobHistory = Array.Empty<StateHistoryDto>();
while (
(jobDetails is null || jobDetails.History.All(s => s.StateName != "Succeeded"))
(jobHistory.All(s => s.StateName != "Succeeded"))
&& (sw.Elapsed.TotalMilliseconds < maxWaitInMilliseconds || Debugger.IsAttached))
{
await Task.Delay(25);
jobDetails = monitoringApi.JobDetails(jobId);
JobDetailsDto jobDetails = monitoringApi.JobDetails(jobId);
jobHistory = jobDetails.History.ToArray();
if (monitoringApi.FailedCount() > 0)
{
break;
Expand Down

0 comments on commit 14fec9c

Please sign in to comment.