Skip to content

Commit

Permalink
RavenDB-20934 : add debug info to flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv committed May 1, 2024
1 parent ed2bb90 commit 8bd2cb4
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions test/SlowTests/Sharding/ETL/ShardedEtlFailoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
using Raven.Client.ServerWide;
using Raven.Client.ServerWide.Operations;
using Raven.Client.ServerWide.Sharding;
using Raven.Server;
using Raven.Server.Documents.Sharding;
using Raven.Server.ServerWide.Context;
using Raven.Server.Utils;
using Raven.Tests.Core.Utils.Entities;
using SlowTests.Server.Documents.ETL.Olap;
using Sparrow.Json;
using Sparrow.Utils;
using Tests.Infrastructure;
using Xunit;
Expand Down Expand Up @@ -152,7 +154,7 @@ public async Task ReplicateFromSingleSource(int replicationFactor)
ex = e;
}

Assert.True(ex is NodeIsPassiveException, await AddDebugInfo(ex));
Assert.True(ex is NodeIsPassiveException, await AddDebugInfo(ex, originalTaskNode));

/*Assert.Throws<NodeIsPassiveException>(() =>
{
Expand Down Expand Up @@ -851,13 +853,52 @@ await session.StoreAsync(new Query.Order
Assert.True(files.Length > count);
}

private async Task<string> AddDebugInfo(Exception ex)
private async Task<string> AddDebugInfo(Exception ex, RavenServer node)
{
var sb = new StringBuilder()
.AppendLine($"Failed. Expected NodeIsPassiveException but {(ex == null ? "none" : ex.GetType())} was thrown.")
.AppendLine("Cluster debug logs:");

await GetClusterDebugLogsAsync(sb);

sb.AppendLine().AppendLine($"Debug logs for removed node '{node.ServerStore.NodeTag}':");

var prevStates = node.ServerStore.Engine.PrevStates;
sb.AppendLine($"{Environment.NewLine}States:{Environment.NewLine}-----------------------");
foreach (var state in prevStates)
{
sb.AppendLine($"{state}{Environment.NewLine}");
}
sb.AppendLine();

using (node.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext clusterOperationContext))
using (clusterOperationContext.OpenReadTransaction())
{
var historyLogs = node.ServerStore.Engine.LogHistory.GetHistoryLogs(clusterOperationContext);
sb.AppendLine($"HistoryLogs:{Environment.NewLine}-----------------------");

using (var context = JsonOperationContext.ShortTermSingleUse())
{
var c = 0;
foreach (var log in historyLogs)
{
var json = context.ReadObject(log, nameof(log) + $"{c++}");
sb.AppendLine(json.ToString());
}
}
sb.AppendLine();

var inMemoryDebug = node.ServerStore.Engine.InMemoryDebug.ToJson();
if (inMemoryDebug != null)
{
sb.AppendLine($"RachisDebug:{Environment.NewLine}-----------------------");
using (var context = JsonOperationContext.ShortTermSingleUse())
{
var json = context.ReadObject(inMemoryDebug, nameof(inMemoryDebug));
sb.AppendLine(json.ToString());
}
}
}

return sb.ToString();
}

Expand Down

0 comments on commit 8bd2cb4

Please sign in to comment.