Stufe 4c (#764): Bezeichner auf Englisch - Typen, Methoden, Felder, Parameter, Locals, Testnamen
Mit Roslyn umbenannt (Verweise folgen, Zeichenketten bleiben unberuehrt). Nicht umbenannt, weil gespeichert oder ueber die API gebunden (Stufe 4e): Properties, Record-Parameter, Enum-Member sowie die Parameter der Endpunkt-Handler (Routen-/Query-Bindung ueber den Namen). Die JSON-Felder anonymer Objekte bleiben ausdruecklich benannt (JsonFilter: pfad). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
837a634a22
commit
77062facc9
@@ -18,10 +18,10 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
Path.GetTempPath(), "clawd-tests", "reg-" + Guid.NewGuid().ToString("N")[..8]);
|
||||
|
||||
private readonly FakeLauncher _launcher = new();
|
||||
private readonly FakeChannel _kanal = new();
|
||||
private readonly List<SupervisionEvent> _ereignisse = [];
|
||||
private readonly FakeChannel _channel = new();
|
||||
private readonly List<SupervisionEvent> _events = [];
|
||||
|
||||
private readonly InstanceDirectoryManager _verzeichnisse;
|
||||
private readonly InstanceDirectoryManager _directories;
|
||||
|
||||
private static readonly SupervisionOptions Options = new(
|
||||
ProbeInterval: TimeSpan.FromMilliseconds(50),
|
||||
@@ -33,18 +33,18 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
|
||||
public InstanceRegistryTests()
|
||||
{
|
||||
_verzeichnisse = new InstanceDirectoryManager(Path.Combine(_root, "Instances"));
|
||||
_directories = new InstanceDirectoryManager(Path.Combine(_root, "Instances"));
|
||||
// The socket only answers if a process is really running - exactly as in
|
||||
// operation (see FakeChannel.Launcher).
|
||||
_kanal.Launcher = _launcher;
|
||||
_channel.Launcher = _launcher;
|
||||
}
|
||||
|
||||
private InstanceRegistry Register()
|
||||
{
|
||||
var register = new InstanceRegistry(
|
||||
_verzeichnisse, _launcher, _kanal, NullLoggerFactory.Instance, Options);
|
||||
_directories, _launcher, _channel, NullLoggerFactory.Instance, Options);
|
||||
|
||||
register.Observed += _ereignisse.Add;
|
||||
register.Observed += _events.Add;
|
||||
return register;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
// ─── What is there ───
|
||||
|
||||
[Fact]
|
||||
public async Task Ein_leeres_Instanzenverzeichnis_ergibt_ein_leeres_Register()
|
||||
public async Task An_empty_instances_directory_gives_an_empty_registry()
|
||||
{
|
||||
await using var register = Register();
|
||||
await register.RefreshAsync();
|
||||
@@ -67,10 +67,10 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Angelegte_Instanzen_stehen_im_Register()
|
||||
public async Task Created_instances_are_in_the_registry()
|
||||
{
|
||||
_verzeichnisse.CreateInstance("Alpha");
|
||||
_verzeichnisse.CreateInstance("Beta");
|
||||
_directories.CreateInstance("Alpha");
|
||||
_directories.CreateInstance("Beta");
|
||||
|
||||
await using var register = Register();
|
||||
await register.RefreshAsync();
|
||||
@@ -84,27 +84,27 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
/// restart of the machine, also start what someone stopped on purpose.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Beim_Nachsehen_wird_nichts_von_selbst_gestartet()
|
||||
public async Task Checking_starts_nothing_by_itself()
|
||||
{
|
||||
_verzeichnisse.CreateInstance("Alpha");
|
||||
_directories.CreateInstance("Alpha");
|
||||
|
||||
await using var register = Register();
|
||||
await register.RefreshAsync();
|
||||
|
||||
_launcher.Starts.ShouldBe(0);
|
||||
_ereignisse.ShouldBeEmpty();
|
||||
_events.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Eine_weggeraeumte_Instanz_faellt_aus_dem_Register()
|
||||
public async Task A_cleared_instance_drops_out_of_the_registry()
|
||||
{
|
||||
var pfad = _verzeichnisse.CreateInstance("Vergaenglich");
|
||||
var path = _directories.CreateInstance("Vergaenglich");
|
||||
|
||||
await using var register = Register();
|
||||
await register.RefreshAsync();
|
||||
register.Instances.Count.ShouldBe(1);
|
||||
|
||||
Directory.Delete(pfad, recursive: true);
|
||||
Directory.Delete(path, recursive: true);
|
||||
await register.RefreshAsync();
|
||||
|
||||
register.Instances.ShouldBeEmpty();
|
||||
@@ -113,41 +113,41 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
// ─── Create, start, stop ───
|
||||
|
||||
[Fact]
|
||||
public async Task Eine_neu_angelegte_Instanz_ist_sofort_im_Register_und_laeuft_nicht()
|
||||
public async Task A_newly_created_instance_is_in_the_registry_at_once_and_not_running()
|
||||
{
|
||||
await using var register = Register();
|
||||
|
||||
var pfad = register.Create("Frisch");
|
||||
var path = register.Create("Frisch");
|
||||
|
||||
Directory.Exists(pfad).ShouldBeTrue();
|
||||
File.Exists(Path.Combine(pfad, "InstanceSettings.json")).ShouldBeTrue();
|
||||
Directory.Exists(path).ShouldBeTrue();
|
||||
File.Exists(Path.Combine(path, "InstanceSettings.json")).ShouldBeTrue();
|
||||
|
||||
var instanz = register.Instances.ShouldHaveSingleItem();
|
||||
instanz.Condition.ShouldBe(InstanceCondition.Unknown);
|
||||
var instance = register.Instances.ShouldHaveSingleItem();
|
||||
instance.Condition.ShouldBe(InstanceCondition.Unknown);
|
||||
_launcher.Starts.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Starten_und_Anhalten_gehen_ueber_das_Register()
|
||||
public async Task Starting_and_stopping_go_through_the_registry()
|
||||
{
|
||||
_kanal.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
_channel.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
|
||||
await using var register = Register();
|
||||
var pfad = register.Create("Alpha");
|
||||
var path = register.Create("Alpha");
|
||||
|
||||
(await register.StartAsync(pfad)).ShouldBeTrue();
|
||||
(await register.StartAsync(path)).ShouldBeTrue();
|
||||
register.Instances.Single().Condition.ShouldBe(InstanceCondition.Running);
|
||||
|
||||
// The instance ends upon the request.
|
||||
var prozess = _launcher.Last!;
|
||||
_kanal.OnStopRequest = _ => { _kanal.Answer = null; prozess.Exit(0); };
|
||||
var process = _launcher.Last!;
|
||||
_channel.OnStopRequest = _ => { _channel.Answer = null; process.Exit(0); };
|
||||
|
||||
(await register.StopAsync(pfad)).ShouldBeTrue();
|
||||
(await register.StopAsync(path)).ShouldBeTrue();
|
||||
register.Instances.Single().Condition.ShouldBe(InstanceCondition.Stopped);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Ein_unbekanntes_Verzeichnis_wird_nicht_stillschweigend_angelegt()
|
||||
public async Task An_unknown_directory_is_not_created_silently()
|
||||
{
|
||||
await using var register = Register();
|
||||
|
||||
@@ -158,99 +158,99 @@ public sealed class InstanceRegistryTests : IAsyncDisposable
|
||||
// ─── E-M6 ───
|
||||
|
||||
[Fact]
|
||||
public async Task Laufende_Instanzen_werden_beim_Nachsehen_uebernommen()
|
||||
public async Task Running_instances_are_adopted_when_checking()
|
||||
{
|
||||
string pfad;
|
||||
string path;
|
||||
|
||||
// The first manager creates two and starts only one.
|
||||
await using (var erster = Register())
|
||||
await using (var firstOne = Register())
|
||||
{
|
||||
pfad = erster.Create("Alpha");
|
||||
erster.Create("Beta");
|
||||
path = firstOne.Create("Alpha");
|
||||
firstOne.Create("Beta");
|
||||
|
||||
// Only Alpha answers. Information that names the same instance for every
|
||||
// directory would turn green here and in operation mix up two
|
||||
// instances.
|
||||
_kanal.AnswerFor[Path.GetFullPath(pfad)] =
|
||||
_channel.AnswerFor[Path.GetFullPath(path)] =
|
||||
new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
|
||||
(await erster.StartAsync(pfad)).ShouldBeTrue();
|
||||
(await firstOne.StartAsync(path)).ShouldBeTrue();
|
||||
}
|
||||
|
||||
_ereignisse.Clear();
|
||||
_events.Clear();
|
||||
|
||||
// Second manager, the same machine.
|
||||
await using var zweiter = Register();
|
||||
await zweiter.RefreshAsync();
|
||||
await using var secondOne = Register();
|
||||
await secondOne.RefreshAsync();
|
||||
|
||||
var alpha = zweiter.Instances.Single(i => i.Name == "Alpha");
|
||||
var alpha = secondOne.Instances.Single(i => i.Name == "Alpha");
|
||||
alpha.Condition.ShouldBe(InstanceCondition.Running);
|
||||
alpha.ProcessId.ShouldBe(_launcher.Last!.Id);
|
||||
|
||||
// Beta does not answer and stays off - it is not pulled up along with it.
|
||||
zweiter.Instances.Single(i => i.Name == "Beta").Condition
|
||||
secondOne.Instances.Single(i => i.Name == "Beta").Condition
|
||||
.ShouldBe(InstanceCondition.Stopped);
|
||||
|
||||
// Taking over is not starting.
|
||||
_launcher.Starts.ShouldBe(1);
|
||||
_ereignisse.ShouldBeEmpty();
|
||||
_events.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whoever closes the manager wants to close the manager — not its instances.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Das_Beenden_des_Managers_beendet_keine_Instanz()
|
||||
public async Task Stopping_the_manager_stops_no_instance()
|
||||
{
|
||||
_kanal.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
_channel.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
|
||||
var register = Register();
|
||||
var pfad = register.Create("Alpha");
|
||||
await register.StartAsync(pfad);
|
||||
var path = register.Create("Alpha");
|
||||
await register.StartAsync(path);
|
||||
|
||||
await register.DisposeAsync();
|
||||
|
||||
_kanal.StopRequests.ShouldBe(0);
|
||||
_channel.StopRequests.ShouldBe(0);
|
||||
_launcher.Last!.WasKilled.ShouldBeFalse();
|
||||
_launcher.Last.HasExited.ShouldBeFalse();
|
||||
|
||||
// And the state file stays behind - it is the hint for the next one.
|
||||
InstanceStateStore.Read(pfad).ShouldNotBeNull();
|
||||
InstanceStateStore.Read(path).ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The one exception: a license revocation is not an outage, but a verdict.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Bei_einem_Grund_der_alle_betrifft_werden_alle_angehalten()
|
||||
public async Task With_a_reason_affecting_everyone_all_are_paused()
|
||||
{
|
||||
_kanal.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
_channel.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
|
||||
await using var register = Register();
|
||||
var a = register.Create("Alpha");
|
||||
await register.StartAsync(a);
|
||||
|
||||
var prozess = _launcher.Last!;
|
||||
_kanal.OnStopRequest = _ => { _kanal.Answer = null; prozess.Exit(0); };
|
||||
var process = _launcher.Last!;
|
||||
_channel.OnStopRequest = _ => { _channel.Answer = null; process.Exit(0); };
|
||||
|
||||
await register.StopAllAsync("Lizenz widerrufen");
|
||||
|
||||
register.Instances.Single().Condition.ShouldBe(InstanceCondition.Stopped);
|
||||
_kanal.StopRequests.ShouldBe(1);
|
||||
_channel.StopRequests.ShouldBe(1);
|
||||
}
|
||||
|
||||
// ─── Occurrences ───
|
||||
|
||||
[Fact]
|
||||
public async Task Vorkommnisse_einzelner_Instanzen_kommen_beim_Register_an()
|
||||
public async Task Incidents_of_single_instances_reach_the_registry()
|
||||
{
|
||||
_kanal.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
_channel.Answer = new InstanceIdentity("i-1", "Alpha", "0.1.2");
|
||||
|
||||
await using var register = Register();
|
||||
var pfad = register.Create("Alpha");
|
||||
await register.StartAsync(pfad);
|
||||
var path = register.Create("Alpha");
|
||||
await register.StartAsync(path);
|
||||
|
||||
_ereignisse.Select(e => e.Kind).ShouldBe([InstanceEventKind.Started]);
|
||||
_ereignisse[0].InstanceDirectory.ShouldBe(Path.GetFullPath(pfad));
|
||||
_events.Select(e => e.Kind).ShouldBe([InstanceEventKind.Started]);
|
||||
_events[0].InstanceDirectory.ShouldBe(Path.GetFullPath(path));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user