From 352cfaf9437b7530716020e38fbfc733d91280d3 Mon Sep 17 00:00:00 2001 From: aviv Date: Thu, 9 May 2024 14:41:28 +0300 Subject: [PATCH] RavenDB-21854 : add more debug info to flaky test --- .../Documents/ETL/Raven/BasicRavenEtlTests.cs | 38 ++++++++++++++++++- .../Tests.Infrastructure/RavenTestBase.Etl.cs | 4 +- .../RavenTestBase.Sharding.cs | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/test/SlowTests/Server/Documents/ETL/Raven/BasicRavenEtlTests.cs b/test/SlowTests/Server/Documents/ETL/Raven/BasicRavenEtlTests.cs index adb9d7975b2f..0a6a83b63187 100644 --- a/test/SlowTests/Server/Documents/ETL/Raven/BasicRavenEtlTests.cs +++ b/test/SlowTests/Server/Documents/ETL/Raven/BasicRavenEtlTests.cs @@ -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()) { @@ -189,6 +189,40 @@ public async Task WithDocumentPrefix(RavenDatabaseMode srcDbMode, RavenDatabaseM } } + private async Task 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() + .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) diff --git a/test/Tests.Infrastructure/RavenTestBase.Etl.cs b/test/Tests.Infrastructure/RavenTestBase.Etl.cs index 78718bf15bc2..dc39199728e5 100644 --- a/test/Tests.Infrastructure/RavenTestBase.Etl.cs +++ b/test/Tests.Infrastructure/RavenTestBase.Etl.cs @@ -331,14 +331,14 @@ public async Task 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(); diff --git a/test/Tests.Infrastructure/RavenTestBase.Sharding.cs b/test/Tests.Infrastructure/RavenTestBase.Sharding.cs index 81417ec7c2f7..8bc44507e05c 100644 --- a/test/Tests.Infrastructure/RavenTestBase.Sharding.cs +++ b/test/Tests.Infrastructure/RavenTestBase.Sharding.cs @@ -311,7 +311,7 @@ public async ValueTask GetAnyShardDocumentDatabaseInsta return null; } - public async ValueTask GetDatabaseStatisticsAsync(DocumentStore store, string database = null, DatabaseRecord record = null, List servers = null) + public async ValueTask GetDatabaseStatisticsAsync(IDocumentStore store, string database = null, DatabaseRecord record = null, List servers = null) { var shardingConfiguration = record != null ? record.Sharding : await GetShardingConfigurationAsync(store, database); DatabaseStatistics combined = new DatabaseStatistics();