2025-01-16 13:51:29 +01:00
|
|
|
|
using CodexClient;
|
|
|
|
|
|
using CodexPlugin;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
using DistTestCore;
|
2023-09-12 15:43:30 +02:00
|
|
|
|
|
2023-10-09 16:59:52 +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
|
|
|
|
{
|
2024-09-24 10:10:59 +02:00
|
|
|
|
private readonly Dictionary<TestLifecycle, ICodexNode> bootstrapNodes = new Dictionary<TestLifecycle, ICodexNode>();
|
2025-04-22 17:11:34 +02:00
|
|
|
|
private bool isBooting = false;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
|
2025-04-22 17:11:34 +02:00
|
|
|
|
protected override void LifecycleStart(TestLifecycle tl)
|
2023-09-12 15:43:30 +02:00
|
|
|
|
{
|
2025-04-22 17:11:34 +02:00
|
|
|
|
base.LifecycleStart(tl);
|
2024-09-24 10:10:59 +02:00
|
|
|
|
if (!bootstrapNodes.ContainsKey(tl))
|
|
|
|
|
|
{
|
2025-04-22 17:11:34 +02:00
|
|
|
|
isBooting = true;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
bootstrapNodes.Add(tl, StartCodex(s => s.WithName("BOOTSTRAP_" + tl.TestNamespace)));
|
2025-04-22 17:11:34 +02:00
|
|
|
|
isBooting = false;
|
2024-09-24 10:10:59 +02:00
|
|
|
|
}
|
2023-09-12 15:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-22 17:11:34 +02:00
|
|
|
|
protected override void LifecycleStop(TestLifecycle lifecycle, DistTestResult result)
|
2023-09-28 14:23:48 +02:00
|
|
|
|
{
|
2025-04-22 17:11:34 +02:00
|
|
|
|
bootstrapNodes.Remove(lifecycle);
|
|
|
|
|
|
base.LifecycleStop(lifecycle, result);
|
2023-09-28 14:23:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 14:24:43 +02:00
|
|
|
|
protected override void OnCodexSetup(ICodexSetup setup)
|
2023-09-12 15:43:30 +02:00
|
|
|
|
{
|
2025-04-22 17:11:34 +02:00
|
|
|
|
if (isBooting) return;
|
|
|
|
|
|
|
2024-09-24 10:10:59 +02:00
|
|
|
|
var node = BootstrapNode;
|
|
|
|
|
|
if (node != null) setup.WithBootstrapNode(node);
|
2023-09-12 15:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-22 17:11:34 +02:00
|
|
|
|
protected ICodexNode BootstrapNode
|
2024-09-24 10:10:59 +02:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var tl = Get();
|
|
|
|
|
|
if (bootstrapNodes.TryGetValue(tl, out var node))
|
|
|
|
|
|
{
|
|
|
|
|
|
return node;
|
|
|
|
|
|
}
|
2025-04-22 17:11:34 +02:00
|
|
|
|
throw new InvalidOperationException("Bootstrap node not yet started.");
|
2024-09-24 10:10:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-09-12 15:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|