test for location selection

This commit is contained in:
benbierens 2023-03-24 14:16:59 +01:00
parent d68a264f35
commit 40aaf42106
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 68 additions and 45 deletions

View File

@ -208,6 +208,7 @@ namespace CodexDistTestCore
},
Spec = new V1PodSpec
{
NodeSelector = CreateNodeSelector(offline),
Containers = CreateDeploymentContainers(online, offline)
}
}
@ -217,6 +218,22 @@ namespace CodexDistTestCore
online.Deployment = client.CreateNamespacedDeployment(deploymentSpec, K8sNamespace);
}
private IDictionary<string, string> CreateNodeSelector(OfflineCodexNodes offline)
{
switch (offline.Location)
{
case Location.Unspecified:
return new Dictionary<string, string>();
case Location.BensLaptop:
return new Dictionary<string, string> { { "codex-test-location", "worker01" } };
case Location.BensOldGamingMachine:
return new Dictionary<string, string> { { "codex-test-location", "worker02" } };
}
Assert.Fail("Unknown location selected: " + offline.Location);
throw new InvalidOperationException();
}
private List<V1Container> CreateDeploymentContainers(CodexNodeGroup online, OfflineCodexNodes offline)
{
var result = new List<V1Container>();

View File

@ -2,7 +2,7 @@
{
public interface IOfflineCodexNodes
{
IOfflineCodexNodes At(CodexNodeLocation location);
IOfflineCodexNodes At(Location location);
IOfflineCodexNodes WithLogLevel(CodexLogLevel level);
IOfflineCodexNodes WithBootstrapNode(IOnlineCodexNode node);
IOfflineCodexNodes WithStorageQuota(ByteSize storageQuota);
@ -18,7 +18,7 @@
Error
}
public enum CodexNodeLocation
public enum Location
{
Unspecified,
BensLaptop,
@ -30,7 +30,7 @@
private readonly IK8sManager k8SManager;
public int NumberOfNodes { get; }
public CodexNodeLocation Location { get; private set; }
public Location Location { get; private set; }
public CodexLogLevel? LogLevel { get; private set; }
public IOnlineCodexNode? BootstrapNode { get; private set; }
public ByteSize? StorageQuota { get; private set; }
@ -39,7 +39,7 @@
{
this.k8SManager = k8SManager;
NumberOfNodes = numberOfNodes;
Location = CodexNodeLocation.Unspecified;
Location = Location.Unspecified;
}
public ICodexNodeGroup BringOnline()
@ -47,7 +47,7 @@
return k8SManager.BringOnline(this);
}
public IOfflineCodexNodes At(CodexNodeLocation location)
public IOfflineCodexNodes At(Location location)
{
Location = location;
return this;

View File

@ -6,70 +6,76 @@ namespace Tests.BasicTests
[TestFixture]
public class SimpleTests : DistTest
{
[Test]
public void GetDebugInfo()
{
var dockerImage = new CodexDockerImage();
//[Test]
//public void GetDebugInfo()
//{
// var dockerImage = new CodexDockerImage();
var node = SetupCodexNodes(1)
.BringOnline()[0];
// var node = SetupCodexNodes(1)
// .BringOnline()[0];
var debugInfo = node.GetDebugInfo();
// var debugInfo = node.GetDebugInfo();
Assert.That(debugInfo.spr, Is.Not.Empty);
Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
}
// Assert.That(debugInfo.spr, Is.Not.Empty);
// Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
//}
[Test]
public void OneClientTest()
{
var primary = SetupCodexNodes(1)
.BringOnline()[0];
//[Test]
//public void OneClientTest()
//{
// var primary = SetupCodexNodes(1)
// .BringOnline()[0];
var testFile = GenerateTestFile(1.MB());
// var testFile = GenerateTestFile(1.MB());
var contentId = primary.UploadFile(testFile);
// var contentId = primary.UploadFile(testFile);
var downloadedFile = primary.DownloadContent(contentId);
// var downloadedFile = primary.DownloadContent(contentId);
testFile.AssertIsEqual(downloadedFile);
}
// testFile.AssertIsEqual(downloadedFile);
//}
[Test]
public void TwoClientsOnePodTest()
{
var group = SetupCodexNodes(2)
.BringOnline();
//[Test]
//public void TwoClientsOnePodTest()
//{
// var group = SetupCodexNodes(2)
// .BringOnline();
var primary = group[0];
var secondary = group[1];
// var primary = group[0];
// var secondary = group[1];
PerformTwoClientTest(primary, secondary);
}
// PerformTwoClientTest(primary, secondary);
//}
[Test]
public void TwoClientsTwoPodsTest()
{
var primary = SetupCodexNodes(1)
.BringOnline()[0];
//[Test]
//public void TwoClientsTwoPodsTest()
//{
// var primary = SetupCodexNodes(1)
// .BringOnline()[0];
var secondary = SetupCodexNodes(1)
.BringOnline()[0];
// var secondary = SetupCodexNodes(1)
// .BringOnline()[0];
PerformTwoClientTest(primary, secondary);
}
// PerformTwoClientTest(primary, secondary);
//}
[Test]
public void TwoClientsTwoLocationsTest()
{
var primary = SetupCodexNodes(1)
.At(CodexNodeLocation.BensLaptop)
.At(Location.BensLaptop)
.BringOnline()[0];
var secondary = SetupCodexNodes(1)
.At(CodexNodeLocation.BensOldGamingMachine)
.At(Location.BensOldGamingMachine)
.BringOnline()[0];
var debugInfo = primary.GetDebugInfo();
Assert.That(debugInfo.spr, Is.Not.Empty);
var debugInfo2 = secondary.GetDebugInfo();
Assert.That(debugInfo2.spr, Is.Not.Empty);
PerformTwoClientTest(primary, secondary);
}