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;
fixtureLog = new FixtureLog(logConfig, startTime);
statusLog = new StatusLog(logConfig, startTime);
PeerConnectionTestHelpers = new PeerConnectionTestHelpers(this);
PeerDownloadTestHelpers = new PeerDownloadTestHelpers(this);
}
public PeerConnectionTestHelpers PeerConnectionTestHelpers { get; }
public PeerDownloadTestHelpers PeerDownloadTestHelpers { get; }
[OneTimeSetUp]
public void GlobalSetup()
{
@ -175,6 +169,16 @@ namespace DistTestCore
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)
{
Stopwatch.Measure(Get().Log, name, action);

View File

@ -1,4 +1,5 @@
using DistTestCore.Codex;
using Logging;
using NUnit.Framework;
using Utils;
@ -14,12 +15,12 @@ namespace DistTestCore.Helpers
public class FullConnectivityHelper
{
private static string Nl = Environment.NewLine;
private readonly DistTest test;
private readonly BaseLog log;
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;
}
@ -30,7 +31,7 @@ namespace DistTestCore.Helpers
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 pairs = CreatePairs(entries);
@ -43,13 +44,13 @@ namespace DistTestCore.Helpers
{
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())));
}
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)
{
test.ScopedTestFiles(pair.Check);
pair.Check();
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)
@ -117,6 +118,11 @@ namespace DistTestCore.Helpers
}
}
private void Log(string msg)
{
log.Log(msg);
}
public class Entry
{
public Entry(IOnlineCodexNode node)

View File

@ -1,4 +1,5 @@
using DistTestCore.Codex;
using Logging;
using static DistTestCore.Helpers.FullConnectivityHelper;
namespace DistTestCore.Helpers
@ -7,9 +8,9 @@ namespace DistTestCore.Helpers
{
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)

View File

@ -1,18 +1,19 @@
using static DistTestCore.Helpers.FullConnectivityHelper;
using Logging;
using static DistTestCore.Helpers.FullConnectivityHelper;
namespace DistTestCore.Helpers
{
public class PeerDownloadTestHelpers : IFullConnectivityImplementation
{
private readonly FullConnectivityHelper helper;
private readonly DistTest test;
private readonly FileManager fileManager;
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();
this.test = test;
this.fileManager = fileManager;
}
public void AssertFullDownloadInterconnectivity(IEnumerable<IOnlineCodexNode> nodes, ByteSize testFileSize)
@ -33,6 +34,7 @@ namespace DistTestCore.Helpers
public PeerConnectionState Check(Entry from, Entry to)
{
fileManager.PushFileSet();
var expectedFile = GenerateTestFile(from.Node, to.Node);
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.
return PeerConnectionState.NoConnection;
}
finally
{
fileManager.PopFileSet();
}
// 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 down = downloader.GetName().Replace("<", "").Replace(">", "");
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;
namespace TestsLong.DownloadConnectivityTests
@ -16,7 +15,7 @@ namespace TestsLong.DownloadConnectivityTests
{
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();
PeerDownloadTestHelpers.AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB());
CreatePeerDownloadTestHelpers().AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB());
}
}
}

View File

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

View File

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