From 5c00205f621a01442d72a5d3f10eccfb733e66fb Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 1 May 2023 11:14:42 +0200 Subject: [PATCH] Cleanup and support for automatic bootstrap tests --- DistTestCore/AutoBootstrapDistTest.cs | 30 +++++++++++++++++++++++ DistTestCore/DistTest.cs | 34 +++++++++++++-------------- Tests/BasicTests/DownloadTests.cs | 4 ++-- 3 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 DistTestCore/AutoBootstrapDistTest.cs diff --git a/DistTestCore/AutoBootstrapDistTest.cs b/DistTestCore/AutoBootstrapDistTest.cs new file mode 100644 index 0000000..352e2ec --- /dev/null +++ b/DistTestCore/AutoBootstrapDistTest.cs @@ -0,0 +1,30 @@ +namespace DistTestCore +{ + public class AutoBootstrapDistTest : DistTest + { + private IOnlineCodexNode? bootstrapNode; + + public override IOnlineCodexNode SetupCodexBootstrapNode(Action setup) + { + throw new Exception("AutoBootstrapDistTest creates and attaches a single boostrap node for you. " + + "If you want to control the bootstrap node from your test, please use DistTest instead."); + } + + public override ICodexNodeGroup SetupCodexNodes(int numberOfNodes, Action setup) + { + var codexSetup = new CodexSetup(numberOfNodes); + setup(codexSetup); + codexSetup.WithBootstrapNode(EnsureBootstapNode()); + return BringOnline(codexSetup); + } + + private IOnlineCodexNode EnsureBootstapNode() + { + if (bootstrapNode == null) + { + bootstrapNode = base.SetupCodexBootstrapNode(s => { }); + } + return bootstrapNode; + } + } +} diff --git a/DistTestCore/DistTest.cs b/DistTestCore/DistTest.cs index 9884249..a85f689 100644 --- a/DistTestCore/DistTest.cs +++ b/DistTestCore/DistTest.cs @@ -69,21 +69,6 @@ namespace DistTestCore } } - private bool ShouldUseLongTimeouts() - { - // Don't be fooled! TestContext.CurrentTest.Test allows you easy access to the attributes of the current test. - // But this doesn't work for tests making use of [TestCase]. So instead, we use reflection here to figure out - // if the attribute is present. - var currentTest = TestContext.CurrentContext.Test; - var className = currentTest.ClassName; - var methodName = currentTest.MethodName; - - var testClasses = testAssemblies.SelectMany(a => a.GetTypes()).Where(c => c.FullName == className).ToArray(); - var testMethods = testClasses.SelectMany(c => c.GetMethods()).Where(m => m.Name == methodName).ToArray(); - - return testMethods.Any(m => m.GetCustomAttribute() != null); - } - [TearDown] public void TearDownDistTest() { @@ -108,7 +93,7 @@ namespace DistTestCore return SetupCodexBootstrapNode(s => { }); } - public IOnlineCodexNode SetupCodexBootstrapNode(Action setup) + public virtual IOnlineCodexNode SetupCodexBootstrapNode(Action setup) { return SetupCodexNode(s => { @@ -132,7 +117,7 @@ namespace DistTestCore return SetupCodexNodes(numberOfNodes, s => { }); } - public ICodexNodeGroup SetupCodexNodes(int numberOfNodes, Action setup) + public virtual ICodexNodeGroup SetupCodexNodes(int numberOfNodes, Action setup) { var codexSetup = new CodexSetup(numberOfNodes); @@ -151,6 +136,21 @@ namespace DistTestCore get { return lifecycle.Log; } } + private bool ShouldUseLongTimeouts() + { + // Don't be fooled! TestContext.CurrentTest.Test allows you easy access to the attributes of the current test. + // But this doesn't work for tests making use of [TestCase]. So instead, we use reflection here to figure out + // if the attribute is present. + var currentTest = TestContext.CurrentContext.Test; + var className = currentTest.ClassName; + var methodName = currentTest.MethodName; + + var testClasses = testAssemblies.SelectMany(a => a.GetTypes()).Where(c => c.FullName == className).ToArray(); + var testMethods = testClasses.SelectMany(c => c.GetMethods()).Where(m => m.Name == methodName).ToArray(); + + return testMethods.Any(m => m.GetCustomAttribute() != null); + } + private void CreateNewTestLifecycle() { Stopwatch.Measure(fixtureLog, $"Setup for {GetCurrentTestName()}", () => diff --git a/Tests/BasicTests/DownloadTests.cs b/Tests/BasicTests/DownloadTests.cs index 4588260..0f61daf 100644 --- a/Tests/BasicTests/DownloadTests.cs +++ b/Tests/BasicTests/DownloadTests.cs @@ -6,8 +6,8 @@ namespace Tests.ParallelTests [TestFixture] public class DownloadTests : DistTest { - [TestCase(3, 5000)] - [TestCase(5, 1000)] + [TestCase(3, 500)] + [TestCase(5, 100)] [TestCase(10, 256)] [UseLongTimeouts] public void ParallelDownload(int numberOfNodes, int filesizeMb)