Skip to content

Commit

Permalink
Decrease execution time for Hangfire.SqlServer.Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Nov 8, 2024
1 parent b841265 commit 982a1d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tests/Hangfire.SqlServer.Tests/SqlServerConnectionFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool
var thread = new Thread(
() => UseConnection(connection1 =>
{
using (connection1.AcquireDistributedLock("exclusive", TimeSpan.FromSeconds(5)))
using (connection1.AcquireDistributedLock("exclusive", TimeSpan.Zero))
{
lockAcquired.Set();
releaseLock.Wait();
Expand All @@ -155,7 +155,7 @@ public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool
Assert.Throws<DistributedLockTimeoutException>(
() =>
{
using (connection2.AcquireDistributedLock("exclusive", TimeSpan.FromSeconds(5)))
using (connection2.AcquireDistributedLock("exclusive", TimeSpan.FromSeconds(1)))
{
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Ctor_ThrowsAnException_IfLockCanNotBeGranted(bool useMicrosoftDataSq
() => UseConnection(connection1 =>
{
var storage = CreateStorage(connection1);
using (new SqlServerDistributedLock(storage, "exclusive", _timeout))
using (new SqlServerDistributedLock(storage, "exclusive", TimeSpan.Zero))
{
lockAcquired.Set();
releaseLock.Wait();
Expand All @@ -86,7 +86,7 @@ public void Ctor_ThrowsAnException_IfLockCanNotBeGranted(bool useMicrosoftDataSq
Assert.Throws<DistributedLockTimeoutException>(
() =>
{
using (new SqlServerDistributedLock(storage, "exclusive", _timeout))
using (new SqlServerDistributedLock(storage, "exclusive", TimeSpan.FromSeconds(1)))
{
}
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Hangfire.SqlServer.Tests/SqlServerTimeoutJobFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void RemoveFromQueue_AfterTimer_RemovesJobFromTheQueue(bool useMicrosoftD
var id = CreateJobQueueRecord(sql, "1", "default", FetchedAt);
using (var processingJob = new SqlServerTimeoutJob(storage, id, "1", "default", FetchedAt))
{
Thread.Sleep(TimeSpan.FromSeconds(2));
Thread.Sleep(TimeSpan.FromSeconds(1));
processingJob.DisposeTimer();

// Act
Expand All @@ -193,7 +193,7 @@ public void RequeueQueue_AfterTimer_SetsFetchedAtValueToNull(bool useMicrosoftDa
var id = CreateJobQueueRecord(sql, "1", "default", FetchedAt);
using (var processingJob = new SqlServerTimeoutJob(storage, id, "1", "default", FetchedAt))
{
Thread.Sleep(TimeSpan.FromSeconds(2));
Thread.Sleep(TimeSpan.FromSeconds(1));
processingJob.DisposeTimer();

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2294,9 +2294,9 @@ public void AcquireDistributedLock_AcquiresExclusiveApplicationLock_OnSession(bo
}

[Theory, CleanDatabase]
[InlineData(false, false), InlineData(false, true)]
[InlineData(true, false), InlineData(true, true)]
public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool useBatching, bool useMicrosoftDataSqlClient)
[InlineData(false)]
[InlineData(true)]
public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool useMicrosoftDataSqlClient)
{
var releaseLock = new ManualResetEventSlim(false);
var lockAcquired = new ManualResetEventSlim(false);
Expand All @@ -2306,7 +2306,7 @@ public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool
{
try
{
transaction1.AcquireDistributedLock("exclusive", TimeSpan.FromSeconds(1));
transaction1.AcquireDistributedLock("exclusive", TimeSpan.Zero);

lockAcquired.Set();
if (!releaseLock.Wait(TimeSpan.FromSeconds(30)))
Expand All @@ -2325,7 +2325,7 @@ public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool
// Need only message
}
}
}, useMicrosoftDataSqlClient, useBatching));
}, useMicrosoftDataSqlClient, useBatching: true));
thread.Start();

if (!lockAcquired.Wait(TimeSpan.FromSeconds(30)))
Expand All @@ -2337,7 +2337,7 @@ public void AcquireDistributedLock_ThrowsAnException_IfLockCanNotBeGranted(bool
{
Assert.Throws<DistributedLockTimeoutException>(
() => transaction2.AcquireDistributedLock("exclusive", TimeSpan.FromSeconds(1)));
}, useMicrosoftDataSqlClient, useBatching);
}, useMicrosoftDataSqlClient, useBatching: true);

releaseLock.Set();
thread.Join();
Expand Down

0 comments on commit 982a1d5

Please sign in to comment.