public void TestIdleSessionKiller() { using (var idleSessionKiller = new IdleSessionKiller(SqlDistributedLockTest.ConnectionString, idleTimeout: TimeSpan.FromSeconds(.25))) { var @lock = new SqlDistributedLock(nameof(TestIdleSessionKiller), SqlDistributedLockTest.ConnectionString); var handle = @lock.Acquire(); Thread.Sleep(TimeSpan.FromSeconds(1)); TestHelper.AssertThrows <SqlException>(() => handle.Dispose()); } }
public void TestIdleSessionKiller() { using var engine = new TEngineFactory().Create <DefaultConnectionStringProvider>(); using var idleSessionKiller = new IdleSessionKiller(ConnectionStringProvider.ConnectionString, idleTimeout: TimeSpan.FromSeconds(.25)); var @lock = engine.CreateLock(nameof(TestIdleSessionKiller)); var handle = @lock.Acquire(); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.Catch <DbException>(() => handle.Dispose()); }
[NonParallelizable] // sets static KeepaliveHelper.Interval public void TestAzureStrategyProtectsFromIdleSessionKiller() { using var engine = this.CreateEngine(); var originalInterval = KeepaliveHelper.Interval; try { KeepaliveHelper.Interval = TimeSpan.FromSeconds(.1); using var idleSessionKiller = new IdleSessionKiller(ConnectionStringProvider.ConnectionString, idleTimeout: TimeSpan.FromSeconds(.25)); var @lock = engine.CreateLock(nameof(TestAzureStrategyProtectsFromIdleSessionKiller)); var handle = @lock.Acquire(); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.DoesNotThrow(() => handle.Dispose()); } finally { KeepaliveHelper.Interval = originalInterval; } }
public void TestAzureStrategyProtectsFromIdleSessionKiller() { var originalInterval = KeepaliveHelper.Interval; try { KeepaliveHelper.Interval = TimeSpan.FromSeconds(.1); using (var idleSessionKiller = new IdleSessionKiller(SqlDistributedLockTest.ConnectionString, idleTimeout: TimeSpan.FromSeconds(.25))) { var @lock = this.CreateLock(nameof(TestAzureStrategyProtectsFromIdleSessionKiller)); var handle = @lock.Acquire(); Thread.Sleep(TimeSpan.FromSeconds(1)); TestHelper.AssertDoesNotThrow(() => handle.Dispose()); } } finally { KeepaliveHelper.Interval = originalInterval; } }