diff --git a/DistTestCore/DistTest.cs b/DistTestCore/DistTest.cs index 943b098..a6379ec 100644 --- a/DistTestCore/DistTest.cs +++ b/DistTestCore/DistTest.cs @@ -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); diff --git a/DistTestCore/Helpers/FullConnectivityHelper.cs b/DistTestCore/Helpers/FullConnectivityHelper.cs index afa3442..0ac6f82 100644 --- a/DistTestCore/Helpers/FullConnectivityHelper.cs +++ b/DistTestCore/Helpers/FullConnectivityHelper.cs @@ -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) diff --git a/DistTestCore/Helpers/PeerConnectionTestHelpers.cs b/DistTestCore/Helpers/PeerConnectionTestHelpers.cs index fa07b06..6b1a673 100644 --- a/DistTestCore/Helpers/PeerConnectionTestHelpers.cs +++ b/DistTestCore/Helpers/PeerConnectionTestHelpers.cs @@ -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 nodes) diff --git a/DistTestCore/Helpers/PeerDownloadTestHelpers.cs b/DistTestCore/Helpers/PeerDownloadTestHelpers.cs index ffb7d52..4ba22a5 100644 --- a/DistTestCore/Helpers/PeerDownloadTestHelpers.cs +++ b/DistTestCore/Helpers/PeerDownloadTestHelpers.cs @@ -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 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); } } } diff --git a/LongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs b/LongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs index 5bb7323..d0650f6 100644 --- a/LongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs +++ b/LongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs @@ -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()); } } } diff --git a/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs b/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs index a1f2c5f..4f91f64 100644 --- a/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs +++ b/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs @@ -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()); } } } diff --git a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index aeb414a..8cd32a2 100644 --- a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -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()); } } } diff --git a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 002fe79..94e7075 100644 --- a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -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()); } } }