refactor: remove ClusterClient streaming path (DebugStreamEvent), events flow via gRPC

This commit is contained in:
Joseph Doherty
2026-03-21 12:18:52 -04:00
parent 2cd43b6992
commit 49f042a937
6 changed files with 27 additions and 90 deletions

View File

@@ -136,6 +136,15 @@ public class ArchitecturalConstraintTests
}
}
[Fact]
public void DebugStreamEvent_ShouldNotExist()
{
// DebugStreamEvent was removed when debug streaming moved from ClusterClient to gRPC.
// Events now flow via SiteStreamManager → StreamRelayActor → gRPC channel.
var type = CommonsAssembly.GetTypes().FirstOrDefault(t => t.Name == "DebugStreamEvent");
Assert.Null(type);
}
[Fact]
public void AllEnums_ShouldBeSingularNamed()
{

View File

@@ -41,21 +41,6 @@ public class InstanceActorIntegrationTests : TestKit, IDisposable
ScriptExecutionTimeoutSeconds = 30
};
// Create a fake site-communication actor that unwraps DebugStreamEvent
// and forwards the inner event to TestActor (simulating the ClusterClient relay)
Sys.ActorOf(Props.Create(() => new DebugStreamEventForwarder(TestActor)), "site-communication");
}
/// <summary>
/// Test helper: stands in for SiteCommunicationActor, unwraps DebugStreamEvent
/// and forwards the inner event to a target actor.
/// </summary>
private class DebugStreamEventForwarder : ReceiveActor
{
public DebugStreamEventForwarder(IActorRef target)
{
Receive<DebugStreamEvent>(msg => target.Tell(msg.Event));
}
}
void IDisposable.Dispose()
@@ -169,22 +154,23 @@ public class InstanceActorIntegrationTests : TestKit, IDisposable
}
[Fact]
public void InstanceActor_WP25_DebugViewSubscriber_ReceivesChanges()
public void InstanceActor_WP25_DebugViewSubscribe_NoLongerForwardsEventsViaClusterClient()
{
// Events now flow via gRPC (SiteStreamManager → StreamRelayActor → gRPC),
// not via ClusterClient. Subscribing returns a snapshot but ongoing events
// are NOT forwarded to the subscriber actor.
var actor = CreateInstanceWithScripts("Pump1");
// Subscribe to debug view
// Subscribe to debug view — should still get snapshot
actor.Tell(new SubscribeDebugViewRequest("Pump1", "debug-2"));
ExpectMsg<DebugViewSnapshot>(TimeSpan.FromSeconds(5));
// Now change an attribute
// Change an attribute
actor.Tell(new AttributeValueChanged(
"Pump1", "Temperature", "Temperature", "200", "Good", DateTimeOffset.UtcNow));
// The subscriber should receive the change notification
var changed = ExpectMsg<AttributeValueChanged>(TimeSpan.FromSeconds(5));
Assert.Equal("Temperature", changed.AttributeName);
Assert.Equal("200", changed.Value?.ToString());
// Should NOT receive change notification (old ClusterClient path removed)
ExpectNoMsg(TimeSpan.FromSeconds(1));
}
[Fact]
@@ -223,20 +209,14 @@ public class InstanceActorIntegrationTests : TestKit, IDisposable
var actor = CreateInstanceWithScripts("Pump1", alarms: alarms);
// Subscribe to debug view to observe alarm state changes
actor.Tell(new SubscribeDebugViewRequest("Pump1", "debug-alarm"));
ExpectMsg<DebugViewSnapshot>(TimeSpan.FromSeconds(5));
// Wait for initialization
Thread.Sleep(500);
// Send value outside range to trigger alarm
actor.Tell(new AttributeValueChanged(
"Pump1", "Temperature", "Temperature", "150", "Good", DateTimeOffset.UtcNow));
// Verify alarm actor was created by checking the debug snapshot includes the alarm
actor.Tell(new DebugSnapshotRequest("Pump1", "snap-alarm"));
var snapshot = ExpectMsg<DebugViewSnapshot>(TimeSpan.FromSeconds(5));
// Should receive the attribute change first (from debug subscription)
ExpectMsg<AttributeValueChanged>(TimeSpan.FromSeconds(5));
// Then the alarm state change (forwarded by Instance Actor)
var alarmMsg = ExpectMsg<AlarmStateChanged>(TimeSpan.FromSeconds(5));
Assert.Equal("HighTemp", alarmMsg.AlarmName);
Assert.Equal(Commons.Types.Enums.AlarmState.Active, alarmMsg.State);
Assert.Single(snapshot.AlarmStates);
Assert.Equal("HighTemp", snapshot.AlarmStates[0].AlarmName);
}
}