From a7e024002fe5a2c7db50fc05e23cb6e2040e599a Mon Sep 17 00:00:00 2001 From: Corbo12 Date: Thu, 20 Apr 2023 12:43:25 +0200 Subject: [PATCH] ADD upload tests --- Tests/BasicTests/ParallelTests.cs | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Tests/BasicTests/ParallelTests.cs b/Tests/BasicTests/ParallelTests.cs index e0f48de..c80eba2 100644 --- a/Tests/BasicTests/ParallelTests.cs +++ b/Tests/BasicTests/ParallelTests.cs @@ -57,13 +57,51 @@ namespace Tests.ParallelTests [Test] public void TwoNodeUploads() { + ParallelUpload(2, 64.MB()); } - + [Test] public void FiveNodeUploads() { + ParallelUpload(5, 1000.MB()); } + [Test] public void TenNodeUploads() { + ParallelUpload(10, 16.MB()); + } + void ParallelUpload(int numberOfNodes, ByteSize filesize) + { + var group = SetupCodexNodes(numberOfNodes).EnableMetrics().BringOnline(); + + var host = group[0]; + + for (int i = 1; i < numberOfNodes; i++) + { + host.ConnectToPeer(group[i]); + } + var testfiles = new List(); + var contentIds = new List(); + for (int i = 1; i < numberOfNodes; i++) + { + testfiles.Add(GenerateTestFile(filesize)); + new Task(() => { upload(host, testfiles[i - 1], contentIds, i - 1); }).Start(); + } + Task.WaitAll(); + for (int i = 0; i < testfiles.Count; i++) + { + new Task(() => { download(contentIds[i], group[i + 1], testfiles[i]); }).Start(); + } + Task.WaitAll(); + } + + void download(ContentId contentId, CodexDistTestCore.IOnlineCodexNode node, TestFile testFile) + { + var downloadedFile = node.DownloadContent(contentId); + testFile.AssertIsEqual(downloadedFile); + } + void upload(CodexDistTestCore.IOnlineCodexNode host, TestFile testfile, List contentIds, int pos) + { + contentIds[pos] = host.UploadFile(testfile); } } [TestFixture]