Update to full connectivity helper

This commit is contained in:
benbierens 2023-09-08 15:43:10 +02:00
parent d074f64c42
commit a5749824fb
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 7 additions and 25 deletions

View File

@ -1,7 +1,6 @@
using DistTestCore.Codex; using DistTestCore.Codex;
using Logging; using Logging;
using NUnit.Framework; using NUnit.Framework;
using Utils;
namespace DistTestCore.Helpers namespace DistTestCore.Helpers
{ {
@ -35,10 +34,9 @@ namespace DistTestCore.Helpers
var entries = CreateEntries(nodes); var entries = CreateEntries(nodes);
var pairs = CreatePairs(entries); var pairs = CreatePairs(entries);
RetryWhilePairs(pairs, () => // Each pair gets two chances.
{ CheckAndRemoveSuccessful(pairs);
CheckAndRemoveSuccessful(pairs); CheckAndRemoveSuccessful(pairs);
});
if (pairs.Any()) if (pairs.Any())
{ {
@ -54,35 +52,19 @@ namespace DistTestCore.Helpers
} }
} }
private static void RetryWhilePairs(List<Pair> pairs, Action action)
{
var timeout = DateTime.UtcNow + TimeSpan.FromMinutes(2);
while (pairs.Any(p => p.Inconclusive) && timeout > DateTime.UtcNow)
{
action();
Time.Sleep(TimeSpan.FromSeconds(2));
}
}
private void CheckAndRemoveSuccessful(List<Pair> pairs) private void CheckAndRemoveSuccessful(List<Pair> pairs)
{ {
// For large sets, don't try and do all of them at once. var results = new List<string>();
var selectedPair = pairs.Take(20).ToArray(); foreach (var pair in pairs.ToArray())
var pairDetails = new List<string>();
foreach (var pair in selectedPair)
{ {
pair.Check(); pair.Check();
if (pair.Success) if (pair.Success)
{ {
pairDetails.AddRange(pair.GetResultMessages()); results.AddRange(pair.GetResultMessages());
pairs.Remove(pair); pairs.Remove(pair);
} }
} }
Log($"Connections successful:{Nl}{string.Join(Nl, results)}");
Log($"Connections successful:{Nl}{string.Join(Nl, pairDetails)}");
} }
private Entry[] CreateEntries(CodexAccess[] nodes) private Entry[] CreateEntries(CodexAccess[] nodes)