adds block exchange tests. Updates namespaces

This commit is contained in:
benbierens 2023-10-09 16:59:52 +02:00
parent 7aae48d489
commit b81d574a4b
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
20 changed files with 99 additions and 22 deletions

View File

@ -1,6 +1,7 @@
using CodexPlugin;
using FileUtils;
using Logging;
using Newtonsoft.Json;
using NUnit.Framework;
using Utils;
@ -21,6 +22,9 @@ namespace ContinuousTests.Tests
[TestMoment(t: Zero)]
public void UploadTestFile()
{
LogBlockExchangeStatus(Nodes[0], "Before upload");
LogBlockExchangeStatus(Nodes[1], "Before upload");
file = FileManager.GenerateFile(size);
LogStoredBytes(Nodes[0]);
@ -37,6 +41,9 @@ namespace ContinuousTests.Tests
LogBytesPerMillisecond(() => dl = Nodes[1].DownloadContent(cid!));
file.AssertIsEqual(dl);
LogBlockExchangeStatus(Nodes[0], "After download");
LogBlockExchangeStatus(Nodes[1], "After download");
}
private void LogStoredBytes(ICodexNode node)
@ -65,5 +72,11 @@ namespace ContinuousTests.Tests
var bytesPerMs = totalBytes / totalMs;
Log.Log($"Bytes per millisecond: {bytesPerMs}");
}
private void LogBlockExchangeStatus(ICodexNode codexNode, string msg)
{
var response = codexNode.GetDebugBlockExchange();
Log.Log($"{codexNode.GetName()} {msg}: {JsonConvert.SerializeObject(response)}");
}
}
}

View File

@ -1,7 +1,7 @@
using CodexTests;
using DistTestCore;
using FileUtils;
using NUnit.Framework;
using Tests;
using Utils;
namespace CodexLongTests.BasicTests

View File

@ -1,8 +1,8 @@
using CodexPlugin;
using CodexTests;
using DistTestCore;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using Tests;
using Utils;
namespace CodexLongTests.BasicTests

View File

@ -1,6 +1,6 @@
using DistTestCore;
using CodexTests;
using DistTestCore;
using NUnit.Framework;
using Tests;
namespace CodexLongTests.BasicTests
{

View File

@ -1,8 +1,8 @@
using CodexPlugin;
using CodexTests;
using DistTestCore;
using FileUtils;
using NUnit.Framework;
using Tests;
using Utils;
namespace CodexLongTests.BasicTests

View File

@ -1,6 +1,6 @@
using DistTestCore;
using CodexTests;
using DistTestCore;
using NUnit.Framework;
using Tests;
using Utils;
namespace CodexLongTests.DownloadConnectivityTests

View File

@ -1,7 +1,7 @@
using CodexPlugin;
using NUnit.Framework;
namespace Tests
namespace CodexTests
{
public class AutoBootstrapDistTest : CodexDistTest
{

View File

@ -0,0 +1,62 @@
using CodexPlugin;
using NUnit.Framework;
using Utils;
namespace CodexTests.BasicTests
{
[TestFixture]
public class BlockExchangeTests : CodexDistTest
{
[Test]
public void EmptyAfterExchange()
{
var bootstrap = AddCodex(s => s.WithName("bootstrap"));
var node = AddCodex(s => s.WithName("node").WithBootstrapNode(bootstrap));
AssertExchangeIsEmpty(bootstrap, node);
var file = GenerateTestFile(1.MB());
var cid = bootstrap.UploadFile(file);
node.DownloadContent(cid);
AssertExchangeIsEmpty(bootstrap, node);
}
[Test]
public void EmptyAfterExchangeWithBystander()
{
var bootstrap = AddCodex(s => s.WithName("bootstrap"));
var node = AddCodex(s => s.WithName("node").WithBootstrapNode(bootstrap));
var bystander = AddCodex(s => s.WithName("bystander").WithBootstrapNode(bootstrap));
AssertExchangeIsEmpty(bootstrap, node, bystander);
var file = GenerateTestFile(1.MB());
var cid = bootstrap.UploadFile(file);
node.DownloadContent(cid);
AssertExchangeIsEmpty(bootstrap, node, bystander);
}
private void AssertExchangeIsEmpty(params ICodexNode[] nodes)
{
foreach (var node in nodes)
{
Time.Retry(() => AssertBlockExchangeIsEmpty(node), nameof(AssertExchangeIsEmpty));
}
}
private void AssertBlockExchangeIsEmpty(ICodexNode node)
{
var msg = $"BlockExchange for {node.GetName()}: ";
var response = node.GetDebugBlockExchange();
foreach (var peer in response.peers)
{
var activeWants = peer.wants.Where(w => !w.cancel).ToArray();
Assert.That(activeWants.Length, Is.EqualTo(0), msg + "thinks a peer has active wants.");
}
Assert.That(response.taskQueue, Is.EqualTo(0), msg + "has tasks in queue.");
Assert.That(response.pendingBlocks, Is.EqualTo(0), msg + "has pending blocks.");
}
}
}

View File

@ -7,7 +7,7 @@ using MetricsPlugin;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
namespace CodexTests.BasicTests
{
[Ignore("Used for debugging continuous tests")]
[TestFixture]
@ -87,7 +87,7 @@ namespace Tests.BasicTests
//CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes());
//CheckRoutingTables(GetAllOnlineCodexNodes());
var node = RandomUtils.PickOneRandom(nodes.ToList());
var node = nodes.ToList().PickOneRandom();
var file = GenerateTestFile(50.MB());
node.UploadFile(file);

View File

@ -6,7 +6,7 @@ using MetricsPlugin;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
namespace CodexTests.BasicTests
{
[TestFixture]
public class ExampleTests : CodexDistTest

View File

@ -3,7 +3,7 @@ using DistTestCore;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
namespace CodexTests.BasicTests
{
// Warning!
// This is a test to check network-isolation in the test-infrastructure.

View File

@ -3,7 +3,7 @@ using DistTestCore;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
namespace CodexTests.BasicTests
{
[TestFixture]
public class OneClientTests : DistTest

View File

@ -1,8 +1,7 @@
using DistTestCore;
using NUnit.Framework;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
namespace CodexTests.BasicTests
{
[TestFixture]
public class ThreeClientTest : AutoBootstrapDistTest

View File

@ -3,7 +3,7 @@ using DistTestCore;
using NUnit.Framework;
using Utils;
namespace Tests.BasicTests
namespace CodexTests.BasicTests
{
[TestFixture]
public class TwoClientTests : DistTest

View File

@ -9,7 +9,7 @@ using GethPlugin;
using NUnit.Framework;
using NUnit.Framework.Constraints;
namespace Tests
namespace CodexTests
{
public class CodexDistTest : DistTest
{

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin;
using CodexTests;
using GethPlugin;
using NUnit.Framework;
using Utils;

View File

@ -3,7 +3,7 @@ using Logging;
using MetricsPlugin;
using NUnit.Framework.Constraints;
namespace Tests
namespace CodexTests
{
public static class MetricsAccessExtensions
{

View File

@ -1,6 +1,6 @@
using NUnit.Framework;
[assembly: LevelOfParallelism(1)]
namespace Tests
namespace CodexTests
{
}

View File

@ -1,4 +1,5 @@
using CodexPlugin;
using CodexTests;
using NUnit.Framework;
namespace Tests.PeerDiscoveryTests

View File

@ -1,4 +1,5 @@
using CodexContractsPlugin;
using CodexTests;
using GethPlugin;
using NUnit.Framework;