Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tests #27

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
11 changes: 11 additions & 0 deletions DistTestCore/cs-codex-dist-tests.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"folders": [
{
"path": ".."
},
{
"path": "../../../CodexTestLogs"
}
],
"settings": {}
}
5 changes: 4 additions & 1 deletion LongTests/BasicTests/DownloadTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using DistTestCore;
using NUnit.Framework;
using k8s;
using k8s.Models;

namespace TestsLong.BasicTests
{
Expand All @@ -23,7 +25,8 @@ public void ParallelDownload(int numberOfNodes, int filesizeMb)
var testFile = GenerateTestFile(filesizeMb.MB());
var contentId = host.UploadFile(testFile);
var list = new List<Task<TestFile?>>();

//sleep for 1 minute
Thread.Sleep(1200000);
foreach (var node in group)
{
list.Add(Task.Run(() => { return node.DownloadContent(contentId); }));
Expand Down
49 changes: 49 additions & 0 deletions Tests/BasicTests/MixedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using DistTestCore;
using NUnit.Framework;

namespace Tests.ParallelTests
{
[TestFixture]
public class MixedTests : DistTest
{
[TestCase(1, 10)]
[UseLongTimeouts]
public void ParallelMixed(int numberOfNodes, int filesizeMb)
{
// initialize the nodes
var group = SetupCodexNodes(numberOfNodes);
var host = SetupCodexNode();

foreach (var node in group)
{
host.ConnectToPeer(node);
}
// Upload single file for the download nodes
var testfile = GenerateTestFile(filesizeMb.MB());
var contentId = host.UploadFile(testfile);

var testfiles = new List<TestFile>();
var contentIds = new List<Task<ContentId>>();

// Starts uploads for the upload nodes
for (int i = 0; i < group.Count(); i++)
{
testfiles.Add(GenerateTestFile(filesizeMb.MB()));
var n = i;
contentIds.Add(Task.Run(() => { return host.UploadFile(testfiles[n]); }));
}
// Starts downloads for the download nodes
var downloads = new List<Task<TestFile?>>();
for (int i = 0; i < group.Count(); i++)
{
var n = i;
downloads.Add(Task.Run(() => { return group[n].DownloadContent(contentId); }));
}
Task.WaitAll(downloads.ToArray());
for (int i = 0; i < group.Count(); i++)
{
testfiles[i].AssertIsEqual(downloads[i].Result);
}
}
}
}
130 changes: 130 additions & 0 deletions Tests/MembershipChangeTest/BasicTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using DistTestCore;
using KubernetesWorkflow;
using NUnit.Framework;
namespace Tests.MembershipChangeTests
{
[TestFixture]
public class MembershipChangeTests : DistTest
{

[Test]
public void SingleDownloadWhileAdding()
{
var filesize = 100.MB();

var group = SetupCodexNodes(1);
var toAdd = SetupCodexNodes(5);
var host = SetupCodexNodes(1)[0];

foreach (var node in group)
{
host.ConnectToPeer(node);
}

var testFile = GenerateTestFile(filesize);
var contentId = host.UploadFile(testFile);
var list = new List<Task>();
foreach (var node in toAdd)
{
list.Add(Task.Run(() => { host.ConnectToPeer(node); }));
}

var resFile = group[0].DownloadContent(contentId);
Task.WaitAll(list.ToArray());
testFile.AssertIsEqual(resFile);
}
[Test]
public void SingleUploadWhileAdding()
{
var filesize = 100.MB();

var group = SetupCodexNodes(1);
var toAdd = SetupCodexNodes(5);
var host = SetupCodexNodes(1)[0];

foreach (var node in group)
{
host.ConnectToPeer(node);
}

var testFile = GenerateTestFile(filesize);
var list = new List<Task>();
foreach (var node in toAdd)
{
list.Add(Task.Run(() => { host.ConnectToPeer(node); }));
}
var contentId = host.UploadFile(testFile);


Task.WaitAll(list.ToArray());
var resFile = group[0].DownloadContent(contentId);
testFile.AssertIsEqual(resFile);
}
[Test]
public void SingleDownloadMixedMembership()
{
var filesize = 100.MB();

var group = SetupCodexNodes(1);
var toAdd = SetupCodexNodes(5);
var toRemove = SetupCodexNodes(5);
var host = SetupCodexNodes(1)[0];

foreach (var node in group)
{
host.ConnectToPeer(node);
}
foreach (var node in toRemove)
{
host.ConnectToPeer(node);
}


var testFile = GenerateTestFile(filesize);
var contentId = host.UploadFile(testFile);

for (var i = 0; i < toAdd.Count(); i++)
{
Task.Run(() => { host.ConnectToPeer(toAdd[i]); });
Task.Run(() => { toRemove[i].BringOffline(); });
}

var resFile = group[0].DownloadContent(contentId);
testFile.AssertIsEqual(resFile);
}
[Test]
public void SingleUploadMixedMembership()
{
var filesize = 100.MB();

var group = SetupCodexNodes(1);
var toAdd = SetupCodexNodes(5);
var toRemove = SetupCodexNodes(5);
var host = SetupCodexNodes(1)[0];

foreach (var node in group)
{
host.ConnectToPeer(node);
}
foreach (var node in toRemove)
{
host.ConnectToPeer(node);
}

var testFile = GenerateTestFile(filesize);

var list = new List<Task>();

for (var i = 0; i < toAdd.Count(); i++)
{
Task.Run(() => { host.ConnectToPeer(toAdd[i]); });
Task.Run(() => { toRemove[i].BringOffline(); });
}
var contentId = host.UploadFile(testFile);

var resFile = group[0].DownloadContent(contentId);
testFile.AssertIsEqual(resFile);
}
}

}
67 changes: 67 additions & 0 deletions Tests/MembershipChangeTest/DownloadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using DistTestCore;
using KubernetesWorkflow;
using NUnit.Framework;
namespace Tests.MembershipChangeTests
{
[TestFixture]
public class DownloadMembershipChangeTests : DistTest
{
[TestCase(1, 100, 5, 0)]
[TestCase(1, 100, 0, 5)]
[TestCase(1, 100, 5, 5)]
[UseLongTimeouts]
public void DownloadMembershipChange(int numberOfNodes, int filesize, int numberOfNodesToAdd = 0, int numberOfNodesToRemove = 0)
{
// Setup 3 node groups, one which will be added during the procedure, one which will be dropped during the procedure, and the one being tested.
ICodexNodeGroup? toAdd = null;
ICodexNodeGroup? toRemove = null;
var group = SetupCodexNodes(numberOfNodes);
if (numberOfNodesToAdd != 0)
toAdd = SetupCodexNodes(numberOfNodesToAdd);
if (numberOfNodesToRemove != 0)
toRemove = SetupCodexNodes(numberOfNodesToRemove);
var host = SetupCodexNodes(1)[0];

// Connect the main and dropping nodes to the host
foreach (var node in group)
{
host.ConnectToPeer(node);
}
if (toRemove != null)
foreach (var node in toRemove)
host.ConnectToPeer(node);

// Upload a file to the host
var testFile = GenerateTestFile(filesize.MB());
var contentId = host.UploadFile(testFile);

var list = new List<Task<TestFile?>>();

// Start the download for each node
foreach (var node in group)
{
list.Add(Task.Run(() => { return node.DownloadContent(contentId); }));
}

// Start adding and dropping nodes during the download
// TODO: The log is put here for debug, but without it the members do not run async
for (var i = 0; (toAdd != null && i < toAdd.Count()) || (toRemove != null && i < toRemove.Count()); i++)
{
Log($"Iteration {i}");
if (toAdd != null && i < toAdd.Count())
Task.Run(() => { host.ConnectToPeer(toAdd[i]); });
if (toRemove != null && i < toRemove.Count())
Task.Run(() => { toRemove[i].BringOffline(); });
}

// Wait for the download to finish
Task.WaitAll(list.ToArray());

// Assert that the download was successful
foreach (var task in list)
{
testFile.AssertIsEqual(task.Result);
}
}
}
}
83 changes: 83 additions & 0 deletions Tests/MembershipChangeTest/MixedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using DistTestCore;
using KubernetesWorkflow;
using NUnit.Framework;
namespace Tests.MembershipChangeTests
{
[TestFixture]
public class MixedMembershipChangeTests : DistTest
{
[TestCase(1, 5, 0, 0)]

[UseLongTimeouts]
public void MixedMembershipChange(int numberOfNodes, int filesize, int numberOfNodesToAdd, int numberOfNodesToRemove)
{
// Creating the node groups
ICodexNodeGroup? toAdd = null;
ICodexNodeGroup? toAddSecondary = null;
ICodexNodeGroup? toRemove = null;
var group = SetupCodexNodes(numberOfNodes);

if (numberOfNodesToAdd != 0) {
toAdd = SetupCodexNodes(numberOfNodesToAdd);
toAddSecondary = SetupCodexNodes(numberOfNodesToAdd);
}
if (numberOfNodesToRemove != 0)
toRemove = SetupCodexNodes(numberOfNodesToRemove);
var host = SetupCodexNodes(1)[0];

// Connect the main and dropping nodes to the host
foreach (var node in group)
{
host.ConnectToPeer(node);
}
if (toRemove != null)
foreach (var node in toRemove)
host.ConnectToPeer(node);

var testFile = GenerateTestFile(filesize.MB());
var contentId = host.UploadFile(testFile);

var testfiles = new List<TestFile>();
var contentIds = new List<Task<ContentId>>();

var downloads = new List<Task<TestFile?>>();

// Start adding and dropping nodes
for (var i = 0; (toAdd != null && i < toAdd.Count()) || (toRemove != null && i < toRemove.Count()); i++)
{
Log($"Iteration {i}");
if (toAdd != null && i < toAdd.Count())
Task.Run(() => { host.ConnectToPeer(toAdd[i]); });
if (toRemove != null && i < toRemove.Count())
Task.Run(() => { toRemove[i].BringOffline(); });
}

// Start the upload for each node in the main group
for (int i = 0; i < group.Count(); i++)
{
testfiles.Add(GenerateTestFile(filesize.MB()));
var n = i;
contentIds.Add(Task.Run(() => { return host.UploadFile(testfiles[n]); }));
}

// Start the download for each node in the main group
for (int i = 0; i < group.Count(); i++)
{
var n = i;
downloads.Add(Task.Run(() => { return group[n].DownloadContent(contentId); }));
}

// Wait for the download to finish
Task.WaitAll(downloads.ToArray());

// Wait for the upload to finish
Task.WaitAll(contentIds.ToArray());

// Assert that the files are intact
for (int i = 0; i < group.Count(); i++)
{
testfiles[i].AssertIsEqual(downloads[i].Result);
}
}
}
}
Loading