From 36d850ff3079cc7690deb3bdfc4a9544d613e45b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 14 Nov 2026 13:50:55 -0600 Subject: inject TimeProvider to enable testing --- src/slskd/Transfers/Downloads/DownloadService.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') 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 OptionsMonitor { get; } private EventBus EventBus { get; } private Regex SubdirectoryPatternTokenRegex { get; } = new Regex(@"\$\{([^\{\}]*)\}", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private TimeProvider TimeProvider { get; } /// /// 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 -- cgit v1.2.3