2
0
mirror of synced 2025-01-11 09:06:56 +00:00

Bonus: sets up peer-tests

This commit is contained in:
benbierens 2023-04-26 14:40:54 +02:00
parent ef546a435b
commit 1c9e59a6ea
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 85 additions and 0 deletions

View File

@ -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;

View File

@ -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()}", () =>

View 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");
}
}
}