From 6a124ba518f6885ed91c0ff6dcb911284187033c Mon Sep 17 00:00:00 2001 From: Alexander Salamatov Date: Mon, 24 May 2021 15:38:01 +0300 Subject: [PATCH] update to net 5 --- .github/release-drafter.yml | 16 ++++ .github/workflows/main.yml | 91 +++++++++++++------ .github/workflows/release-drafter.yml | 14 +++ RedisLock.sln | 3 + RedisLock.sln.DotSettings | 2 - RedisLock.sln.DotSettings.user | 37 -------- samples/WorkerService/Program.cs | 2 +- samples/WorkerService/Worker.cs | 6 +- samples/WorkerService/WorkerService.csproj | 6 +- .../appsettings.Development.json | 9 -- src/Directory.Packages.props | 20 ++++ .../DistributedLockException.cs | 8 -- .../ch1seL.DistributedLock.Abstraction.csproj | 12 --- .../MemoryLock.cs | 8 +- .../MemoryLockServiceCollectionExtensions.cs | 3 +- .../ch1seL.DistributedLock.MemoryLock.csproj | 17 +--- .../StackExchangeRedis/RedisLock.cs | 13 +-- .../StackExchangeRedis/RedisLockOptions.cs | 2 + .../ch1seL.DistributedLock.RedisLock.csproj | 11 --- .../Base/IntervalsWithLockTestsBase.cs | 10 +- .../MemoryLockTests/MemoryLeakTests.cs | 4 +- .../ch1seL.DistributedLock.Tests.csproj | 9 +- 22 files changed, 151 insertions(+), 152 deletions(-) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yml delete mode 100644 RedisLock.sln.DotSettings delete mode 100644 RedisLock.sln.DotSettings.user delete mode 100644 samples/WorkerService/appsettings.Development.json create mode 100644 src/Directory.Packages.props diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..5778a3d --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,16 @@ +name-template: 'v$NEXT_PATCH_VERSION' +tag-template: 'v$NEXT_PATCH_VERSION' +template: | + # What's Changed + + $CHANGES +categories: + - title: '🚀 Features' + label: 'Feature' + - title: '🐛 Bug Fixes' + label: 'Bug' + - title: '🧰 Maintenance' + label: 'Maintenance' + - title: '📖 Documentation' + label: 'Docs' +change-template: '- (#$NUMBER) $TITLE - Thanks to @$AUTHOR ' \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 78fb988..dd074ea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,22 +1,39 @@ -name: Build and Test +name: Main workflow on: - push: - branches: [ master ] pull_request: + push: branches: [ master ] + release: + types: [ published ] + +env: + DOTNET_SDK_VERSION: 5.0.x + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + GITHUB_FEED: https://nuget.pkg.github.com/ch1seL/ + GITHUB_USER: ch1seL + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUGET_FEED: https://api.nuget.org/v3/index.json + NUGET_KEY: ${{ secrets.NUGET_API_KEY }} jobs: build: + name: Build and test + if: github.event_name != 'release' runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - - name: Setup .NET Core + - name: Setup dotnet SDK 3.1 uses: actions/setup-dotnet@v1 with: dotnet-version: 3.1.x + + - name: Setup dotnet SDK ${{ env.DOTNET_SDK_VERSION }} + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_SDK_VERSION }} - name: Restore run: dotnet restore @@ -24,29 +41,47 @@ jobs: - name: Build run: dotnet build --configuration Release --no-restore - - name: Setup Redis Server - uses: supercharge/redis-github-action@1.1.0 + - name: Run redis + run: | + docker run -d -p 6379:6379 redis + wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh + chmod +x wait-for-it.sh + ./wait-for-it.sh -s -t 120 localhost:6379 - name: Test run: dotnet test --configuration Release --no-restore --no-build --verbosity normal - - - name: Publish NuGet ch1seL.DistributedLock.Abstraction - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: src/ch1seL.DistributedLock.Abstraction/ch1seL.DistributedLock.Abstraction.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} - VERSION_REGEX: ^\s*(.*)<\/PackageVersion>\s*$ - - - name: Publish NuGet ch1seL.DistributedLock.RedisLock - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: src/ch1seL.DistributedLock.RedisLock/ch1seL.DistributedLock.RedisLock.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} - VERSION_REGEX: ^\s*(.*)<\/PackageVersion>\s*$ - - - name: Publish NuGet ch1seL.DistributedLock.MemoryLock - uses: brandedoutcast/publish-nuget@v2.5.5 - with: - PROJECT_FILE_PATH: src/ch1seL.DistributedLock.MemoryLock/ch1seL.DistributedLock.MemoryLock.csproj - NUGET_KEY: ${{secrets.NUGET_API_KEY}} - VERSION_REGEX: ^\s*(.*)<\/PackageVersion>\s*$ \ No newline at end of file + + publish: + name: Publish NuGet + needs: build + if: github.event_name == 'release' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_SDK_VERSION }} + - name: Create Release NuGet package + run: | + arrTag=(${GITHUB_REF//\// }) + VERSION="${arrTag[2]}" + echo Version: $VERSION + VERSION="${VERSION//v}" + echo Clean Version: $VERSION + dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg + - name: Push to GitHub Feed + working-directory: nupkg + run: | + for f in *.nupkg + do + curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED + done + - name: Push to NuGet Feed + working-directory: nupkg + run: | + for f in *.nupkg + do + echo $f + dotnet nuget push $f --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY + done \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..3fb8ef3 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,14 @@ +name: Release Drafter + +on: + push: + branches: + - master + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/RedisLock.sln b/RedisLock.sln index 77a8356..465a1fa 100644 --- a/RedisLock.sln +++ b/RedisLock.sln @@ -1,6 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AA3FA77D-B187-41A1-95A9-8BC93CCF79D8}" +ProjectSection(SolutionItems) = preProject + src\Directory.Packages.props = src\Directory.Packages.props +EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ch1seL.DistributedLock.Abstraction", "src\ch1seL.DistributedLock.Abstraction\ch1seL.DistributedLock.Abstraction.csproj", "{503205F0-5FC4-4077-B1BF-C31FE5F73AF4}" EndProject diff --git a/RedisLock.sln.DotSettings b/RedisLock.sln.DotSettings deleted file mode 100644 index a65e714..0000000 --- a/RedisLock.sln.DotSettings +++ /dev/null @@ -1,2 +0,0 @@ - - True \ No newline at end of file diff --git a/RedisLock.sln.DotSettings.user b/RedisLock.sln.DotSettings.user deleted file mode 100644 index c274a60..0000000 --- a/RedisLock.sln.DotSettings.user +++ /dev/null @@ -1,37 +0,0 @@ - - <AssemblyExplorer> - <Assembly Path="C:\Users\ch1seL\.nuget\packages\microsoft.extensions.caching.abstractions\3.1.9\lib\netcoreapp3.1\Microsoft.Extensions.Caching.Abstractions.dll" /> - <Assembly Path="C:\Users\ch1seL\.nuget\packages\microsoft.extensions.caching.stackexchangeredis\3.1.9\lib\netstandard2.0\Microsoft.Extensions.Caching.StackExchangeRedis.dll" /> -</AssemblyExplorer> - <SessionState ContinuousTestingMode="0" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Project Location="C:\Users\ch1seL\repos\ch1seL\RedisLock\tests\ch1seL.DistributedLock.Tests" Presentation="&lt;tests&gt;\&lt;ch1seL.DistributedLock.Tests&gt;" /> -</SessionState> - <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;tests&gt;\&lt;ch1seL.DistributedLock.RedisLock.IntegrationTests&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Project Location="C:\Users\ch1seL\repos\ch1seL\RedisLock" Presentation="&lt;tests&gt;" /> -</SessionState> - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/WorkerService/Program.cs b/samples/WorkerService/Program.cs index b3e3529..57c61f8 100644 --- a/samples/WorkerService/Program.cs +++ b/samples/WorkerService/Program.cs @@ -4,7 +4,7 @@ namespace WorkerService { - public class Program + public static class Program { public static readonly Guid AppId = Guid.NewGuid(); diff --git a/samples/WorkerService/Worker.cs b/samples/WorkerService/Worker.cs index 9d3717c..e166b7f 100644 --- a/samples/WorkerService/Worker.cs +++ b/samples/WorkerService/Worker.cs @@ -12,7 +12,7 @@ public class Worker : BackgroundService private readonly IDistributedLock _distributedLock; private readonly Guid _instanceId = Guid.NewGuid(); private readonly ILogger _logger; - private readonly Random _random = new Random(); + private readonly Random _random = new(); public Worker(ILogger logger, IDistributedLock distributedLock) { @@ -27,9 +27,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) using (await _distributedLock.CreateLockAsync("test-lock", waitTime: TimeSpan.FromMinutes(5), retryTime: TimeSpan.FromMilliseconds(10), cancellationToken: stoppingToken)) { - _logger.LogInformation("App:{appId} | Instance: {instanceId} | Worker running at: {time}", Program.AppId, _instanceId, DateTimeOffset.Now); + _logger.LogInformation("App:{AppId} | Instance: {InstanceId} | Worker running at: {Time}", Program.AppId, _instanceId, DateTimeOffset.Now); await Task.Delay(TimeSpan.FromSeconds(3), stoppingToken); - _logger.LogInformation("App:{appId} | Instance: {instanceId} | Worker finished at: {time}", Program.AppId, _instanceId, DateTimeOffset.Now); + _logger.LogInformation("App:{AppId} | Instance: {InstanceId} | Worker finished at: {Time}", Program.AppId, _instanceId, DateTimeOffset.Now); } // RedLock uses retries and will use mostly only one instance of the worker diff --git a/samples/WorkerService/WorkerService.csproj b/samples/WorkerService/WorkerService.csproj index 0f2413f..98c4f65 100644 --- a/samples/WorkerService/WorkerService.csproj +++ b/samples/WorkerService/WorkerService.csproj @@ -1,12 +1,12 @@ - netcoreapp3.1 - dotnet-WorkerService-56DC58EC-8910-4947-A202-60D027333D3A + net5.0 + false - + diff --git a/samples/WorkerService/appsettings.Development.json b/samples/WorkerService/appsettings.Development.json deleted file mode 100644 index 8983e0f..0000000 --- a/samples/WorkerService/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props new file mode 100644 index 0000000..68e3d1d --- /dev/null +++ b/src/Directory.Packages.props @@ -0,0 +1,20 @@ + + + + Alexander Salamatov + https://github.com/ch1seL/RedisLock + + true + snupkg + + MIT + + git + https://github.com/ch1seL/RedisLock + true + + true + latest + + + diff --git a/src/ch1seL.DistributedLock.Abstraction/DistributedLockException.cs b/src/ch1seL.DistributedLock.Abstraction/DistributedLockException.cs index 9d3d6de..507055d 100644 --- a/src/ch1seL.DistributedLock.Abstraction/DistributedLockException.cs +++ b/src/ch1seL.DistributedLock.Abstraction/DistributedLockException.cs @@ -7,17 +7,9 @@ public class DistributedLockException : Exception public DistributedLockException(string resource, string lockId, DistributedLockBadStatus status, Exception innerException = null) : base( "Lock is not acquired", innerException) { - Resource = resource; - LockId = lockId; - Status = status; - base.Data.Add("Resource", resource); base.Data.Add("LockId", lockId); base.Data.Add("Status", status); } - - public string Resource { get; } - public string LockId { get; } - public DistributedLockBadStatus Status { get; } } } \ No newline at end of file diff --git a/src/ch1seL.DistributedLock.Abstraction/ch1seL.DistributedLock.Abstraction.csproj b/src/ch1seL.DistributedLock.Abstraction/ch1seL.DistributedLock.Abstraction.csproj index 5608d4d..fd008df 100644 --- a/src/ch1seL.DistributedLock.Abstraction/ch1seL.DistributedLock.Abstraction.csproj +++ b/src/ch1seL.DistributedLock.Abstraction/ch1seL.DistributedLock.Abstraction.csproj @@ -2,19 +2,7 @@ netstandard2.1 - 0.1.2 - ch1seL - true - ch1seL.DistributedLock.Abstraction - ch1seL.DistributedLock.Abstraction - LICENSE - https://github.com/ch1seL/RedisLock - ch1seL.DistributedLock.Abstraction Microsoft.Extensions.Caching.Distributed - - - - diff --git a/src/ch1seL.DistributedLock.MemoryLock/MemoryLock.cs b/src/ch1seL.DistributedLock.MemoryLock/MemoryLock.cs index ebcb0fd..b6186c1 100644 --- a/src/ch1seL.DistributedLock.MemoryLock/MemoryLock.cs +++ b/src/ch1seL.DistributedLock.MemoryLock/MemoryLock.cs @@ -10,8 +10,7 @@ public class MemoryLock : IDistributedLock, IDisposable { public static readonly string SemaphoreReleaserTypeFullName = typeof(SemaphoreReleaser).FullName; - private readonly ConcurrentDictionary> _semaphoreSlims = - new ConcurrentDictionary>(); + private readonly ConcurrentDictionary> _semaphoreSlims = new(); public void Dispose() { @@ -23,9 +22,8 @@ public void Dispose() } } - public async Task CreateLockAsync(string resource, TimeSpan? expiryTime = null, - TimeSpan? waitTime = null, - TimeSpan? retryTime = null, CancellationToken cancellationToken = new CancellationToken()) + public async Task CreateLockAsync(string resource, TimeSpan? expiryTime = null, TimeSpan? waitTime = null, TimeSpan? retryTime = null, + CancellationToken cancellationToken = default) { Exception innerException = null; try diff --git a/src/ch1seL.DistributedLock.MemoryLock/MemoryLockServiceCollectionExtensions.cs b/src/ch1seL.DistributedLock.MemoryLock/MemoryLockServiceCollectionExtensions.cs index d6595d0..3766667 100644 --- a/src/ch1seL.DistributedLock.MemoryLock/MemoryLockServiceCollectionExtensions.cs +++ b/src/ch1seL.DistributedLock.MemoryLock/MemoryLockServiceCollectionExtensions.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Caching; -using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Caching.Distributed; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection diff --git a/src/ch1seL.DistributedLock.MemoryLock/ch1seL.DistributedLock.MemoryLock.csproj b/src/ch1seL.DistributedLock.MemoryLock/ch1seL.DistributedLock.MemoryLock.csproj index 50ff11e..a099569 100644 --- a/src/ch1seL.DistributedLock.MemoryLock/ch1seL.DistributedLock.MemoryLock.csproj +++ b/src/ch1seL.DistributedLock.MemoryLock/ch1seL.DistributedLock.MemoryLock.csproj @@ -1,24 +1,13 @@ - netstandard2.1 - 0.1.4 - ch1seL - true - ch1seL.DistributedLock.MemoryLock - ch1seL.DistributedLock.MemoryLock - LICENSE - https://github.com/ch1seL/RedisLock + netstandard2.1 Microsoft.Extensions.Caching.Distributed - - - - - - + + diff --git a/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLock.cs b/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLock.cs index 75bc2a2..cec084b 100644 --- a/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLock.cs +++ b/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLock.cs @@ -15,10 +15,10 @@ namespace Microsoft.Extensions.Caching.StackExchangeRedis { public class RedisLock : IDistributedLock, IDisposable { - private readonly SemaphoreSlim _connectionLock = new SemaphoreSlim(1, 1); - private readonly TimeSpan _defaultExpiryTime = TimeSpan.FromSeconds(60); + private readonly SemaphoreSlim _connectionLock = new(1, 1); + private readonly TimeSpan _defaultExpiryTime = TimeSpan.FromMinutes(2); private readonly TimeSpan _defaultRetryTime = TimeSpan.FromMilliseconds(500); - private readonly TimeSpan _defaultWaitTime = TimeSpan.FromSeconds(30); + private readonly TimeSpan _defaultWaitTime = TimeSpan.FromMinutes(1); private readonly ILoggerFactory _loggerFactory; private readonly RedisLockOptions _options; private IDistributedLockFactory _distributedLockFactory; @@ -42,13 +42,13 @@ public async Task CreateLockAsync(string resource, TimeSpan? expiry if (_options.InstanceName != null) resource = string.Join('-', _options.InstanceName, resource); - IRedLock @lock = await _distributedLockFactory.CreateLockAsync(resource, expiryTime ?? _defaultExpiryTime, waitTime ?? _defaultWaitTime, + var @lock = await _distributedLockFactory.CreateLockAsync(resource, expiryTime ?? _defaultExpiryTime, waitTime ?? _defaultWaitTime, retryTime ?? _defaultRetryTime, cancellationToken); if (@lock.IsAcquired) return @lock; var lockId = @lock.LockId; - DistributedLockBadStatus status = RedLockStatusToDistributedLockBadStatus(@lock.Status); + var status = RedLockStatusToDistributedLockBadStatus(@lock.Status); @lock.Dispose(); throw new DistributedLockException(resource, lockId, status); } @@ -61,6 +61,7 @@ private static DistributedLockBadStatus RedLockStatusToDistributedLockBadStatus( RedLockStatus.Conflicted => DistributedLockBadStatus.Conflicted, RedLockStatus.Expired => DistributedLockBadStatus.Expired, RedLockStatus.NoQuorum => DistributedLockBadStatus.NoQuorum, + RedLockStatus.Acquired => throw new ArgumentOutOfRangeException(), _ => throw new ArgumentOutOfRangeException() }; } @@ -72,7 +73,7 @@ private async Task Connect() try { if (_distributedLockFactory != null) return; - ConnectionMultiplexer connection = _options.ConfigurationOptions != null + var connection = _options.ConfigurationOptions != null ? await ConnectionMultiplexer.ConnectAsync(_options.ConfigurationOptions) : await ConnectionMultiplexer.ConnectAsync(_options.Configuration); _distributedLockFactory = RedLockFactory.Create(new List {connection}, _loggerFactory); diff --git a/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLockOptions.cs b/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLockOptions.cs index 3eee548..5bcfb39 100644 --- a/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLockOptions.cs +++ b/src/ch1seL.DistributedLock.RedisLock/StackExchangeRedis/RedisLockOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Options; using StackExchange.Redis; @@ -9,6 +10,7 @@ namespace Microsoft.Extensions.Caching.StackExchangeRedis /// /// Configuration options for . /// + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] public class RedisLockOptions : IOptions { /// diff --git a/src/ch1seL.DistributedLock.RedisLock/ch1seL.DistributedLock.RedisLock.csproj b/src/ch1seL.DistributedLock.RedisLock/ch1seL.DistributedLock.RedisLock.csproj index a391d18..58205b1 100644 --- a/src/ch1seL.DistributedLock.RedisLock/ch1seL.DistributedLock.RedisLock.csproj +++ b/src/ch1seL.DistributedLock.RedisLock/ch1seL.DistributedLock.RedisLock.csproj @@ -2,20 +2,9 @@ netstandard2.1 - 0.1.2 - ch1seL - true - ch1seL.DistributedLock.RedisLock - ch1seL.DistributedLock.RedisLock - LICENSE - https://github.com/ch1seL/RedisLock Microsoft.Extensions.Caching - - - - diff --git a/tests/ch1seL.DistributedLock.Tests/Base/IntervalsWithLockTestsBase.cs b/tests/ch1seL.DistributedLock.Tests/Base/IntervalsWithLockTestsBase.cs index e2ab9e0..150af2e 100644 --- a/tests/ch1seL.DistributedLock.Tests/Base/IntervalsWithLockTestsBase.cs +++ b/tests/ch1seL.DistributedLock.Tests/Base/IntervalsWithLockTestsBase.cs @@ -11,10 +11,10 @@ namespace ch1seL.DistributedLock.Tests.Base { public abstract class IntervalsWithLockTestsBase : IDisposable { - private readonly object _intervalsLock = new object(); + private readonly object _intervalsLock = new(); private readonly string _key = Guid.NewGuid().ToString("N"); private readonly Stopwatch _stopwatch = Stopwatch.StartNew(); - private readonly object _taskListLock = new object(); + private readonly object _taskListLock = new(); protected readonly IList Intervals = new List(); protected readonly IList TaskList = new List(); @@ -37,7 +37,7 @@ protected void Init(Action lockServiceRegistration) protected void AddSaveIntervalTaskToTaskList(TimeSpan? waitTime = null, TimeSpan? workTime = null, string key = null, CancellationToken cancellationToken = default) { - Task task = SaveInterval(waitTime, workTime, key, cancellationToken); + var task = SaveInterval(waitTime, workTime, key, cancellationToken); lock (_taskListLock) { @@ -47,7 +47,7 @@ protected void AddSaveIntervalTaskToTaskList(TimeSpan? waitTime = null, TimeSpan private async Task SaveInterval(TimeSpan? waitTime = null, TimeSpan? workTime = null, string key = null, CancellationToken cancellationToken = default) { - using IDisposable lockAsync = await _distributedLock.CreateLockAsync(key ?? _key, TimeSpan.FromMinutes(5), waitTime ?? TimeSpan.FromMinutes(5), + using var lockAsync = await _distributedLock.CreateLockAsync(key ?? _key, TimeSpan.FromMinutes(5), waitTime ?? TimeSpan.FromMinutes(5), TimeSpan.FromMilliseconds(100), cancellationToken); var start = _stopwatch.ElapsedTicks; @@ -61,7 +61,7 @@ private async Task SaveInterval(TimeSpan? waitTime = null, TimeSpan? workTime = } } - protected (Interval, Interval)[] GetIntersections() + protected IEnumerable<(Interval, Interval)> GetIntersections() { lock (_intervalsLock) { diff --git a/tests/ch1seL.DistributedLock.Tests/MemoryLockTests/MemoryLeakTests.cs b/tests/ch1seL.DistributedLock.Tests/MemoryLockTests/MemoryLeakTests.cs index 04aef71..d1c0453 100644 --- a/tests/ch1seL.DistributedLock.Tests/MemoryLockTests/MemoryLeakTests.cs +++ b/tests/ch1seL.DistributedLock.Tests/MemoryLockTests/MemoryLeakTests.cs @@ -34,7 +34,7 @@ public void Test() }); dotMemory.Check(memory => { - ObjectSet semaphores = memory.GetObjects(where => where.Type.Like(MemoryLock.SemaphoreReleaserTypeFullName)); + var semaphores = memory.GetObjects(where => where.Type.Like(MemoryLock.SemaphoreReleaserTypeFullName)); semaphores.ObjectsCount.Should().Be(repeat); }); @@ -45,7 +45,7 @@ public void Test() Intervals.Count.Should().Be(0); dotMemory.Check(memory => { - ObjectSet semaphores = memory.GetObjects(where => where.Type.Like(MemoryLock.SemaphoreReleaserTypeFullName)); + var semaphores = memory.GetObjects(where => where.Type.Like(MemoryLock.SemaphoreReleaserTypeFullName)); semaphores.ObjectsCount.Should().Be(0); }); } diff --git a/tests/ch1seL.DistributedLock.Tests/ch1seL.DistributedLock.Tests.csproj b/tests/ch1seL.DistributedLock.Tests/ch1seL.DistributedLock.Tests.csproj index 9c45c20..decd8c7 100644 --- a/tests/ch1seL.DistributedLock.Tests/ch1seL.DistributedLock.Tests.csproj +++ b/tests/ch1seL.DistributedLock.Tests/ch1seL.DistributedLock.Tests.csproj @@ -1,21 +1,22 @@ - netcoreapp3.1 + netcoreapp3.1;net5 false + latest - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive