Skip to content

Commit

Permalink
RavenDB-21392 : fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv86 committed Nov 13, 2023
1 parent b5cd580 commit f4371af
Showing 1 changed file with 4 additions and 60 deletions.
64 changes: 4 additions & 60 deletions test/SlowTests/Issues/RavenDB-15330.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FastTests;
using FastTests.Server.Replication;
using Orders;
using Raven.Client.Documents.Indexes;
using Raven.Client.Util;
using Raven.Server.Config;
using Raven.Server.Documents.Indexes.Static;
using Raven.Server.Rachis;
using Raven.Server.ServerWide;
using Raven.Server.ServerWide.Commands.Indexes;
using Raven.Server.ServerWide.Commands.Subscriptions;
using Raven.Server.ServerWide.Context;
using Raven.Server.Utils;
using SlowTests.Rolling;
using Sparrow.Json.Parsing;
using Tests.Infrastructure;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -33,69 +20,26 @@ public RavenDB_15330(ITestOutputHelper output) : base(output)
[Fact]
public async Task Command_With_DontCareId_Should_Be_Committed()
{
var typeProp = nameof(RachisLogHistory.LogHistoryColumn.Type);
var stateProp = nameof(RachisLogHistory.LogHistoryColumn.State);
var indexProp = nameof(RachisLogHistory.LogHistoryColumn.Index);

var server = GetNewServer();
using var store = GetDocumentStoreForRollingIndexes(new RavenTestBase.Options
using var store = GetDocumentStoreForRollingIndexes(new Options
{
ModifyDatabaseRecord =
record => record.Settings[RavenConfiguration.GetKey(x => x.Indexing.MaxTimeToWaitAfterFlushAndSyncWhenReplacingSideBySideIndex)] = "5",
Server = server,
ReplicationFactor = 1,
});

await store.ExecuteIndexAsync(new SomeRollingIndex());

var result = await server.ServerStore.SendToLeaderAsync(new PutRollingIndexCommand(store.Database, nameof(SomeRollingIndex),
await server.ServerStore.SendToLeaderAsync(new PutRollingIndexCommand(store.Database, "SomeRollingIndex",
DateTime.UtcNow, RaftIdGenerator.DontCareId));

using (server.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
using (context.OpenReadTransaction())
{
var historyLog = server.ServerStore.Engine.LogHistory.GetHistoryLogs(context);
bool contain = false;
bool first = true;
long lastIndex = 0;
foreach (var djv in historyLog)
{
if (first)
{
lastIndex = long.Parse(djv[indexProp].ToString());
first = false;
}
else
{
var currentIndex = long.Parse(djv[indexProp].ToString());
Assert.Equal(lastIndex+1, currentIndex);
lastIndex = currentIndex;
}

if (djv[typeProp] != null && djv[typeProp].ToString() == nameof(PutRollingIndexCommand) &&
djv[stateProp] !=null && djv[stateProp].ToString() == "Committed")
{
contain = true;
break;
}
}
bool contain = historyLog.Any(djv => djv[nameof(RachisLogHistory.LogHistoryColumn.Type)]?.ToString() == nameof(PutRollingIndexCommand) &&
djv[nameof(RachisLogHistory.LogHistoryColumn.State)]?.ToString() == "Committed");
Assert.True(contain);
}
}

private class SomeRollingIndex : AbstractIndexCreationTask<Order>
{
public SomeRollingIndex()
{
Map = orders => from order in orders
select new
{
order.Company,
};

DeploymentMode = IndexDeploymentMode.Rolling;
}
}

}

0 comments on commit f4371af

Please sign in to comment.