Skip to content

Commit c7bb477

Browse files
committed
Uses time provider for delays
Ensures delays use the configured time provider, allowing for easier testing and mocking of time-dependent operations. This change replaces direct calls to `Task.Delay` with the `TimeProvider` instance.
1 parent 3688492 commit c7bb477

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Foundatio.Repositories.Elasticsearch/Repositories/ElasticReindexer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
@@ -228,7 +228,7 @@ private async Task<ReindexResult> InternalReindexAsync(ReindexWorkItem workItem,
228228
if (status.Task.Status.Total < 100)
229229
timeToWait = TimeSpan.FromMilliseconds(100);
230230

231-
await Task.Delay(timeToWait, cancellationToken).AnyContext();
231+
await _timeProvider.Delay(timeToWait, cancellationToken).AnyContext();
232232
} while (!cancellationToken.IsCancellationRequested);
233233
sw.Stop();
234234

src/Foundatio.Repositories.Elasticsearch/Repositories/ElasticRepositoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ public virtual async Task<long> PatchAllAsync(IRepositoryQuery query, IPatchOper
792792

793793
_logger.LogDebug("Checking script operation task ({TaskId}) status: Created: {Created} Updated: {Updated} Deleted: {Deleted} Conflicts: {Conflicts} Total: {Total}", taskId, status.Created, status.Updated, status.Deleted, status.VersionConflicts, status.Total);
794794
var delay = TimeSpan.FromSeconds(attempts <= 5 ? 1 : 5);
795-
await Task.Delay(delay).AnyContext();
795+
await ElasticIndex.Configuration.TimeProvider.Delay(delay).AnyContext();
796796
} while (true);
797797
}
798798
else

0 commit comments

Comments
 (0)