aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Transfers/Downloads/DownloadService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-11-14 13:50:55 -0600
committerJP Dillingham <jp@dillingham.me>2026-11-14 13:50:55 -0600
commit36d850ff3079cc7690deb3bdfc4a9544d613e45b (patch)
tree92abc649fcb5a03d30b43bb8d7730316da4179b5 /src/slskd/Transfers/Downloads/DownloadService.cs
parent52a411477d89aa8bc128383725b9846d8fb6d791 (diff)
downloadslskd-36d850ff3079cc7690deb3bdfc4a9544d613e45b.tar.gz
inject TimeProvider to enable testing
Diffstat (limited to 'src/slskd/Transfers/Downloads/DownloadService.cs')
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index d4b07878..56b5f111 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -195,7 +195,8 @@ namespace slskd.Transfers.Downloads
FileService fileService,
IRelayService relayService,
IFTPService ftpClient,
- EventBus eventBus)
+ EventBus eventBus,
+ TimeProvider timeProvider)
{
Batches = batchService;
Searches = searchService;
@@ -207,6 +208,8 @@ namespace slskd.Transfers.Downloads
Relay = relayService;
EventBus = eventBus;
+ TimeProvider = timeProvider ?? TimeProvider.System;
+
Clock.EveryMinute += (_, _) => Task.Run(() => CleanupEnqueueSemaphoresAsync());
Clock.EveryFiveSeconds += (_, _) => Task.Run(() => EmitMetrics());
}
@@ -245,6 +248,7 @@ namespace slskd.Transfers.Downloads
private IOptionsMonitor<Options> OptionsMonitor { get; }
private EventBus EventBus { get; }
private Regex SubdirectoryPatternTokenRegex { get; } = new Regex(@"\$\{([^\{\}]*)\}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
+ private TimeProvider TimeProvider { get; }
/// <summary>
/// Allow only one enqueue operation for a given user at a time. Entries are added on the fly if they
@@ -546,7 +550,7 @@ namespace slskd.Transfers.Downloads
TransferStates state = TransferStates.None;
// satisfies condition #4; remote user doesn't respond after a really long time
- using var timeoutCts = new CancellationTokenSource(maxTimeToWaitForEnqueueRequestAck);
+ using var timeoutCts = new CancellationTokenSource(delay: maxTimeToWaitForEnqueueRequestAck, timeProvider: TimeProvider);
timeoutCts.Token.Register(() =>
{
// note: disposed once we leave the try block, so registration doesn't fire unless it actually times out