Cleanup of full-connectivity helper.

This commit is contained in:
benbierens 2023-08-24 10:59:11 +02:00
parent 3c94727101
commit 7eda26d177
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
8 changed files with 44 additions and 30 deletions

View File

@ -30,14 +30,8 @@ namespace DistTestCore
var startTime = DateTime.UtcNow; var startTime = DateTime.UtcNow;
fixtureLog = new FixtureLog(logConfig, startTime); fixtureLog = new FixtureLog(logConfig, startTime);
statusLog = new StatusLog(logConfig, startTime); statusLog = new StatusLog(logConfig, startTime);
PeerConnectionTestHelpers = new PeerConnectionTestHelpers(this);
PeerDownloadTestHelpers = new PeerDownloadTestHelpers(this);
} }
public PeerConnectionTestHelpers PeerConnectionTestHelpers { get; }
public PeerDownloadTestHelpers PeerDownloadTestHelpers { get; }
[OneTimeSetUp] [OneTimeSetUp]
public void GlobalSetup() public void GlobalSetup()
{ {
@ -175,6 +169,16 @@ namespace DistTestCore
GetTestLog().Debug(msg); GetTestLog().Debug(msg);
} }
public PeerConnectionTestHelpers CreatePeerConnectionTestHelpers()
{
return new PeerConnectionTestHelpers(GetTestLog());
}
public PeerDownloadTestHelpers CreatePeerDownloadTestHelpers()
{
return new PeerDownloadTestHelpers(GetTestLog(), Get().FileManager);
}
public void Measure(string name, Action action) public void Measure(string name, Action action)
{ {
Stopwatch.Measure(Get().Log, name, action); Stopwatch.Measure(Get().Log, name, action);

View File

@ -1,4 +1,5 @@
using DistTestCore.Codex; using DistTestCore.Codex;
using Logging;
using NUnit.Framework; using NUnit.Framework;
using Utils; using Utils;
@ -14,12 +15,12 @@ namespace DistTestCore.Helpers
public class FullConnectivityHelper public class FullConnectivityHelper
{ {
private static string Nl = Environment.NewLine; private static string Nl = Environment.NewLine;
private readonly DistTest test; private readonly BaseLog log;
private readonly IFullConnectivityImplementation implementation; private readonly IFullConnectivityImplementation implementation;
public FullConnectivityHelper(DistTest test, IFullConnectivityImplementation implementation) public FullConnectivityHelper(BaseLog log, IFullConnectivityImplementation implementation)
{ {
this.test = test; this.log = log;
this.implementation = implementation; this.implementation = implementation;
} }
@ -30,7 +31,7 @@ namespace DistTestCore.Helpers
private void AssertFullyConnected(IOnlineCodexNode[] nodes) private void AssertFullyConnected(IOnlineCodexNode[] nodes)
{ {
test.Log($"Asserting '{implementation.Description()}' for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'..."); Log($"Asserting '{implementation.Description()}' for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'...");
var entries = CreateEntries(nodes); var entries = CreateEntries(nodes);
var pairs = CreatePairs(entries); var pairs = CreatePairs(entries);
@ -43,13 +44,13 @@ namespace DistTestCore.Helpers
{ {
var pairDetails = string.Join(Nl, pairs.SelectMany(p => p.GetResultMessages())); var pairDetails = string.Join(Nl, pairs.SelectMany(p => p.GetResultMessages()));
test.Log($"Connections failed:{Nl}{pairDetails}"); Log($"Connections failed:{Nl}{pairDetails}");
Assert.Fail(string.Join(Nl, pairs.SelectMany(p => p.GetResultMessages()))); Assert.Fail(string.Join(Nl, pairs.SelectMany(p => p.GetResultMessages())));
} }
else else
{ {
test.Log($"'{implementation.Description()}' = Success! for nodes: {string.Join(",", nodes.Select(n => n.GetName()))}"); Log($"'{implementation.Description()}' = Success! for nodes: {string.Join(",", nodes.Select(n => n.GetName()))}");
} }
} }
@ -72,7 +73,7 @@ namespace DistTestCore.Helpers
foreach (var pair in selectedPair) foreach (var pair in selectedPair)
{ {
test.ScopedTestFiles(pair.Check); pair.Check();
if (pair.Success) if (pair.Success)
{ {
@ -81,7 +82,7 @@ namespace DistTestCore.Helpers
} }
} }
test.Log($"Connections successful:{Nl}{string.Join(Nl, pairDetails)}"); Log($"Connections successful:{Nl}{string.Join(Nl, pairDetails)}");
} }
private Entry[] CreateEntries(IOnlineCodexNode[] nodes) private Entry[] CreateEntries(IOnlineCodexNode[] nodes)
@ -117,6 +118,11 @@ namespace DistTestCore.Helpers
} }
} }
private void Log(string msg)
{
log.Log(msg);
}
public class Entry public class Entry
{ {
public Entry(IOnlineCodexNode node) public Entry(IOnlineCodexNode node)

View File

@ -1,4 +1,5 @@
using DistTestCore.Codex; using DistTestCore.Codex;
using Logging;
using static DistTestCore.Helpers.FullConnectivityHelper; using static DistTestCore.Helpers.FullConnectivityHelper;
namespace DistTestCore.Helpers namespace DistTestCore.Helpers
@ -7,9 +8,9 @@ namespace DistTestCore.Helpers
{ {
private readonly FullConnectivityHelper helper; private readonly FullConnectivityHelper helper;
public PeerConnectionTestHelpers(DistTest test) public PeerConnectionTestHelpers(BaseLog log)
{ {
helper = new FullConnectivityHelper(test, this); helper = new FullConnectivityHelper(log, this);
} }
public void AssertFullyConnected(IEnumerable<IOnlineCodexNode> nodes) public void AssertFullyConnected(IEnumerable<IOnlineCodexNode> nodes)

View File

@ -1,18 +1,19 @@
using static DistTestCore.Helpers.FullConnectivityHelper; using Logging;
using static DistTestCore.Helpers.FullConnectivityHelper;
namespace DistTestCore.Helpers namespace DistTestCore.Helpers
{ {
public class PeerDownloadTestHelpers : IFullConnectivityImplementation public class PeerDownloadTestHelpers : IFullConnectivityImplementation
{ {
private readonly FullConnectivityHelper helper; private readonly FullConnectivityHelper helper;
private readonly DistTest test; private readonly FileManager fileManager;
private ByteSize testFileSize; private ByteSize testFileSize;
public PeerDownloadTestHelpers(DistTest test) public PeerDownloadTestHelpers(BaseLog log, FileManager fileManager)
{ {
helper = new FullConnectivityHelper(test, this); helper = new FullConnectivityHelper(log, this);
testFileSize = 1.MB(); testFileSize = 1.MB();
this.test = test; this.fileManager = fileManager;
} }
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes, ByteSize testFileSize) public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes, ByteSize testFileSize)
@ -33,6 +34,7 @@ namespace DistTestCore.Helpers
public PeerConnectionState Check(Entry from, Entry to) public PeerConnectionState Check(Entry from, Entry to)
{ {
fileManager.PushFileSet();
var expectedFile = GenerateTestFile(from.Node, to.Node); var expectedFile = GenerateTestFile(from.Node, to.Node);
var contentId = from.Node.UploadFile(expectedFile); var contentId = from.Node.UploadFile(expectedFile);
@ -49,6 +51,10 @@ namespace DistTestCore.Helpers
// We consider that as no-connection for the purpose of this test. // We consider that as no-connection for the purpose of this test.
return PeerConnectionState.NoConnection; return PeerConnectionState.NoConnection;
} }
finally
{
fileManager.PopFileSet();
}
// Should an exception occur during upload, then this try is inconclusive and we try again next loop. // Should an exception occur during upload, then this try is inconclusive and we try again next loop.
} }
@ -58,7 +64,7 @@ namespace DistTestCore.Helpers
var up = uploader.GetName().Replace("<", "").Replace(">", ""); var up = uploader.GetName().Replace("<", "").Replace(">", "");
var down = downloader.GetName().Replace("<", "").Replace(">", ""); var down = downloader.GetName().Replace("<", "").Replace(">", "");
var label = $"~from:{up}-to:{down}~"; var label = $"~from:{up}-to:{down}~";
return test.GenerateTestFile(testFileSize, label); return fileManager.GenerateTestFile(testFileSize, label);
} }
} }
} }

View File

@ -1,5 +1,4 @@
using DistTestCore.Helpers; using DistTestCore;
using DistTestCore;
using NUnit.Framework; using NUnit.Framework;
namespace TestsLong.DownloadConnectivityTests namespace TestsLong.DownloadConnectivityTests
@ -16,7 +15,7 @@ namespace TestsLong.DownloadConnectivityTests
{ {
for (var i = 0; i < numberOfNodes; i++) SetupCodexNode(); for (var i = 0; i < numberOfNodes; i++) SetupCodexNode();
PeerDownloadTestHelpers.AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB()); CreatePeerDownloadTestHelpers().AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB());
} }
} }
} }

View File

@ -14,7 +14,7 @@ namespace Tests.DownloadConnectivityTests
{ {
for (var i = 0; i < numberOfNodes; i++) SetupCodexNode(); for (var i = 0; i < numberOfNodes; i++) SetupCodexNode();
PeerDownloadTestHelpers.AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB()); CreatePeerDownloadTestHelpers().AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB());
} }
} }
} }

View File

@ -1,5 +1,4 @@
using DistTestCore; using DistTestCore;
using DistTestCore.Helpers;
using NUnit.Framework; using NUnit.Framework;
namespace Tests.PeerDiscoveryTests namespace Tests.PeerDiscoveryTests
@ -47,7 +46,7 @@ namespace Tests.PeerDiscoveryTests
private void AssertAllNodesConnected() private void AssertAllNodesConnected()
{ {
PeerConnectionTestHelpers.AssertFullyConnected(GetAllOnlineCodexNodes()); CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes());
} }
} }
} }

View File

@ -1,5 +1,4 @@
using DistTestCore; using DistTestCore;
using DistTestCore.Helpers;
using NUnit.Framework; using NUnit.Framework;
namespace Tests.PeerDiscoveryTests namespace Tests.PeerDiscoveryTests
@ -33,7 +32,7 @@ namespace Tests.PeerDiscoveryTests
private void AssertAllNodesConnected() private void AssertAllNodesConnected()
{ {
PeerConnectionTestHelpers.AssertFullyConnected(GetAllOnlineCodexNodes()); CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes());
} }
} }
} }