Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to SystemClock removal #34

Merged
merged 4 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Foundatio.AzureStorage/Foundatio.AzureStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.3" />
<PackageReference Include="Microsoft.Azure.Storage.Queue" Version="11.2.3" />

<PackageReference Include="Foundatio" Version="10.7.1" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<PackageReference Include="Foundatio" Version="11.0.0" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<ProjectReference Include="..\..\..\Foundatio\src\Foundatio\Foundatio.csproj" Condition="'$(ReferenceFoundatioSource)' == 'true'" />
</ItemGroup>
</Project>
5 changes: 2 additions & 3 deletions src/Foundatio.AzureStorage/Queues/AzureStorageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Foundatio.AsyncEx;
using Foundatio.Extensions;
using Foundatio.Serializer;
using Foundatio.Utility;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Queue;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -74,7 +73,7 @@ protected override async Task<string> EnqueueImplAsync(T data, QueueEntryOptions
var message = new CloudQueueMessage(_serializer.SerializeToBytes(data));
await _queueReference.AddMessageAsync(message, null, options.DeliveryDelay, null, null).AnyContext();

var entry = new QueueEntry<T>(message.Id, null, data, this, SystemClock.UtcNow, 0);
var entry = new QueueEntry<T>(message.Id, null, data, this, _timeProvider.GetLocalNow().UtcDateTime, 0);
await OnEnqueuedAsync(entry).AnyContext();

return message.Id;
Expand All @@ -99,7 +98,7 @@ protected override async Task<IQueueEntry<T>> DequeueImplAsync(CancellationToken
try
{
if (!linkedCancellationToken.IsCancellationRequested)
await SystemClock.SleepAsync(_options.DequeueInterval, linkedCancellationToken).AnyContext();
await _timeProvider.Delay(_options.DequeueInterval, linkedCancellationToken).AnyContext();
}
catch (OperationCanceledException) { }

Expand Down
7 changes: 4 additions & 3 deletions src/Foundatio.AzureStorage/Storage/AzureFileStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -8,7 +8,6 @@
using Foundatio.Azure.Extensions;
using Foundatio.Extensions;
using Foundatio.Serializer;
using Foundatio.Utility;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Extensions.Logging;
Expand All @@ -21,12 +20,14 @@ public class AzureFileStorage : IFileStorage
private readonly CloudBlobContainer _container;
private readonly ISerializer _serializer;
protected readonly ILogger _logger;
protected readonly TimeProvider _timeProvider;

public AzureFileStorage(AzureFileStorageOptions options)
{
if (options == null)
throw new ArgumentNullException(nameof(options));

_timeProvider = options.TimeProvider ?? TimeProvider.System;
_serializer = options.Serializer ?? DefaultSerializer.Instance;
_logger = options.LoggerFactory?.CreateLogger(GetType()) ?? NullLogger.Instance;

Expand Down Expand Up @@ -170,7 +171,7 @@ public async Task<bool> CopyFileAsync(string path, string targetPath, Cancellati

await newBlob.StartCopyAsync(oldBlob, cancellationToken).AnyContext();
while (newBlob.CopyState.Status == CopyStatus.Pending)
await SystemClock.SleepAsync(50, cancellationToken).AnyContext();
await _timeProvider.Delay(TimeSpan.FromMilliseconds(50), cancellationToken).AnyContext();

return newBlob.CopyState.Status == CopyStatus.Success;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<NoWarn>$(NoWarn);CS1591;NU1701</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />

<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="All" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="All" />

<PackageReference Include="Foundatio.TestHarness" Version="10.7.1" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<PackageReference Include="Foundatio.TestHarness" Version="11.0.0" Condition="'$(ReferenceFoundatioSource)' == '' OR '$(ReferenceFoundatioSource)' == 'false'" />
<ProjectReference Include="..\..\..\Foundatio\src\Foundatio.TestHarness\Foundatio.TestHarness.csproj" Condition="'$(ReferenceFoundatioSource)' == 'true'" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\docker-compose.yml">
<Link>docker-compose.yml</Link>
</Content>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AzureStorageQueueTests : QueueTestBase

public AzureStorageQueueTests(ITestOutputHelper output) : base(output) { }

protected override IQueue<SimpleWorkItem> GetQueue(int retries = 1, TimeSpan? workItemTimeout = null, TimeSpan? retryDelay = null, int[] retryMultipliers = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true)
protected override IQueue<SimpleWorkItem> GetQueue(int retries = 1, TimeSpan? workItemTimeout = null, TimeSpan? retryDelay = null, int[] retryMultipliers = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true, TimeProvider timeProvider = null)
{
string connectionString = Configuration.GetConnectionString("AzureStorageConnectionString");
if (String.IsNullOrEmpty(connectionString))
Expand All @@ -31,6 +31,7 @@ protected override IQueue<SimpleWorkItem> GetQueue(int retries = 1, TimeSpan? wo
.RetryPolicy(retries <= 0 ? new NoRetry() : (IRetryPolicy)new ExponentialRetry(retryDelay.GetValueOrDefault(TimeSpan.FromMinutes(1)), retries))
.WorkItemTimeout(workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5)))
.DequeueInterval(TimeSpan.FromMilliseconds(100))
.TimeProvider(timeProvider)
.LoggerFactory(Log));
}

Expand Down