fix(host): site singletons (deployment-manager, event-log-handler) via SingletonRegistrar — PhaseClusterLeave drains for site SQLite writes (plan R2-01 T11)

This commit is contained in:
Joseph Doherty
2026-07-13 11:01:44 -04:00
parent 80e5b36852
commit 56d39b5fce
2 changed files with 42 additions and 51 deletions
@@ -61,11 +61,29 @@ public class CoordinatedShutdownTests
Assert.Contains($"\"{name}\"", content);
}
// No hand-rolled ClusterSingletonManager registrations remain in the
// CENTRAL branch. The only two left are the SITE singletons
// (deployment-manager, event-log-handler), which stay hand-rolled because
// they are role-scoped (.WithRole(siteRole)).
Assert.Equal(2, CountOccurrences(content, "ClusterSingletonManager.Props("));
// No hand-rolled ClusterSingletonManager registrations remain anywhere:
// the two role-scoped SITE singletons now also go through the registrar
// (SingletonRegistrar.Start(..., role: siteRole)), so every singleton in
// the file is created through the registrar with a drain task.
Assert.Equal(0, CountOccurrences(content, "ClusterSingletonManager.Props("));
}
[Fact]
public void SiteSingletons_RegisterThroughRegistrarWithDrain()
{
var hostProjectDir = FindHostProjectDirectory();
Assert.NotNull(hostProjectDir);
var content = File.ReadAllText(Path.Combine(hostProjectDir!, "Actors", "AkkaHostedService.cs"));
// Round-2 N5: the two role-scoped SITE singletons previously stayed
// hand-rolled (bare PoisonPill, no PhaseClusterLeave drain). They now
// go through SingletonRegistrar.Start(..., role: siteRole), which
// always adds the GracefulStop drain — in-flight SQLite writes
// (static overrides, native_alarm_state) complete before handover.
Assert.Contains("\"deployment-manager\"", content);
Assert.Contains("\"event-log-handler\"", content);
Assert.Contains("role: siteRole", content);
Assert.Equal(0, CountOccurrences(content, "ClusterSingletonManager.Props("));
}
private static int CountOccurrences(string haystack, string needle)