51 lines
1.5 KiB
C#
Raw Normal View History

2025-01-16 13:51:29 +01:00
using CodexClient;
using CodexPlugin;
using DistTestCore;
2023-09-12 15:43:30 +02:00
namespace CodexTests
2023-09-12 15:43:30 +02:00
{
2023-09-13 14:24:43 +02:00
public class AutoBootstrapDistTest : CodexDistTest
2023-09-12 15:43:30 +02:00
{
private readonly Dictionary<TestLifecycle, ICodexNode> bootstrapNodes = new Dictionary<TestLifecycle, ICodexNode>();
private bool isBooting = false;
protected override void LifecycleStart(TestLifecycle tl)
2023-09-12 15:43:30 +02:00
{
base.LifecycleStart(tl);
if (!bootstrapNodes.ContainsKey(tl))
{
isBooting = true;
bootstrapNodes.Add(tl, StartCodex(s => s.WithName("BOOTSTRAP_" + tl.TestNamespace)));
isBooting = false;
}
2023-09-12 15:43:30 +02:00
}
protected override void LifecycleStop(TestLifecycle lifecycle, DistTestResult result)
{
bootstrapNodes.Remove(lifecycle);
base.LifecycleStop(lifecycle, result);
}
2023-09-13 14:24:43 +02:00
protected override void OnCodexSetup(ICodexSetup setup)
2023-09-12 15:43:30 +02:00
{
if (isBooting) return;
var node = BootstrapNode;
if (node != null) setup.WithBootstrapNode(node);
2023-09-12 15:43:30 +02:00
}
protected ICodexNode BootstrapNode
{
get
{
var tl = Get();
if (bootstrapNodes.TryGetValue(tl, out var node))
{
return node;
}
throw new InvalidOperationException("Bootstrap node not yet started.");
}
}
2023-09-12 15:43:30 +02:00
}
}