Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster fixture shutdown logging #1864

Merged
merged 1 commit into from
Nov 30, 2022
Merged
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
39 changes: 37 additions & 2 deletions tests/Proto.Cluster.Tests/ClusterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,21 @@ public async Task DisposeAsync()
try
{
await OnDisposing();
//_tracerProvider?.Dispose();
await Task.WhenAll(Members.ToList().Select(cluster => cluster.ShutdownAsync())).ConfigureAwait(false);

if (EnableTracing)
{
var testName = this.GetType().Name;
using (Tracing.StartActivity("ClusterFixture.DisposeAsync " + testName))
{
await WaitForMembersToShutdown();
}
}
else
{
await WaitForMembersToShutdown();
}

_tracerProvider?.Dispose();
Members.Clear(); // prevent multiple shutdown attempts if dispose is called multiple times
}
catch (Exception e)
Expand All @@ -114,6 +127,28 @@ public async Task DisposeAsync()
}
}

private async Task WaitForMembersToShutdown()
{
foreach (var cluster in _members)
{
_logger.LogInformation("Preparing shutdown for cluster member {MemberId}", cluster.System.Id);
}

var tasks = Members.ToList().Select(cluster => (cluster, cluster.ShutdownAsync())).ToList();
foreach (var (cluster, task) in tasks)
{
try
{
_logger.LogInformation("Shutting down cluster member {MemberId}", cluster.System.Id);
await task;
}
catch (Exception e)
{
_logger.LogError(e, "Error shutting down cluster {MemberId}", cluster.System.Id);
}
}
}

public int ClusterSize { get; }

public LogStore LogStore { get; } = new();
Expand Down