Skip to content

Commit

Permalink
Issue hashicorp#7: Fix error in renewperiodic logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Mul committed May 27, 2015
1 parent 26c7732 commit 65b819d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Consul.Test/SemaphoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Consul/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 65b819d

Please sign in to comment.