fix: re-enable leader check in API router and fix stepdown simulation
Re-enabled the leader check in JetStreamApiRouter.Route() that was commented out during B8 agent work. Added BecomeLeader() method to JetStreamMetaGroup for single-process test fixtures to simulate winning the post-stepdown election. MetaControllerFixture now auto-calls BecomeLeader() after a successful meta leader stepdown.
This commit is contained in:
@@ -625,7 +625,17 @@ internal sealed class MetaControllerFixture : IAsyncDisposable
|
||||
public MetaGroupState GetMetaState() => _metaGroup.GetState();
|
||||
|
||||
public Task<JetStreamApiResponse> RequestAsync(string subject, string payload)
|
||||
=> Task.FromResult(_router.Route(subject, Encoding.UTF8.GetBytes(payload)));
|
||||
{
|
||||
var response = _router.Route(subject, Encoding.UTF8.GetBytes(payload));
|
||||
|
||||
// In a real cluster, after stepdown a new leader is elected.
|
||||
// Simulate this node becoming the new leader so subsequent mutating
|
||||
// operations through the router succeed.
|
||||
if (subject.Equals(JetStreamApiSubjects.MetaLeaderStepdown, StringComparison.Ordinal) && response.Success)
|
||||
_metaGroup.BecomeLeader();
|
||||
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user