diff --git a/Consul.Test/SemaphoreTest.cs b/Consul.Test/SemaphoreTest.cs index 468c599d4fdd..d5f1cf177874 100644 --- a/Consul.Test/SemaphoreTest.cs +++ b/Consul.Test/SemaphoreTest.cs @@ -112,6 +112,29 @@ public void Semaphore_AcquireRelease() Assert.IsFalse(s.IsHeld); } + [TestMethod] + public void Semaphore_AcquireWaitRelease() + { + const string Name = "XService"; + const string Prefix = Name + "/lock"; + const int Limit = 1; + var _semaphoreOptions = new SemaphoreOptions(Prefix, Limit) { SessionName = Name + "_Session", SessionTTL = TimeSpan.FromSeconds(10) }; + var c = ClientTest.MakeClient(); + + var s = c.Semaphore(_semaphoreOptions); + + s.Acquire(CancellationToken.None); + + Assert.IsTrue(s.IsHeld); + Thread.Sleep(30000); + Assert.IsTrue(s.IsHeld); + + Assert.IsTrue(s.IsHeld); + + s.Release(); + + Assert.IsFalse(s.IsHeld); + } [TestMethod] public void Semaphore_Contend() diff --git a/Consul/Session.cs b/Consul/Session.cs index bde05cfffd4a..87d19467d1aa 100644 --- a/Consul/Session.cs +++ b/Consul/Session.cs @@ -325,7 +325,7 @@ public Task RenewPeriodic(TimeSpan initialTTL, string id, WriteOptions q, Cancel try { var res = Renew(id, q); - if (res.Response != null) + if (res.Response == null) { lastException = new TaskCanceledException("Session no longer exists"); }