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()
{
var ip = Container.Pod.Cluster.GetIp();
var ip = Container.Pod.Cluster.IP;
var port = Container.ServicePorts[0].Number;
return new Http(ip, port, baseUrl: "/api/codex/v1");
}

View File

@ -14,7 +14,14 @@
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; }

View File

@ -4,40 +4,21 @@ namespace KubernetesWorkflow
{
public class K8sCluster
{
private KubernetesClientConfiguration? config;
public K8sCluster(Configuration configuration)
{
Configuration = configuration;
}
public Configuration Configuration { get; }
public string IP { get; private set; } = string.Empty;
public KubernetesClientConfiguration GetK8sClientConfig()
{
if (config != null) return config;
if (Configuration.KubeConfigFile != null)
{
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile);
}
else
{
config = KubernetesClientConfiguration.BuildDefaultConfig();
}
var config = GetConfig();
UpdateIp(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)
{
if (location == Location.Unspecified) return string.Empty;
@ -53,5 +34,23 @@ namespace KubernetesWorkflow
{
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
{
Name = "deploy-" + workflowNumberSource.WorkflowNumber,
Name = "service-" + workflowNumberSource.WorkflowNumber,
NamespaceProperty = K8sNamespace
};
}

View File

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