Skip to content

Commit

Permalink
fix: wait for the proper raft status instead of just for the status t…
Browse files Browse the repository at this point in the history
…o be up. Removed obsolete purge events
  • Loading branch information
yreynhout committed Nov 22, 2023
1 parent 67fb80a commit 107b513
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
8 changes: 1 addition & 7 deletions src/AxonIQ.AxonServer.Embedded/AxonServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ public DnsEndPoint GetGrpcEndpoint()
return Server.GetGrpcEndpoint();
}

public GrpcChannel CreateGrpcChannel(GrpcChannelOptions? options = default)
public GrpcChannel CreateGrpcChannel(GrpcChannelOptions? options)
{
return Server.CreateGrpcChannel(options);
}

public async Task PurgeEvents()
{
using var client = Server.CreateHttpClient();
(await client.DeleteAsync("v1/devmode/purge-events")).EnsureSuccessStatusCode();
}

public Task DisposeAsync()
{
return Server.DisposeAsync();
Expand Down
19 changes: 17 additions & 2 deletions src/AxonIQ.AxonServer.Embedded/EmbeddedAxonServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public async Task WaitUntilAvailableAsync(TimeSpan? maximumWaitTime = default, T
Port = endpoint.Port,
Path = "actuator/health"
}.Uri;

//Only test the raft status of contexts this node is hosting a replication group for
var contexts =
Template
.ReplicationGroups?
.Where(replicationGroup =>
replicationGroup.Roles?.Any(role => role.Node == Properties.NodeSetup.Name) ?? false)
.SelectMany(replicationGroup => replicationGroup.Contexts?.Where(context => context.Name != null)
.Select(context => new Context(context.Name!)) ?? Array.Empty<Context>())
.ToArray() ?? Array.Empty<Context>();

var watch = Stopwatch.StartNew();
while (!available && watch.Elapsed < (maximumWaitTime ?? DefaultMaximumWaitTime))
Expand All @@ -113,8 +123,13 @@ public async Task WaitUntilAvailableAsync(TimeSpan? maximumWaitTime = default, T
var response = (await client.GetAsync(requestUri)).EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
var document = JsonDocument.Parse(json);
var property = document.RootElement.GetProperty("status");
if (property.GetString() == "UP")
if (document.RootElement.GetProperty("status").GetString() == "UP" &&
document.RootElement.GetProperty("components").GetProperty("raft").GetProperty("status").GetString() == "UP" &&
contexts.All(context =>
document.RootElement
.GetProperty("components").GetProperty("raft").GetProperty("details")
.GetProperty($"{context.ToString()}.leader").GetString() != null
))
{
available = true;
}
Expand Down
8 changes: 1 addition & 7 deletions src/AxonIQ.AxonServer.Embedded/ToxicAxonServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ public DnsEndPoint GetGrpcEndpoint()
return Server.GetGrpcEndpoint();
}

public GrpcChannel CreateGrpcChannel(GrpcChannelOptions? options = default)
public GrpcChannel CreateGrpcChannel(GrpcChannelOptions? options)
{
return Server.CreateGrpcChannel(options);
}

public async Task PurgeEvents()
{
using var client = Server.CreateHttpClient();
(await client.DeleteAsync("v1/devmode/purge-events")).EnsureSuccessStatusCode();
}

public Task DisposeAsync()
{
return Server.DisposeAsync();
Expand Down

0 comments on commit 107b513

Please sign in to comment.