Bonus: sets up peer-tests
This commit is contained in:
parent
ef546a435b
commit
1c9e59a6ea
@ -55,9 +55,31 @@ namespace DistTestCore.Codex
|
||||
public string[] addrs { get; set; } = new string[0];
|
||||
public string repo { get; set; } = string.Empty;
|
||||
public string spr { get; set; } = string.Empty;
|
||||
public EnginePeerResponse[] enginePeers { get; set; } = Array.Empty<EnginePeerResponse>();
|
||||
public SwitchPeerResponse[] switchPeers { get; set; } = Array.Empty<SwitchPeerResponse>();
|
||||
public CodexDebugVersionResponse codex { get; set; } = new();
|
||||
}
|
||||
|
||||
public class EnginePeerResponse
|
||||
{
|
||||
public string peerId { get; set; } = string.Empty;
|
||||
public EnginePeerContextResponse context { get; set; } = new();
|
||||
}
|
||||
|
||||
public class EnginePeerContextResponse
|
||||
{
|
||||
public int blocks { get; set; } = 0;
|
||||
public int peerWants { get; set; } = 0;
|
||||
public int exchanged { get; set; } = 0;
|
||||
public string lastExchange { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class SwitchPeerResponse
|
||||
{
|
||||
public string peerId { get; set; } = string.Empty;
|
||||
public string key { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class CodexDebugVersionResponse
|
||||
{
|
||||
public string version { get; set; } = string.Empty;
|
||||
|
@ -106,6 +106,11 @@ namespace DistTestCore
|
||||
return lifecycle.CodexStarter.BringOnline((CodexSetup)codexSetup);
|
||||
}
|
||||
|
||||
protected BaseLog Log
|
||||
{
|
||||
get { return lifecycle.Log; }
|
||||
}
|
||||
|
||||
private void CreateNewTestLifecycle()
|
||||
{
|
||||
Stopwatch.Measure(fixtureLog, $"Setup for {GetCurrentTestName()}", () =>
|
||||
|
58
Tests/BasicTests/PeerTests.cs
Normal file
58
Tests/BasicTests/PeerTests.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using DistTestCore;
|
||||
using DistTestCore.Codex;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests.BasicTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PeerTests : DistTest
|
||||
{
|
||||
[Test]
|
||||
public void TwoNodes()
|
||||
{
|
||||
var primary = SetupCodexNode();
|
||||
var secondary = SetupCodexNode(s => s.WithBootstrapNode(primary));
|
||||
|
||||
AssertKnowEachother(primary, secondary);
|
||||
}
|
||||
|
||||
[TestCase(2)]
|
||||
[TestCase(3)]
|
||||
[TestCase(10)]
|
||||
public void VariableNodes(int number)
|
||||
{
|
||||
var bootstrap = SetupCodexNode();
|
||||
var nodes = SetupCodexNodes(number, s => s.WithBootstrapNode(bootstrap));
|
||||
|
||||
foreach (var node in nodes) AssertKnowEachother(node, bootstrap);
|
||||
|
||||
for (var x = 0; x < number; x++)
|
||||
{
|
||||
for (var y = x + 1; y < number; y++)
|
||||
{
|
||||
AssertKnowEachother(nodes[x], nodes[y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AssertKnowEachother(IOnlineCodexNode a, IOnlineCodexNode b)
|
||||
{
|
||||
AssertKnowEachother(a.GetDebugInfo(), b.GetDebugInfo());
|
||||
}
|
||||
|
||||
private void AssertKnowEachother(CodexDebugResponse a, CodexDebugResponse b)
|
||||
{
|
||||
AssertKnows(a, b);
|
||||
AssertKnows(b, a);
|
||||
}
|
||||
|
||||
private void AssertKnows(CodexDebugResponse a, CodexDebugResponse b)
|
||||
{
|
||||
Log.Debug($"Looking for {b.id} in engine-peers [{string.Join(",", a.enginePeers.Select(p => p.peerId))}]");
|
||||
Log.Debug($"Looking for {b.id} in switch-peers [{string.Join(",", a.switchPeers.Select(p => p.peerId))}]");
|
||||
|
||||
Assert.That(a.enginePeers.Any(p => p.peerId == b.id), "Expected peerId not found in engine-peers");
|
||||
Assert.That(a.switchPeers.Any(p => p.peerId == b.id), "Expected peerId not found in switch-peers");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user