2023-03-19 10:49:03 +01:00
|
|
|
|
using NUnit.Framework;
|
2023-03-17 11:43:29 +01:00
|
|
|
|
|
2023-03-21 13:20:21 +01:00
|
|
|
|
namespace CodexDistTestCore
|
2023-03-17 11:43:29 +01:00
|
|
|
|
{
|
2023-03-21 09:20:09 +01:00
|
|
|
|
[SetUpFixture]
|
2023-03-17 11:43:29 +01:00
|
|
|
|
public abstract class DistTest
|
|
|
|
|
{
|
2023-03-22 09:22:18 +01:00
|
|
|
|
private TestLog log = null!;
|
2023-03-19 10:49:03 +01:00
|
|
|
|
private FileManager fileManager = null!;
|
|
|
|
|
private K8sManager k8sManager = null!;
|
2023-03-17 11:43:29 +01:00
|
|
|
|
|
2023-03-21 09:20:09 +01:00
|
|
|
|
[OneTimeSetUp]
|
|
|
|
|
public void GlobalSetup()
|
|
|
|
|
{
|
|
|
|
|
// Previous test run may have been interrupted.
|
|
|
|
|
// Begin by cleaning everything up.
|
2023-03-22 09:22:18 +01:00
|
|
|
|
log = new TestLog();
|
|
|
|
|
fileManager = new FileManager(log);
|
|
|
|
|
k8sManager = new K8sManager(log, fileManager);
|
2023-03-21 09:20:09 +01:00
|
|
|
|
|
2023-03-22 09:22:18 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
k8sManager.DeleteAllResources();
|
|
|
|
|
fileManager.DeleteAllTestFiles();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
GlobalTestFailure.HasFailed = true;
|
|
|
|
|
log.Error($"Global setup cleanup failed with: {ex}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
log.Log("Global setup cleanup successful");
|
2023-03-21 09:20:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-19 10:49:03 +01:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUpDistTest()
|
2023-03-17 11:43:29 +01:00
|
|
|
|
{
|
2023-03-20 10:37:03 +01:00
|
|
|
|
if (GlobalTestFailure.HasFailed)
|
|
|
|
|
{
|
|
|
|
|
Assert.Inconclusive("Skip test: Previous test failed during clean up.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-03-22 09:22:18 +01:00
|
|
|
|
log = new TestLog();
|
|
|
|
|
fileManager = new FileManager(log);
|
|
|
|
|
k8sManager = new K8sManager(log, fileManager);
|
2023-03-20 10:37:03 +01:00
|
|
|
|
}
|
2023-03-17 11:43:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-19 10:49:03 +01:00
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDownDistTest()
|
2023-03-17 11:43:29 +01:00
|
|
|
|
{
|
2023-03-20 10:37:03 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-03-22 09:22:18 +01:00
|
|
|
|
log.EndTest(k8sManager);
|
2023-03-20 10:37:03 +01:00
|
|
|
|
k8sManager.DeleteAllResources();
|
|
|
|
|
fileManager.DeleteAllTestFiles();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-03-22 09:22:18 +01:00
|
|
|
|
log.Error("Cleanup failed: " + ex.Message);
|
2023-03-20 10:37:03 +01:00
|
|
|
|
GlobalTestFailure.HasFailed = true;
|
|
|
|
|
}
|
2023-03-17 11:43:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 09:20:09 +01:00
|
|
|
|
public TestFile GenerateTestFile(ByteSize size)
|
2023-03-17 11:43:29 +01:00
|
|
|
|
{
|
2023-03-19 10:49:03 +01:00
|
|
|
|
return fileManager.GenerateTestFile(size);
|
|
|
|
|
}
|
2023-03-17 11:43:29 +01:00
|
|
|
|
|
2023-03-21 15:17:48 +01:00
|
|
|
|
public IOfflineCodexNodes SetupCodexNodes(int numberOfNodes)
|
2023-03-19 10:49:03 +01:00
|
|
|
|
{
|
2023-03-21 15:17:48 +01:00
|
|
|
|
return new OfflineCodexNodes(k8sManager, numberOfNodes);
|
2023-03-17 11:43:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-20 10:37:03 +01:00
|
|
|
|
|
|
|
|
|
public static class GlobalTestFailure
|
|
|
|
|
{
|
|
|
|
|
public static bool HasFailed { get; set; } = false;
|
|
|
|
|
}
|
2023-03-17 11:43:29 +01:00
|
|
|
|
}
|