2
0
mirror of synced 2025-02-21 04:28:13 +00:00

86 lines
3.0 KiB
C#
Raw Normal View History

2023-04-26 14:40:54 +02:00
using DistTestCore;
using DistTestCore.Codex;
using NUnit.Framework;
namespace Tests.BasicTests
{
[TestFixture]
public class PeerTests : DistTest
{
[Test]
public void TwoNodes()
{
var primary = SetupCodexBootstrapNode();
2023-04-26 14:40:54 +02:00
var secondary = SetupCodexNode(s => s.WithBootstrapNode(primary));
2023-04-30 11:10:38 +02:00
primary.ConnectToPeer(secondary); // TODO REMOVE THIS: This is required for the switchPeers to show up.
2023-04-30 10:08:32 +02:00
// This is required for the enginePeers to show up.
//var file = GenerateTestFile(10.MB());
//var contentId = primary.UploadFile(file);
//var file2 = secondary.DownloadContent(contentId);
//file.AssertIsEqual(file2);
2023-04-26 14:40:54 +02:00
AssertKnowEachother(primary, secondary);
}
[TestCase(2)]
[TestCase(3)]
[TestCase(10)]
public void VariableNodes(int number)
{
var bootstrap = SetupCodexBootstrapNode();
2023-04-26 14:40:54 +02:00
var nodes = SetupCodexNodes(number, s => s.WithBootstrapNode(bootstrap));
2023-04-30 10:08:32 +02:00
var file = GenerateTestFile(10.MB());
var contentId = nodes.First().UploadFile(file);
var file2 = nodes.Last().DownloadContent(contentId);
file.AssertIsEqual(file2);
2023-04-30 11:10:38 +02:00
// <TODO REMOVE THIS>
2023-04-30 10:08:32 +02:00
foreach (var node in nodes) bootstrap.ConnectToPeer(node);
2023-04-30 11:10:38 +02:00
for (var x = 0; x < number; x++)
{
for (var y = x + 1; y < number; y++)
{
nodes[x].ConnectToPeer(nodes[y]);
}
}
// </TODO REMOVE THIS>
2023-04-30 10:08:32 +02:00
2023-04-26 14:40:54 +02:00
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)
{
2023-04-30 10:08:32 +02:00
//var enginePeers = string.Join(",", a.enginePeers.Select(p => p.peerId));
2023-04-26 15:31:01 +02:00
var switchPeers = string.Join(",", a.switchPeers.Select(p => p.peerId));
2023-04-26 14:40:54 +02:00
2023-05-04 15:21:36 +02:00
//Debug($"Looking for {b.id} in engine-peers [{enginePeers}]");
Debug($"{a.id} is looking for {b.id} in switch-peers [{switchPeers}]");
2023-04-26 15:31:01 +02:00
//Assert.That(a.enginePeers.Any(p => p.peerId == b.id), $"{a.id} was looking for '{b.id}' in engine-peers [{enginePeers}] but it was not found.");
Assert.That(a.switchPeers.Any(p => p.peerId == b.id), $"{a.id} was looking for '{b.id}' in switch-peers [{switchPeers}] but it was not found.");
2023-04-26 14:40:54 +02:00
}
}
}