Skip to content

Commit

Permalink
RavenDB-21854 : add more debug info to flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv committed May 9, 2024
1 parent cfbd791 commit 352cfaf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
38 changes: 36 additions & 2 deletions test/SlowTests/Server/Documents/ETL/Raven/BasicRavenEtlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public async Task WithDocumentPrefix(RavenDatabaseMode srcDbMode, RavenDatabaseM
session.Advanced.Exists(secondaryId) == false;
}
}, true, timeout);

Assert.True(etlReachedDestination, await Etl.GetEtlDebugInfo(src.Database, TimeSpan.FromMilliseconds(timeout), srcDbMode));
Assert.True(etlReachedDestination, await AddDebugInfo(src, dest, srcDbMode, dstDbMode));

using (var session = dest.OpenSession())
{
Expand All @@ -189,6 +189,40 @@ public async Task WithDocumentPrefix(RavenDatabaseMode srcDbMode, RavenDatabaseM
}
}

private async Task<string> AddDebugInfo(IDocumentStore src, IDocumentStore dest, RavenDatabaseMode srcDbMode, RavenDatabaseMode destDbMode)
{
var etlDebugInfo = await Etl.GetEtlDebugInfo(src.Database, TimeSpan.FromMilliseconds(30_000), srcDbMode);
var sb = new StringBuilder().AppendLine(etlDebugInfo);

sb.AppendLine().AppendLine($"Database statistics for destination db '{dest.Database}':");

var stats = destDbMode switch
{
RavenDatabaseMode.Single => await dest.Maintenance.SendAsync(new GetStatisticsOperation()),
RavenDatabaseMode.Sharded => await Sharding.GetDatabaseStatisticsAsync(dest),
_ => throw new ArgumentOutOfRangeException(nameof(destDbMode), destDbMode, null)
};

sb.AppendLine(JsonConvert.SerializeObject(stats)).AppendLine();

using (var session = dest.OpenAsyncSession())
{
var ids = await session.Query<User>()
.Select(u => u.Id)
.ToListAsync();

if (ids.Count > 0)
{
sb.AppendLine($"'User' documents in destination database '{dest.Database}': ")
.Append('[')
.Append(string.Join(',', ids))
.Append(']');
}
}

return sb.ToString();
}

[RavenTheory(RavenTestCategory.Etl)]
[RavenData(DatabaseMode = RavenDatabaseMode.All)]
public void SetMentorToEtlAndFailover(Options options)
Expand Down
4 changes: 2 additions & 2 deletions test/Tests.Infrastructure/RavenTestBase.Etl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ public async Task<string> GetEtlDebugInfo(string database, TimeSpan? timeout = n
_ => throw new ArgumentOutOfRangeException(nameof(databaseMode), databaseMode, null)
};

var sb = new StringBuilder($"ETL did not finish in {timeout?.TotalSeconds ?? 30} seconds.");
var sb = new StringBuilder().AppendLine($"ETL did not finish in {timeout?.TotalSeconds ?? 30} seconds.");

foreach (var documentDatabase in databases)
{
var performanceStats = GetEtlPerformanceStatsForDatabase(documentDatabase);
if (performanceStats == null)
continue;
sb.AppendLine($"database '{documentDatabase.Name}' stats : {performanceStats}");
sb.AppendLine($"Database '{documentDatabase.Name}' ETL performance stats : {performanceStats}");
}

return sb.ToString();
Expand Down
2 changes: 1 addition & 1 deletion test/Tests.Infrastructure/RavenTestBase.Sharding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public async ValueTask<ShardedDocumentDatabase> GetAnyShardDocumentDatabaseInsta
return null;
}

public async ValueTask<DatabaseStatistics> GetDatabaseStatisticsAsync(DocumentStore store, string database = null, DatabaseRecord record = null, List<RavenServer> servers = null)
public async ValueTask<DatabaseStatistics> GetDatabaseStatisticsAsync(IDocumentStore store, string database = null, DatabaseRecord record = null, List<RavenServer> servers = null)
{
var shardingConfiguration = record != null ? record.Sharding : await GetShardingConfigurationAsync(store, database);
DatabaseStatistics combined = new DatabaseStatistics();
Expand Down

0 comments on commit 352cfaf

Please sign in to comment.