Skip to content
Closed
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
6 changes: 1 addition & 5 deletions docs/Developing DistributedLock.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ If the Oracle tests fail with `ORA-12541: TNS:no listener`, you may have to star

### Postgres

You can install Postgres from [here](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads).

In `C:\Program Files\PostgreSQL\<version>\data\postgresql.conf`, update `max_connections` to 200.

Add your username (e.g. postgres) and password to `DistributedLock.Tests/credentials/postgres.txt`, with the username on line 1 and the password on line 2.
Have docker installed, we are using https://testcontainers.com/modules/postgresql/

### SQL Server

Expand Down
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageVersion Include="NUnit.Analyzers" Version="4.1.0" />
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="3.21.130" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
<PackageVersion Include="Oracle.ManagedDataAccess" Version="21.13.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageVersion Include="Npgsql" Version="8.0.2" />
<PackageVersion Include="Npgsql" Version="8.0.3" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.27" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.0" />
<PackageVersion Include="nunit" Version="3.14.0" />
Expand All @@ -22,6 +22,7 @@
<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="System.Threading.AccessControl" Version="8.0.0" Condition="'$(TargetFramework)' != 'net462'" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="3.8.0" />
<PackageVersion Include="ZooKeeperNetEx" Version="3.4.12.4" />
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'" />
Expand Down
30 changes: 3 additions & 27 deletions src/DistributedLock.Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
"System.Threading.Tasks.Extensions": "4.5.4"
}
},
"Microsoft.CodeAnalysis.PublicApiAnalyzers": {
"type": "Direct",
"requested": "[3.3.4, )",
"resolved": "3.3.4",
"contentHash": "kNLTfXtXUWDHVt5iaPkkiPuyHYlMgLI6SOFT4w88bfeI2vqSeGgHunFkdvlaCM8RDfcY0t2+jnesQtidRJJ/DA=="
},
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
"requested": "[1.0.3, )",
Expand Down Expand Up @@ -81,12 +75,6 @@
"System.Threading.Tasks.Extensions": "4.5.4"
}
},
"Microsoft.CodeAnalysis.PublicApiAnalyzers": {
"type": "Direct",
"requested": "[3.3.4, )",
"resolved": "3.3.4",
"contentHash": "kNLTfXtXUWDHVt5iaPkkiPuyHYlMgLI6SOFT4w88bfeI2vqSeGgHunFkdvlaCM8RDfcY0t2+jnesQtidRJJ/DA=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
"requested": "[8.0.0, )",
Expand Down Expand Up @@ -136,12 +124,6 @@
}
},
".NETStandard,Version=v2.1": {
"Microsoft.CodeAnalysis.PublicApiAnalyzers": {
"type": "Direct",
"requested": "[3.3.4, )",
"resolved": "3.3.4",
"contentHash": "kNLTfXtXUWDHVt5iaPkkiPuyHYlMgLI6SOFT4w88bfeI2vqSeGgHunFkdvlaCM8RDfcY0t2+jnesQtidRJJ/DA=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
"requested": "[8.0.0, )",
Expand All @@ -164,17 +146,11 @@
}
},
"net8.0": {
"Microsoft.CodeAnalysis.PublicApiAnalyzers": {
"type": "Direct",
"requested": "[3.3.4, )",
"resolved": "3.3.4",
"contentHash": "kNLTfXtXUWDHVt5iaPkkiPuyHYlMgLI6SOFT4w88bfeI2vqSeGgHunFkdvlaCM8RDfcY0t2+jnesQtidRJJ/DA=="
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.2, )",
"resolved": "8.0.2",
"contentHash": "hKTrehpfVzOhAz0mreaTAZgbz0DrMEbWq4n3hAo8Ks6WdxdqQhNPvzOqn9VygKuWf1bmxPdraqzTaXriO/sn0A=="
"requested": "[8.0.5, )",
"resolved": "8.0.5",
"contentHash": "4ISW1Ndgz86FkIbu5rVlMqhhtojdy5rUlxC/N+9kPh9qbYcvHiCvYbHKzAPVIx9OPYIjT9trXt7JI42Y5Ukq6A=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down
18 changes: 9 additions & 9 deletions src/DistributedLock.Postgres/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
},
"Npgsql": {
"type": "Direct",
"requested": "[8.0.2, )",
"resolved": "8.0.2",
"contentHash": "MuJzLoWCaQhQAR3oh66YR0Ir6mxuezncGX3f8wxvAc21g0+9HICktJQlqMoODhxztZKXE5k9GxRxqUAN+vPb4g==",
"requested": "[8.0.3, )",
"resolved": "8.0.3",
"contentHash": "6WEmzsQJCZAlUG1pThKg/RmeF6V+I0DmBBBE/8YzpRtEzhyZzKcK7ulMANDm5CkxrALBEC8H+5plxHWtIL7xnA==",
"dependencies": {
"Microsoft.Bcl.HashCode": "1.1.1",
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
Expand Down Expand Up @@ -215,9 +215,9 @@
},
"Npgsql": {
"type": "Direct",
"requested": "[8.0.2, )",
"resolved": "8.0.2",
"contentHash": "MuJzLoWCaQhQAR3oh66YR0Ir6mxuezncGX3f8wxvAc21g0+9HICktJQlqMoODhxztZKXE5k9GxRxqUAN+vPb4g==",
"requested": "[8.0.3, )",
"resolved": "8.0.3",
"contentHash": "6WEmzsQJCZAlUG1pThKg/RmeF6V+I0DmBBBE/8YzpRtEzhyZzKcK7ulMANDm5CkxrALBEC8H+5plxHWtIL7xnA==",
"dependencies": {
"Microsoft.Bcl.HashCode": "1.1.1",
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
Expand Down Expand Up @@ -384,9 +384,9 @@
},
"Npgsql": {
"type": "Direct",
"requested": "[8.0.2, )",
"resolved": "8.0.2",
"contentHash": "MuJzLoWCaQhQAR3oh66YR0Ir6mxuezncGX3f8wxvAc21g0+9HICktJQlqMoODhxztZKXE5k9GxRxqUAN+vPb4g==",
"requested": "[8.0.3, )",
"resolved": "8.0.3",
"contentHash": "6WEmzsQJCZAlUG1pThKg/RmeF6V+I0DmBBBE/8YzpRtEzhyZzKcK7ulMANDm5CkxrALBEC8H+5plxHWtIL7xnA==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
"System.Collections.Immutable": "8.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public async Task TestLockAbandonment()
public void TestCrossProcess()
{
var lockName = this._lockProvider.GetUniqueSafeName();
var command = this.RunLockTaker(this._lockProvider, this._lockProvider.GetCrossProcessLockType(), lockName);
var command = this.RunLockTaker(this._lockProvider, this._lockProvider.GetCrossProcessLockType(), lockName, this._lockProvider.GetConnectionStringForCrossProcessTest());
Assert.That(command.StandardOutput.ReadLineAsync().Wait(TimeSpan.FromSeconds(10)), Is.True);
Assert.That(command.Task.Wait(TimeSpan.FromSeconds(.1)), Is.False);

Expand Down Expand Up @@ -421,7 +421,7 @@ public void TestCrossProcessAbandonmentWithKill()
private void CrossProcessAbandonmentHelper(bool asyncWait, bool kill)
{
var name = this._lockProvider.GetUniqueSafeName($"cpl-{asyncWait}-{kill}");
var command = this.RunLockTaker(this._lockProvider, this._lockProvider.GetCrossProcessLockType(), name);
var command = this.RunLockTaker(this._lockProvider, this._lockProvider.GetCrossProcessLockType(), name, this._lockProvider.GetConnectionStringForCrossProcessTest());
Assert.That(command.StandardOutput.ReadLineAsync().Wait(TimeSpan.FromSeconds(10)), Is.True);
Assert.That(command.Task.IsCompleted, Is.False);

Expand Down
1 change: 1 addition & 0 deletions src/DistributedLock.Tests/DistributedLock.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="MedallionShell.StrongName" />
<PackageReference Include="System.Data.SqlClient" />
<PackageReference Include="Moq" />
<PackageReference Include="Testcontainers.PostgreSql" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/DistributedLock.Tests/Infrastructure/Postgres/PostgresDb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Testcontainers.PostgreSql;

namespace Medallion.Threading.Tests.Postgres;

public class PostgresDb
{
public static PostgreSqlContainer Container { get; } = new PostgreSqlBuilder().Build();

static PostgresDb()
{
Container.StartAsync().Wait();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Medallion.Threading.Tests.Postgres;

public sealed class TestingPostgresDb : TestingPrimaryClientDb
{
internal static readonly string DefaultConnectionString = PostgresCredentials.GetConnectionString(TestContext.CurrentContext.TestDirectory);
internal static readonly string DefaultConnectionString = PostgresDb.Container.GetConnectionString();

private readonly NpgsqlConnectionStringBuilder _connectionStringBuilder = new(DefaultConnectionString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public override IDistributedLock CreateLockWithExactName(string name) =>

public override string GetSafeName(string name) => new PostgresAdvisoryLockKey(name, allowHashing: true).ToString();

public override string GetConnectionStringForCrossProcessTest() => TestingPostgresDb.DefaultConnectionString;

internal static Action<PostgresConnectionOptionsBuilder> ToPostgresOptions((bool useMultiplexing, bool useTransaction, TimeSpan? keepaliveCadence) options) => o =>
{
o.UseMultiplexing(options.useMultiplexing);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class TestingLockProvider<TStrategy> : ITestingNameProvider, IDi
public virtual string GetCrossProcessLockType() => this.CreateLock(string.Empty).GetType().Name;
public virtual void Dispose() => this.Strategy.Dispose();

public virtual string GetConnectionStringForCrossProcessTest() => "<connection-string>";

/// <summary>
/// Returns a lock whose name is based on <see cref="TestingNameProviderExtensions.GetUniqueSafeName(ITestingNameProvider, string)"/>
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/DistributedLock.Tests/Tests/GlobalSetupTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Medallion.Threading.Tests.Postgres;
using NUnit.Framework;

namespace Medallion.Threading.Tests;

public class GlobalSetupTest
{

[OneTimeSetUp]
public async Task GlobalSetup()
{
// await PostgresDb.Container.StartAsync();
}

[OneTimeTearDown]
public async Task GlobalTeardown()
{
await PostgresDb.Container.StopAsync();
}
}
Loading