Skip to content

Commit

Permalink
RavenDB-20808 fix test base
Browse files Browse the repository at this point in the history
  • Loading branch information
karmeli87 authored and ppekrol committed Jul 7, 2023
1 parent 840e9de commit b39aa49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions test/Tests.Infrastructure/RavenTestBase.Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ public string GetRaftHistory(RavenServer server)
return sb.ToString();
}

public async Task WaitForRaftIndexToBeAppliedInClusterAsyncWithoutValidation(long index, TimeSpan? timeout = null, List<RavenServer> nodes = null)
public async Task WaitForRaftIndexToBeAppliedInClusterAsync(long index, TimeSpan? timeout = null, List<RavenServer> nodes = null)
{
await WaitForRaftIndexToBeAppliedOnClusterNodesAsync(index, nodes ?? _parent.Servers, timeout);
}

public async Task WaitForRaftIndexToBeAppliedInClusterAsync(long index, TimeSpan? timeout = null, List<RavenServer> nodes = null)
public async Task WaitForRaftIndexToBeAppliedInClusterWithNodesValidationAsync(long index, TimeSpan? timeout = null, List<RavenServer> nodes = null)
{
var servers = nodes ?? _parent.Servers;
var notDisposed = servers.Count(s => s.ServerStore.Disposed == false);
Expand Down
9 changes: 6 additions & 3 deletions test/Tests.Infrastructure/RavenTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ protected virtual DocumentStore GetDocumentStore(Options options = null, [Caller
};

options.ModifyDocumentStore?.Invoke(store);
store.Urls = GetUrls(serverToUse, store.Conventions.DisableTopologyUpdates);
if (store.Urls.Length == 0)
{
store.Urls = GetUrls(serverToUse, store.Conventions.DisableTopologyUpdates);
}

store.Initialize();

Expand All @@ -261,7 +264,7 @@ protected virtual DocumentStore GetDocumentStore(Options options = null, [Caller
if (servers.Count > 1)
{
var timeout = TimeSpan.FromMinutes(Debugger.IsAttached ? 5 : 1);
AsyncHelpers.RunSync(async () => await Cluster.WaitForRaftIndexToBeAppliedInClusterAsyncWithoutValidation(raftCommand, timeout, servers));
AsyncHelpers.RunSync(async () => await Cluster.WaitForRaftIndexToBeAppliedInClusterWithNodesValidationAsync(raftCommand, timeout, servers));
}

// skip 'wait for requests' on DocumentDatabase dispose
Expand Down Expand Up @@ -295,7 +298,7 @@ protected virtual DocumentStore GetDocumentStore(Options options = null, [Caller
if (servers.Count > 1 && result != null)
{
var timeout = options.DeleteTimeout ?? TimeSpan.FromSeconds(Debugger.IsAttached ? 150 : 15);
AsyncHelpers.RunSync(async () => await Cluster.WaitForRaftIndexToBeAppliedInClusterAsyncWithoutValidation(result.RaftCommandIndex, timeout, servers));
AsyncHelpers.RunSync(async () => await Cluster.WaitForRaftIndexToBeAppliedInClusterAsync(result.RaftCommandIndex, timeout, servers));
}
}
catch (Exception e)
Expand Down
8 changes: 1 addition & 7 deletions test/Tests.Infrastructure/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ public List<RavenServer> GetServers()

public IEnumerable<RavenServer> GetServersInCluster(RavenServer server)
{
if (Servers.Count == 0)
{
yield return server;
yield break;
}

var topology = server.ServerStore.GetClusterTopology().TopologyId;
foreach (var s in Servers)
{
Expand Down Expand Up @@ -593,7 +587,7 @@ protected static string[] UseFiddler(string url)

protected string[] GetUrls(RavenServer serverToUse, bool disableTopologyUpdates = false)
{
if (disableTopologyUpdates)
if (disableTopologyUpdates || Servers.Count == 0 || Servers.Contains(serverToUse) == false)
return UseFiddler(serverToUse.WebUrl);

return GetServersInCluster(serverToUse).Select(s => UseFiddlerUrl(s.WebUrl)).ToArray();
Expand Down

0 comments on commit b39aa49

Please sign in to comment.