Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,36 @@ public void ClusterSingleton_with_lease_should_release_lease_when_leaving_oldest
_cluster.Leave(_cluster.SelfAddress);
testLease.Probe.ExpectMsg(new TestLease.ReleaseReq(_leaseOwner));
}

[Fact]
public void ClusterSingleton_with_lease_should_log_error_when_lease_release_fails_on_leaving_oldest()
{
var singletonProbe = CreateTestProbe();
var settings = NextSettings();

Sys.ActorOf(
ClusterSingletonManager.Props(Props.Create(() => new ImportantSingleton(singletonProbe.Ref)), PoisonPill.Instance, settings),
settings.SingletonName);

TestLease testLease = null;
AwaitAssert(() =>
{
testLease = _testLeaseExt.GetTestLease(LeaseNameFor(settings));
});

singletonProbe.ExpectNoMsg(_shortDuration);
testLease.Probe.ExpectMsg(new TestLease.AcquireReq(_leaseOwner));
testLease.InitialPromise.SetResult(true);
singletonProbe.ExpectMsg("preStart");

// Make release return a faulted task
testLease.SetNextReleaseResult(Task.FromException<bool>(new TestException("lease release failed")));

EventFilter.Error(contains: "Failed to release lease").ExpectOne(() =>
{
_cluster.Leave(_cluster.SelfAddress);
testLease.Probe.ExpectMsg(new TestLease.ReleaseReq(_leaseOwner));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,12 @@ when removed.Member.UniqueAddress.Equals(_cluster.SelfUniqueAddress) && !_selfEx
if (from == ClusterSingletonState.Oldest && _lease != null)
{
Log.Info("Releasing lease as leaving Oldest");
_lease.Release().ContinueWith(r => new ReleaseLeaseResult(r.Result)).PipeTo(Self);
_lease.Release().ContinueWith(r =>
{
if (r.IsCanceled || r.IsFaulted)
return (object)new ReleaseLeaseFailure(r.Exception ?? (Exception)new LeaseException("Failed to release lease"));
return new ReleaseLeaseResult(r.Result);
}).PipeTo(Self);
}

if (to is ClusterSingletonState.Younger or ClusterSingletonState.Oldest) GetNextOldestChanged();
Expand Down
5 changes: 4 additions & 1 deletion src/core/Akka.Coordination.Tests/TestLease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static Config Configuration

public TestProbe Probe { get; }
private AtomicReference<Task<bool>> nextAcquireResult;
private AtomicReference<Task<bool>> nextReleaseResult = new(Task.FromResult(true));
private AtomicBoolean nextCheckLeaseResult = new(false);
private AtomicReference<Action<Exception>> currentCallBack = new(_ => { });
private ILoggingAdapter _log;
Expand All @@ -136,6 +137,8 @@ public TestLease(LeaseSettings settings, ExtendedActorSystem system)

public void SetNextAcquireResult(Task<bool> next) => nextAcquireResult.GetAndSet(next);

public void SetNextReleaseResult(Task<bool> next) => nextReleaseResult.GetAndSet(next);

public void SetNextCheckLeaseResult(bool value) => nextCheckLeaseResult.GetAndSet(value);

public Action<Exception> GetCurrentCallback() => currentCallBack.Value;
Expand All @@ -151,7 +154,7 @@ public override Task<bool> Acquire()
public override Task<bool> Release()
{
Probe.Ref.Tell(new ReleaseReq(Settings.OwnerName));
return Task.FromResult(true);
return nextReleaseResult.Value;
}

public override bool CheckLease() => nextCheckLeaseResult.Value;
Expand Down
Loading