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 Spec = new V1PodSpec
{ {
NodeSelector = CreateNodeSelector(offline),
Containers = CreateDeploymentContainers(online, offline) Containers = CreateDeploymentContainers(online, offline)
} }
} }
@ -217,6 +218,22 @@ namespace CodexDistTestCore
online.Deployment = client.CreateNamespacedDeployment(deploymentSpec, K8sNamespace); 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) private List<V1Container> CreateDeploymentContainers(CodexNodeGroup online, OfflineCodexNodes offline)
{ {
var result = new List<V1Container>(); var result = new List<V1Container>();

View File

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

View File

@ -6,70 +6,76 @@ namespace Tests.BasicTests
[TestFixture] [TestFixture]
public class SimpleTests : DistTest public class SimpleTests : DistTest
{ {
[Test] //[Test]
public void GetDebugInfo() //public void GetDebugInfo()
{ //{
var dockerImage = new CodexDockerImage(); // var dockerImage = new CodexDockerImage();
var node = SetupCodexNodes(1) // var node = SetupCodexNodes(1)
.BringOnline()[0]; // .BringOnline()[0];
var debugInfo = node.GetDebugInfo(); // var debugInfo = node.GetDebugInfo();
Assert.That(debugInfo.spr, Is.Not.Empty); // Assert.That(debugInfo.spr, Is.Not.Empty);
Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision())); // Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
} //}
[Test] //[Test]
public void OneClientTest() //public void OneClientTest()
{ //{
var primary = SetupCodexNodes(1) // var primary = SetupCodexNodes(1)
.BringOnline()[0]; // .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] //[Test]
public void TwoClientsOnePodTest() //public void TwoClientsOnePodTest()
{ //{
var group = SetupCodexNodes(2) // var group = SetupCodexNodes(2)
.BringOnline(); // .BringOnline();
var primary = group[0]; // var primary = group[0];
var secondary = group[1]; // var secondary = group[1];
PerformTwoClientTest(primary, secondary); // PerformTwoClientTest(primary, secondary);
} //}
[Test] //[Test]
public void TwoClientsTwoPodsTest() //public void TwoClientsTwoPodsTest()
{ //{
var primary = SetupCodexNodes(1) // var primary = SetupCodexNodes(1)
.BringOnline()[0]; // .BringOnline()[0];
var secondary = SetupCodexNodes(1) // var secondary = SetupCodexNodes(1)
.BringOnline()[0]; // .BringOnline()[0];
PerformTwoClientTest(primary, secondary); // PerformTwoClientTest(primary, secondary);
} //}
[Test] [Test]
public void TwoClientsTwoLocationsTest() public void TwoClientsTwoLocationsTest()
{ {
var primary = SetupCodexNodes(1) var primary = SetupCodexNodes(1)
.At(CodexNodeLocation.BensLaptop) .At(Location.BensLaptop)
.BringOnline()[0]; .BringOnline()[0];
var secondary = SetupCodexNodes(1) var secondary = SetupCodexNodes(1)
.At(CodexNodeLocation.BensOldGamingMachine) .At(Location.BensOldGamingMachine)
.BringOnline()[0]; .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); PerformTwoClientTest(primary, secondary);
} }