Allows disabling of log download on test failure with test attirbute

This commit is contained in:
benbierens 2023-03-26 10:57:54 +02:00
parent ce963a228c
commit 5d66e900f1
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 92 additions and 69 deletions

View File

@ -83,7 +83,15 @@ namespace CodexDistTestCore
var result = TestContext.CurrentContext.Result;
if (result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed)
{
k8sManager.ForEachOnlineGroup(DownloadLogs);
if (IsDownloadingLogsEnabled())
{
log.Log("Downloading all CodexNode logs because of test failure...");
k8sManager.ForEachOnlineGroup(DownloadLogs);
}
else
{
log.Log("Skipping download of all CodexNode logs due to [DontDownloadLogsOnFailure] attribute.");
}
}
}
@ -96,6 +104,12 @@ namespace CodexDistTestCore
downloader.DownloadLog(n);
}
}
private bool IsDownloadingLogsEnabled()
{
var testProperties = TestContext.CurrentContext.Test.Properties;
return !testProperties.ContainsKey(PodLogDownloader.DontDownloadLogsOnFailureKey);
}
}
public static class GlobalTestFailure

View File

@ -1,12 +1,25 @@
namespace CodexDistTestCore
using NUnit.Framework;
namespace CodexDistTestCore
{
public interface IPodLogHandler
{
void Log(Stream log);
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class DontDownloadLogsOnFailureAttribute : PropertyAttribute
{
public DontDownloadLogsOnFailureAttribute()
: base(Timing.UseLongTimeoutsKey)
{
}
}
public class PodLogDownloader
{
public const string DontDownloadLogsOnFailureKey = "DontDownloadLogsOnFailure";
private readonly TestLog log;
private readonly IK8sManager k8SManager;

View File

@ -1,4 +1,5 @@
using CodexDistTestCore;
using CodexDistTestCore.Config;
using NUnit.Framework;
namespace Tests.BasicTests
@ -7,87 +8,82 @@ namespace Tests.BasicTests
public class SimpleTests : DistTest
{
[Test]
public void GetDebugInfo()
{
var dockerImage = new CodexDockerImage();
var node = SetupCodexNodes(1).BringOnline()[0];
var debugInfo = node.GetDebugInfo();
Assert.That(debugInfo.spr, Is.Not.Empty);
Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
}
[Test, DontDownloadLogsOnFailure]
public void CanAccessLogs()
{
var node = SetupCodexNodes(1).BringOnline()[0];
var log = node.DownloadLog();
log.AssertLogContains("Started codex node");
}
[Test]
public void OneClientTest()
{
var primary = SetupCodexNodes(1).BringOnline()[0];
var testFile = GenerateTestFile(1.MB());
var contentId = primary.UploadFile(testFile);
var downloadedFile = primary.DownloadContent(contentId);
testFile.AssertIsEqual(downloadedFile);
}
[Test]
public void TwoClientsOnePodTest()
{
var group = SetupCodexNodes(2).BringOnline();
var log = group[0].DownloadLog();
var primary = group[0];
var secondary = group[1];
log.AssertLogContains("topics=\"discv5\"");
PerformTwoClientTest(primary, secondary);
}
//[Test]
//public void GetDebugInfo()
//{
// var dockerImage = new CodexDockerImage();
[Test]
public void TwoClientsTwoPodsTest()
{
var primary = SetupCodexNodes(1).BringOnline()[0];
// var node = SetupCodexNodes(1)
// .BringOnline()[0];
var secondary = SetupCodexNodes(1).BringOnline()[0];
// var debugInfo = node.GetDebugInfo();
PerformTwoClientTest(primary, secondary);
}
// Assert.That(debugInfo.spr, Is.Not.Empty);
// Assert.That(debugInfo.codex.revision, Is.EqualTo(dockerImage.GetExpectedImageRevision()));
//}
[Test]
public void TwoClientsTwoLocationsTest()
{
var primary = SetupCodexNodes(1)
.At(Location.BensLaptop)
.BringOnline()[0];
//[Test]
//public void OneClientTest()
//{
// var primary = SetupCodexNodes(1)
// .BringOnline()[0];
var secondary = SetupCodexNodes(1)
.At(Location.BensOldGamingMachine)
.BringOnline()[0];
// var testFile = GenerateTestFile(1.MB());
var debugInfo = primary.GetDebugInfo();
Assert.That(debugInfo.spr, Is.Not.Empty);
// var contentId = primary.UploadFile(testFile);
var debugInfo2 = secondary.GetDebugInfo();
Assert.That(debugInfo2.spr, Is.Not.Empty);
// var downloadedFile = primary.DownloadContent(contentId);
// testFile.AssertIsEqual(downloadedFile);
//}
//[Test]
//public void TwoClientsOnePodTest()
//{
// var group = SetupCodexNodes(2)
// .BringOnline();
// var primary = group[0];
// var secondary = group[1];
// PerformTwoClientTest(primary, secondary);
//}
//[Test]
//public void TwoClientsTwoPodsTest()
//{
// var primary = SetupCodexNodes(1)
// .BringOnline()[0];
// var secondary = SetupCodexNodes(1)
// .BringOnline()[0];
// PerformTwoClientTest(primary, secondary);
//}
//[Test]
//public void TwoClientsTwoLocationsTest()
//{
// var primary = SetupCodexNodes(1)
// .At(Location.BensLaptop)
// .BringOnline()[0];
// var secondary = SetupCodexNodes(1)
// .At(Location.BensOldGamingMachine)
// .BringOnline()[0];
// var debugInfo = primary.GetDebugInfo();
// Assert.That(debugInfo.spr, Is.Not.Empty);
// var debugInfo2 = secondary.GetDebugInfo();
// Assert.That(debugInfo2.spr, Is.Not.Empty);
// PerformTwoClientTest(primary, secondary);
//}
PerformTwoClientTest(primary, secondary);
}
private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)
{