adds wait-and-check to theseus test

This commit is contained in:
Ben 2025-08-13 11:35:03 +02:00
parent 07c25142c1
commit 5f793c6454
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
6 changed files with 46 additions and 18 deletions

View File

@ -1,9 +0,0 @@
namespace Utils
{
//public interface ICrashWatcher
//{
// void Start();
// void Stop();
// bool HasCrashed();
//}
}

View File

@ -57,9 +57,14 @@ namespace CodexPlugin
return Nodes.GetEnumerator();
}
public string Describe()
public string Names()
{
return $"group:[{string.Join(",", Nodes.Select(n => n.GetName()))}]";
return $"[{string.Join(",", Nodes.Select(n => n.GetName()))}]";
}
public override string ToString()
{
return Names();
}
public void EnsureOnline()
@ -76,4 +81,17 @@ namespace CodexPlugin
Version = first;
}
}
public static class CodexNodeGroupExtensions
{
public static string Names(this ICodexNode[] nodes)
{
return $"[{string.Join(",", nodes.Select(n => n.GetName()))}]";
}
public static string Names(this List<ICodexNode> nodes)
{
return $"[{string.Join(",", nodes.Select(n => n.GetName()))}]";
}
}
}

View File

@ -1,4 +1,5 @@
using CodexClient;
using CodexPlugin;
using CodexTests;
using FileUtils;
using NUnit.Framework;
@ -36,7 +37,7 @@ namespace CodexReleaseTests.DataTests
for (var i = 0; i < steps; i++)
{
Log($"{nameof(Theseus)} step {i}");
nodes[i].Stop(waitTillStopped: true);
nodes[0].Stop(waitTillStopped: true);
nodes.RemoveAt(0);
nodes.Add(StartCodex());
@ -47,8 +48,12 @@ namespace CodexReleaseTests.DataTests
private void AllNodesHaveFile()
{
Log($"{nameof(AllNodesHaveFile)} [{string.Join(",", nodes.Select(n => n.GetName()))}]");
WaitAndCheckNodesStaysAlive(TimeSpan.FromSeconds(20), nodes.ToArray());
Log($"{nameof(AllNodesHaveFile)} {nodes.Names()}");
foreach (var n in nodes) HasFile(n);
WaitAndCheckNodesStaysAlive(TimeSpan.FromSeconds(20), nodes.ToArray());
}
private void HasFile(ICodexNode n)

View File

@ -16,6 +16,7 @@ using Newtonsoft.Json;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using OverwatchTranscript;
using Utils;
namespace CodexTests
{
@ -128,16 +129,25 @@ namespace CodexTests
public void WaitAndCheckNodesStaysAlive(TimeSpan duration, params ICodexNode[] nodes)
{
Log($"{nameof(WaitAndCheckNodesStaysAlive)} {Time.FormatDuration(duration)}...");
var timeout = TimeSpan.FromSeconds(3.0);
Assert.That(duration.TotalSeconds, Is.GreaterThan(timeout.TotalSeconds));
var start = DateTime.UtcNow;
while ((DateTime.UtcNow - start) < duration)
{
Thread.Sleep(5000);
Thread.Sleep(timeout);
foreach (var node in nodes)
{
Assert.That(node.HasCrashed(), Is.False);
var info = node.GetDebugInfo();
Assert.That(!string.IsNullOrEmpty(info.Id));
}
}
Log($"{nameof(WaitAndCheckNodesStaysAlive)} OK");
}
public void AssertNodesContainFile(ContentId cid, ICodexNodeGroup nodes)
@ -147,11 +157,15 @@ namespace CodexTests
public void AssertNodesContainFile(ContentId cid, params ICodexNode[] nodes)
{
Log($"{nameof(AssertNodesContainFile)} {nodes.Names()} {cid}...");
foreach (var node in nodes)
{
var localDatasets = node.LocalFiles();
CollectionAssert.Contains(localDatasets.Content.Select(c => c.Cid), cid);
}
Log($"{nameof(AssertNodesContainFile)} OK");
}
private string GetBasicNodeStatus(ICodexNode node)

View File

@ -1,4 +1,5 @@
using CodexClient;
using CodexPlugin;
using Logging;
using NUnit.Framework;
@ -30,7 +31,7 @@ namespace CodexTests.Helpers
private void AssertFullyConnected(ICodexNode[] nodes)
{
Log($"Asserting '{implementation.Description()}' for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'...");
Log($"Asserting '{implementation.Description()}' for nodes: '{nodes.Names()}'...");
Assert.That(nodes.Length, Is.GreaterThan(1));
var entries = CreateEntries(nodes);
@ -50,7 +51,7 @@ namespace CodexTests.Helpers
}
else
{
Log($"'{implementation.Description()}' = Success! for nodes: {string.Join(",", nodes.Select(n => n.GetName()))}");
Log($"'{implementation.Description()}' = Success! for nodes: {nodes.Names()}");
}
}

View File

@ -222,8 +222,7 @@ namespace CodexNetDeployer
}
else
{
Log(
$"Check failed. The following containers have crashed: {string.Join(",", crashes.Select(c => c.GetName()))}");
Log($"Check failed. The following containers have crashed: {crashes.Names()}");
throw new Exception("Deployment failed: One or more containers crashed.");
}
}