diff --git a/DistTestCore/Codex/CodexAccess.cs b/DistTestCore/Codex/CodexAccess.cs index 00affc2..5a8d472 100644 --- a/DistTestCore/Codex/CodexAccess.cs +++ b/DistTestCore/Codex/CodexAccess.cs @@ -24,7 +24,7 @@ namespace DistTestCore.Codex public CodexDebugPeerResponse GetDebugPeer(string peerId) { - return Http().HttpGetJson($"debug/peer/{peerId}"); + return Http(TimeSpan.FromSeconds(2)).HttpGetJson($"debug/peer/{peerId}"); } public string UploadFile(FileStream fileStream) diff --git a/DistTestCore/Http.cs b/DistTestCore/Http.cs index a4feeb8..a83df8a 100644 --- a/DistTestCore/Http.cs +++ b/DistTestCore/Http.cs @@ -1,6 +1,5 @@ using Logging; using Newtonsoft.Json; -using NUnit.Framework; using System.Net.Http.Headers; using System.Net.Http.Json; using Utils; @@ -120,7 +119,6 @@ namespace DistTestCore catch (Exception exception) { var msg = $"Failed to deserialize JSON: '{json}' with exception: {exception}"; - Assert.Fail(msg); throw new InvalidOperationException(msg, exception); } } diff --git a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 9d5c735..a2f3ed4 100644 --- a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -6,14 +6,6 @@ namespace Tests.PeerDiscoveryTests [TestFixture] public class PeerDiscoveryTests : AutoBootstrapDistTest { - [Test] - public void TwoNodes() - { - SetupCodexNode(); - - AssertAllNodesConnected(); - } - [TestCase(2)] [TestCase(3)] [TestCase(10)] @@ -37,6 +29,19 @@ namespace Tests.PeerDiscoveryTests AssertAllNodesConnected(); } + [TestCase(3, 3)] + [TestCase(3, 5)] + [TestCase(3, 10)] + public void StagedVariableNodes(int numberOfNodes, int numberOfStages) + { + for (var i = 0; i < numberOfStages; i++) + { + SetupCodexNodes(numberOfNodes); + + AssertAllNodesConnected(); + } + } + private void AssertAllNodesConnected() { PeerTestHelpers.AssertFullyConnected(GetAllOnlineCodexNodes(), GetTestLog()); diff --git a/Tests/PeerDiscoveryTests/PeerTestHelpers.cs b/Tests/PeerDiscoveryTests/PeerTestHelpers.cs index 8b09fa6..99a6cbb 100644 --- a/Tests/PeerDiscoveryTests/PeerTestHelpers.cs +++ b/Tests/PeerDiscoveryTests/PeerTestHelpers.cs @@ -31,35 +31,57 @@ namespace Tests.PeerDiscoveryTests private static void AssertKnowEachother(List failureMessags, Entry a, Entry b, BaseLog? log) { - AssertKnows(failureMessags, a, b, log); - AssertKnows(failureMessags, b, a, log); + var aKnowsB = Knows(a, b); + var bKnowsA = Knows(b, a); + + var message = GetMessage(a, b, aKnowsB, bKnowsA); + + if (log != null) log.Log(message); + if (!aKnowsB || !bKnowsA) failureMessags.Add(message); } - private static void AssertKnows(List failureMessags, Entry a, Entry b, BaseLog? log) + private static string GetMessage(Entry a, Entry b, bool aKnowsB, bool bKnowsA) + { + var aName = a.Response.id; + var bName = b.Response.id; + + if (aKnowsB && bKnowsA) + { + return $"{aName} and {bName} know each other."; + } + if (aKnowsB) + { + return $"{aName} knows {bName}, but {bName} does not know {aName}"; + } + if (bKnowsA) + { + return $"{bName} knows {aName}, but {aName} does not know {bName}"; + } + return $"{aName} and {bName} don't know each other."; + } + + private static bool Knows(Entry a, Entry b) { var peerId = b.Response.id; try { var response = GetDebugPeer(a.Node, peerId); - if (string.IsNullOrEmpty(response.peerId) || !response.addresses.Any()) + if (!string.IsNullOrEmpty(response.peerId) && response.addresses.Any()) { - failureMessags.Add($"{a.Response.id} did not know peer {peerId}"); - } - else if (log != null) - { - log.Log($"{a.Response.id} knows {peerId}."); + return true; } } catch { - failureMessags.Add($"{a.Response.id} was unable to get 'debug/peer/{peerId}'."); } + + return false; } private static CodexDebugPeerResponse GetDebugPeer(IOnlineCodexNode node, string peerId) { - return Time.Retry(() => node.GetDebugPeer(peerId)); + return Time.Retry(() => node.GetDebugPeer(peerId), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(0.1)); } public class Entry