diff --git a/.gitignore b/.gitignore index 63bc327..c134fee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vs obj bin +.vscode \ No newline at end of file diff --git a/Logging/LogFile.cs b/Logging/LogFile.cs index 96ed16b..349e7c6 100644 --- a/Logging/LogFile.cs +++ b/Logging/LogFile.cs @@ -3,6 +3,7 @@ public class LogFile { private readonly string extension; + private readonly object fileLock = new object(); private string filename; public LogFile(string filename, string extension) @@ -25,7 +26,10 @@ { try { - File.AppendAllLines(FullFilename, new[] { message }); + lock (fileLock) + { + File.AppendAllLines(FullFilename, new[] { message }); + } } catch (Exception ex) { diff --git a/Tests/BasicTests/DownloadTests.cs b/Tests/BasicTests/DownloadTests.cs new file mode 100644 index 0000000..bba4da1 --- /dev/null +++ b/Tests/BasicTests/DownloadTests.cs @@ -0,0 +1,51 @@ +using DistTestCore; +using KubernetesWorkflow; +using NUnit.Framework; +namespace Tests.ParallelTests +{ + [TestFixture] + public class DownloadTests : DistTest + { + [Test] + public void ThreeNodeDownloads() + { + ParallelDownload(3, 5000.MB()); + } + [Test] + public void FiveNodeDownloads() + { + ParallelDownload(5, 1000.MB()); + } + [Test] + public void TenNodeDownloads() + { + ParallelDownload(10, 256.MB()); + } + + void ParallelDownload(int numberOfNodes, ByteSize filesize) + { + var group = SetupCodexNodes(numberOfNodes).BringOnline(); + var host = SetupCodexNodes(1).BringOnline()[0]; + + foreach (var node in group) + { + host.ConnectToPeer(node); + } + + var testFile = GenerateTestFile(filesize); + var contentId = host.UploadFile(testFile); + var list = new List>(); + + foreach (var node in group) + { + list.Add(Task.Run(() => { return node.DownloadContent(contentId); })); + } + + Task.WaitAll(list.ToArray()); + foreach (var task in list) + { + testFile.AssertIsEqual(task.Result); + } + } + } +} \ No newline at end of file diff --git a/Tests/BasicTests/UploadTests.cs b/Tests/BasicTests/UploadTests.cs new file mode 100644 index 0000000..a603524 --- /dev/null +++ b/Tests/BasicTests/UploadTests.cs @@ -0,0 +1,56 @@ +using DistTestCore; +using KubernetesWorkflow; +using NUnit.Framework; +namespace Tests.ParallelTests +{ + [TestFixture] + public class UploadTests : DistTest + { + [Test] + public void ThreeNodeUploads() + { + ParallelUpload(3, 50.MB()); + } + [Test] + public void FiveNodeUploads() + { + ParallelUpload(5, 750.MB()); + } + [Test] + public void TenNodeUploads() + { + ParallelUpload(10, 25.MB()); + } + void ParallelUpload(int numberOfNodes, ByteSize filesize) + { + var group = SetupCodexNodes(numberOfNodes).BringOnline(); + var host = SetupCodexNodes(1).BringOnline()[0]; + + foreach (var node in group) + { + host.ConnectToPeer(node); + } + + var testfiles = new List(); + var contentIds = new List>(); + + for (int i = 0; i < group.Count(); i++) + { + testfiles.Add(GenerateTestFile(filesize)); + var n = i; + contentIds.Add(Task.Run(() => { return host.UploadFile(testfiles[n]); })); + } + var downloads = new List>(); + for (int i = 0; i < group.Count(); i++) + { + var n = i; + downloads.Add(Task.Run(() => { return group[n].DownloadContent(contentIds[n].Result); })); + } + Task.WaitAll(downloads.ToArray()); + for (int i = 0; i < group.Count(); i++) + { + testfiles[i].AssertIsEqual(downloads[i].Result); + } + } + } +} \ No newline at end of file