2023-04-12 14:06:04 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
|
|
|
|
[SetUpFixture]
|
|
|
|
|
public abstract class DistTest
|
|
|
|
|
{
|
|
|
|
|
private TestLifecycle lifecycle = null!;
|
|
|
|
|
|
|
|
|
|
[OneTimeSetUp]
|
|
|
|
|
public void GlobalSetup()
|
|
|
|
|
{
|
|
|
|
|
// Previous test run may have been interrupted.
|
|
|
|
|
// Begin by cleaning everything up.
|
|
|
|
|
CreateNewTestLifecycle();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lifecycle.DeleteAllResources();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
GlobalTestFailure.HasFailed = true;
|
|
|
|
|
Error($"Global setup cleanup failed with: {ex}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
Log("Global setup cleanup successful");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUpDistTest()
|
|
|
|
|
{
|
|
|
|
|
if (GlobalTestFailure.HasFailed)
|
|
|
|
|
{
|
|
|
|
|
Assert.Inconclusive("Skip test: Previous test failed during clean up.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CreateNewTestLifecycle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDownDistTest()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lifecycle.Log.EndTest();
|
|
|
|
|
IncludeLogsAndMetricsOnTestFailure();
|
|
|
|
|
lifecycle.DeleteAllResources();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Error("Cleanup failed: " + ex.Message);
|
|
|
|
|
GlobalTestFailure.HasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TestFile GenerateTestFile(ByteSize size)
|
|
|
|
|
{
|
|
|
|
|
return lifecycle.FileManager.GenerateTestFile(size);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public ICodexSetup SetupCodexNodes(int numberOfNodes)
|
2023-04-12 14:06:04 +00:00
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
return new CodexSetup(lifecycle.CodexStarter, numberOfNodes);
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IncludeLogsAndMetricsOnTestFailure()
|
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
//var result = TestContext.CurrentContext.Result;
|
|
|
|
|
//if (result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed)
|
|
|
|
|
//{
|
|
|
|
|
// if (IsDownloadingLogsAndMetricsEnabled())
|
|
|
|
|
// {
|
|
|
|
|
// log.Log("Downloading all CodexNode logs and metrics because of test failure...");
|
|
|
|
|
// k8sManager.ForEachOnlineGroup(DownloadLogs);
|
|
|
|
|
// k8sManager.DownloadAllMetrics();
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// log.Log("Skipping download of all CodexNode logs and metrics due to [DontDownloadLogsAndMetricsOnFailure] attribute.");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Log(string msg)
|
|
|
|
|
{
|
|
|
|
|
lifecycle.Log.Log(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Error(string msg)
|
|
|
|
|
{
|
|
|
|
|
lifecycle.Log.Error(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateNewTestLifecycle()
|
|
|
|
|
{
|
|
|
|
|
lifecycle = new TestLifecycle(new Configuration());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DownloadLogs(CodexNodeGroup group)
|
|
|
|
|
{
|
2023-04-13 07:33:10 +00:00
|
|
|
|
//foreach (var node in group)
|
|
|
|
|
//{
|
|
|
|
|
// var downloader = new PodLogDownloader(log, k8sManager);
|
|
|
|
|
// var n = (OnlineCodexNode)node;
|
|
|
|
|
// downloader.DownloadLog(n);
|
|
|
|
|
//}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
//private bool IsDownloadingLogsAndMetricsEnabled()
|
|
|
|
|
//{
|
|
|
|
|
// var testProperties = TestContext.CurrentContext.Test.Properties;
|
|
|
|
|
// return !testProperties.ContainsKey(PodLogDownloader.DontDownloadLogsOnFailureKey);
|
|
|
|
|
//}
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class GlobalTestFailure
|
|
|
|
|
{
|
|
|
|
|
public static bool HasFailed { get; set; } = false;
|
|
|
|
|
}
|
|
|
|
|
}
|