two-client tests pass

This commit is contained in:
benbierens 2023-04-13 10:11:33 +02:00
parent f5c60f0bca
commit 56063bbbf1
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 67 additions and 60 deletions

View File

@ -30,7 +30,7 @@ namespace DistTestCore.Codex
private Http Http() private Http Http()
{ {
var ip = Container.Pod.Cluster.GetIp(); var ip = Container.Pod.Cluster.IP;
var port = Container.ServicePorts[0].Number; var port = Container.ServicePorts[0].Number;
return new Http(ip, port, baseUrl: "/api/codex/v1"); return new Http(ip, port, baseUrl: "/api/codex/v1");
} }

View File

@ -14,7 +14,14 @@
Initialize(config); Initialize(config);
return new ContainerRecipe(containerNumber, Image, exposedPorts.ToArray(), internalPorts.ToArray(), envVars.ToArray()); var recipe = new ContainerRecipe(containerNumber, Image, exposedPorts.ToArray(), internalPorts.ToArray(), envVars.ToArray());
exposedPorts.Clear();
internalPorts.Clear();
envVars.Clear();
this.factory = null!;
return recipe;
} }
protected abstract string Image { get; } protected abstract string Image { get; }

View File

@ -4,40 +4,21 @@ namespace KubernetesWorkflow
{ {
public class K8sCluster public class K8sCluster
{ {
private KubernetesClientConfiguration? config;
public K8sCluster(Configuration configuration) public K8sCluster(Configuration configuration)
{ {
Configuration = configuration; Configuration = configuration;
} }
public Configuration Configuration { get; } public Configuration Configuration { get; }
public string IP { get; private set; } = string.Empty;
public KubernetesClientConfiguration GetK8sClientConfig() public KubernetesClientConfiguration GetK8sClientConfig()
{ {
if (config != null) return config; var config = GetConfig();
UpdateIp(config);
if (Configuration.KubeConfigFile != null)
{
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile);
}
else
{
config = KubernetesClientConfiguration.BuildDefaultConfig();
}
return config; return config;
} }
public string GetIp()
{
var c = GetK8sClientConfig();
var host = c.Host.Replace("https://", "");
return host.Substring(0, host.IndexOf(':'));
}
public string GetNodeLabelForLocation(Location location) public string GetNodeLabelForLocation(Location location)
{ {
if (location == Location.Unspecified) return string.Empty; if (location == Location.Unspecified) return string.Empty;
@ -53,5 +34,23 @@ namespace KubernetesWorkflow
{ {
return Configuration.RetryDelay; return Configuration.RetryDelay;
} }
private KubernetesClientConfiguration GetConfig()
{
if (Configuration.KubeConfigFile != null)
{
return KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile);
}
else
{
return KubernetesClientConfiguration.BuildDefaultConfig();
}
}
private void UpdateIp(KubernetesClientConfiguration config)
{
var host = config.Host.Replace("https://", "");
IP = host.Substring(0, host.IndexOf(':'));
}
} }
} }

View File

@ -227,7 +227,7 @@ namespace KubernetesWorkflow
{ {
return new V1ObjectMeta return new V1ObjectMeta
{ {
Name = "deploy-" + workflowNumberSource.WorkflowNumber, Name = "service-" + workflowNumberSource.WorkflowNumber,
NamespaceProperty = K8sNamespace NamespaceProperty = K8sNamespace
}; };
} }

View File

@ -1,4 +1,5 @@
using DistTestCore; using DistTestCore;
using KubernetesWorkflow;
using NUnit.Framework; using NUnit.Framework;
namespace Tests.BasicTests namespace Tests.BasicTests
@ -20,41 +21,41 @@ namespace Tests.BasicTests
testFile.AssertIsEqual(downloadedFile); testFile.AssertIsEqual(downloadedFile);
} }
//[Test] [Test]
//public void TwoClientsOnePodTest() public void TwoClientsOnePodTest()
//{ {
// var group = SetupCodexNodes(2).BringOnline(); var group = SetupCodexNodes(2).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).BringOnline()[0]; 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] [Test]
//[Ignore("Requires Location map to be configured for k8s cluster.")] [Ignore("Requires Location map to be configured for k8s cluster.")]
//public void TwoClientsTwoLocationsTest() public void TwoClientsTwoLocationsTest()
//{ {
// var primary = SetupCodexNodes(1) var primary = SetupCodexNodes(1)
// .At(Location.BensLaptop) .At(Location.BensLaptop)
// .BringOnline()[0]; .BringOnline()[0];
// var secondary = SetupCodexNodes(1) var secondary = SetupCodexNodes(1)
// .At(Location.BensOldGamingMachine) .At(Location.BensOldGamingMachine)
// .BringOnline()[0]; .BringOnline()[0];
// PerformTwoClientTest(primary, secondary); PerformTwoClientTest(primary, secondary);
//} }
//[Test] //[Test]
//public void TwoMetricsExample() //public void TwoMetricsExample()
@ -118,17 +119,17 @@ namespace Tests.BasicTests
// //primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage."); // //primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage.");
//} //}
//private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary) private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
//{ {
// primary.ConnectToPeer(secondary); primary.ConnectToPeer(secondary);
// var testFile = GenerateTestFile(1.MB()); var testFile = GenerateTestFile(1.MB());
// var contentId = primary.UploadFile(testFile); var contentId = primary.UploadFile(testFile);
// var downloadedFile = secondary.DownloadContent(contentId); var downloadedFile = secondary.DownloadContent(contentId);
// testFile.AssertIsEqual(downloadedFile); testFile.AssertIsEqual(downloadedFile);
//} }
} }
} }