forked from madelson/DistributedLock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestingLockProvider.cs
More file actions
25 lines (18 loc) · 1.08 KB
/
TestingLockProvider.cs
File metadata and controls
25 lines (18 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
namespace Medallion.Threading.Tests;
public abstract class TestingLockProvider<TStrategy> : ITestingNameProvider, IDisposable
where TStrategy : TestingSynchronizationStrategy, new()
{
private readonly Lazy<TStrategy> _lazyStrategy = new(() => new TStrategy());
public virtual TStrategy Strategy => this._lazyStrategy.Value;
public virtual bool SupportsCrossProcessAbandonment => true;
public abstract IDistributedLock CreateLockWithExactName(string name);
public abstract string GetSafeName(string name);
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>
public IDistributedLock CreateLock(string baseName) =>
this.CreateLockWithExactName(this.GetUniqueSafeName(baseName));
}