cs-codex-dist-tests/Tests/ExperimentalTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs

56 lines
1.7 KiB
C#
Raw Permalink Normal View History

2024-06-12 13:28:08 +00:00
using CodexPlugin;
using NUnit.Framework;
2023-09-12 13:43:30 +00:00
2023-11-12 09:36:48 +00:00
namespace CodexTests.PeerDiscoveryTests
2023-09-12 13:43:30 +00:00
{
[TestFixture]
2023-09-13 12:24:43 +00:00
public class LayeredDiscoveryTests : CodexDistTest
2023-09-12 13:43:30 +00:00
{
[Test]
public void TwoLayersTest()
{
2024-05-09 07:32:48 +00:00
var root = StartCodex();
var l1Source = StartCodex(s => s.WithBootstrapNode(root));
var l1Node = StartCodex(s => s.WithBootstrapNode(root));
var l2Target = StartCodex(s => s.WithBootstrapNode(l1Node));
2023-09-12 13:43:30 +00:00
2024-06-12 13:28:08 +00:00
AssertAllNodesConnected(root, l1Source, l1Node, l2Target);
2023-09-12 13:43:30 +00:00
}
[Test]
public void ThreeLayersTest()
{
2024-05-09 07:32:48 +00:00
var root = StartCodex();
var l1Source = StartCodex(s => s.WithBootstrapNode(root));
var l1Node = StartCodex(s => s.WithBootstrapNode(root));
var l2Node = StartCodex(s => s.WithBootstrapNode(l1Node));
var l3Target = StartCodex(s => s.WithBootstrapNode(l2Node));
2023-09-12 13:43:30 +00:00
2024-06-12 13:28:08 +00:00
AssertAllNodesConnected(root, l1Source, l1Node, l2Node, l3Target);
2023-09-12 13:43:30 +00:00
}
[TestCase(3)]
[TestCase(5)]
[TestCase(10)]
public void NodeChainTest(int chainLength)
{
2024-06-12 13:28:08 +00:00
var nodes = new List<ICodexNode>();
2024-05-09 07:32:48 +00:00
var node = StartCodex();
2024-06-12 13:28:08 +00:00
nodes.Add(node);
2023-09-12 13:43:30 +00:00
for (var i = 1; i < chainLength; i++)
{
2024-05-09 07:32:48 +00:00
node = StartCodex(s => s.WithBootstrapNode(node));
2024-06-12 13:28:08 +00:00
nodes.Add(node);
2023-09-12 13:43:30 +00:00
}
2024-06-12 13:28:08 +00:00
AssertAllNodesConnected(nodes.ToArray());
2023-09-12 13:43:30 +00:00
}
2024-06-12 13:28:08 +00:00
private void AssertAllNodesConnected(params ICodexNode[] nodes)
2023-09-12 13:43:30 +00:00
{
2024-06-12 13:28:08 +00:00
CreatePeerConnectionTestHelpers().AssertFullyConnected(nodes);
2023-09-12 13:43:30 +00:00
}
}
}