Debugging two-client test

This commit is contained in:
benbierens 2023-03-19 11:18:56 +01:00
parent 457951c561
commit 686cdc88e2
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 68 additions and 19 deletions

View File

@ -15,24 +15,24 @@ namespace CodexDistTests.BasicTests
Assert.That(debugInfo.spr, Is.Not.Empty); Assert.That(debugInfo.spr, Is.Not.Empty);
} }
//[Test] //[Test]
//public void TwoClientTest() //public void TwoClientTest()
//{ //{
// var primaryNodex = SetupCodexNode() // var primary = SetupCodexNode()
// .WithLogLevel(CodexLogLevel.Warn) // .WithLogLevel(CodexLogLevel.Warn)
// .WithStorageQuota(1024 * 1024) // .WithStorageQuota(1024 * 1024)
// .BringOnline(); // .BringOnline();
// var secondaryNodex = SetupCodexNode() // var secondary = SetupCodexNode()
// .WithBootstrapNode(primaryNodex) // .WithBootstrapNode(primary)
// .BringOnline(); // .BringOnline();
// var testFile = GenerateTestFile(1024 * 1024); // var testFile = GenerateTestFile(1024 * 1024);
// var contentId = primaryNodex.UploadFile(testFile); // var contentId = primary.UploadFile(testFile);
// var downloadedFile = secondaryNodex.DownloadContent(contentId); // var downloadedFile = secondary.DownloadContent(contentId);
// testFile.AssertIsEqual(downloadedFile); // testFile.AssertIsEqual(downloadedFile);

View File

@ -0,0 +1,50 @@
using k8s.Models;
namespace CodexDistTests.TestCore
{
public class CodexDockerImage
{
public string GetImageTag()
{
return "thatbenbierens/nim-codex:sha-c9a62de";
}
public List<V1EnvVar> CreateEnvironmentVariables(OfflineCodexNode node)
{
var formatter = new EnvFormatter();
formatter.Create(node);
return formatter.Result;
}
private class EnvFormatter
{
public List<V1EnvVar> Result { get; } = new List<V1EnvVar>();
public void Create(OfflineCodexNode node)
{
if (node.BootstrapNode != null)
{
var debugInfo = node.BootstrapNode.GetDebugInfo();
AddVar("BOOTSTRAP_SPR", debugInfo.spr);
}
if (node.LogLevel != null)
{
AddVar("LOG_LEVEL", node.LogLevel.ToString()!.ToUpperInvariant());
}
if (node.StorageQuota != null)
{
AddVar("STORAGE_QUOTA", node.StorageQuota.ToString()!);
}
}
private void AddVar(string key, string value)
{
Result.Add(new V1EnvVar
{
Name = key,
Value = value
});
}
}
}
}

View File

@ -17,8 +17,8 @@ namespace CodexDistTests.TestCore
[TearDown] [TearDown]
public void TearDownDistTest() public void TearDownDistTest()
{ {
fileManager.DeleteAllTestFiles();
k8sManager.DeleteAllResources(); k8sManager.DeleteAllResources();
fileManager.DeleteAllTestFiles();
} }
public TestFile GenerateTestFile(int size = 1024) public TestFile GenerateTestFile(int size = 1024)

View File

@ -16,9 +16,15 @@ namespace CodexDistTests.TestCore
private readonly Random random = new Random(); private readonly Random random = new Random();
private readonly List<TestFile> activeFiles = new List<TestFile>(); private readonly List<TestFile> activeFiles = new List<TestFile>();
public FileManager()
{
if (!Directory.Exists(Folder)) Directory.CreateDirectory(Folder);
}
public TestFile CreateEmptyTestFile() public TestFile CreateEmptyTestFile()
{ {
var result = new TestFile(Path.Combine(Folder, Guid.NewGuid().ToString() + "_test.bin")); var result = new TestFile(Path.Combine(Folder, Guid.NewGuid().ToString() + "_test.bin"));
File.Create(result.Filename).Close();
activeFiles.Add(result); activeFiles.Add(result);
return result; return result;
} }

View File

@ -11,7 +11,7 @@ namespace CodexDistTests.TestCore
public class K8sManager : IK8sManager public class K8sManager : IK8sManager
{ {
private const string k8sNamespace = "codex-test-namespace"; private const string k8sNamespace = "codex-test-namespace";
private const string codexDockerImage = "thatbenbierens/nim-codex:sha-c9a62de"; private readonly CodexDockerImage dockerImage = new CodexDockerImage();
private readonly IFileManager fileManager; private readonly IFileManager fileManager;
private int freePort; private int freePort;
private int nodeOrderNumber; private int nodeOrderNumber;
@ -36,7 +36,7 @@ namespace CodexDistTests.TestCore
var codexNode = new OnlineCodexNode(node, fileManager, activeNode.Port); var codexNode = new OnlineCodexNode(node, fileManager, activeNode.Port);
activeNodes.Add(codexNode, activeNode); activeNodes.Add(codexNode, activeNode);
CreateDeployment(activeNode, client); CreateDeployment(activeNode, client, node);
CreateService(activeNode, client); CreateService(activeNode, client);
WaitUntilOnline(activeNode, client); WaitUntilOnline(activeNode, client);
@ -162,7 +162,7 @@ namespace CodexDistTests.TestCore
#region Deployment management #region Deployment management
private void CreateDeployment(ActiveNode node, Kubernetes client) private void CreateDeployment(ActiveNode node, Kubernetes client, OfflineCodexNode codexNode)
{ {
var deploymentSpec = new V1Deployment var deploymentSpec = new V1Deployment
{ {
@ -188,7 +188,7 @@ namespace CodexDistTests.TestCore
new V1Container new V1Container
{ {
Name = node.GetContainerName(), Name = node.GetContainerName(),
Image = codexDockerImage, Image = dockerImage.GetImageTag(),
Ports = new List<V1ContainerPort> Ports = new List<V1ContainerPort>
{ {
new V1ContainerPort new V1ContainerPort
@ -197,14 +197,7 @@ namespace CodexDistTests.TestCore
Name = node.GetContainerPortName() Name = node.GetContainerPortName()
} }
}, },
Env = new List<V1EnvVar>// todo Env = dockerImage.CreateEnvironmentVariables(codexNode)
{
new V1EnvVar
{
Name = "LOG_LEVEL",
Value = "WARN"
}
}
} }
} }
} }