From d030153378d4da31111bc81b0cc514c9ec22b35b Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Sat, 16 May 2026 14:33:09 -0400 Subject: [PATCH] test(site-runtime): fix stale SetStaticAttribute tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HandleSetStaticAttribute was made fire-and-forget (commit 2951507) — it no longer replies with SetStaticAttributeResponse — but three InstanceActor tests still ExpectMsg and timed out. Verify the mutation via the GetAttributeRequest round-trip instead, which the FIFO mailbox makes a sound sync point. Test intent (in-memory update, SQLite persistence, serialized ordering) is unchanged. --- .../Actors/InstanceActorIntegrationTests.cs | 8 +++----- .../Actors/InstanceActorTests.cs | 16 +++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorIntegrationTests.cs b/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorIntegrationTests.cs index 0bc84b1..68543f9 100644 --- a/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorIntegrationTests.cs +++ b/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorIntegrationTests.cs @@ -123,11 +123,9 @@ public class InstanceActorIntegrationTests : TestKit, IDisposable $"corr-{i}", "Pump1", "Temperature", $"{i}", DateTimeOffset.UtcNow)); } - // Wait for all to process - for (int i = 0; i < 50; i++) - { - ExpectMsg(TimeSpan.FromSeconds(10)); - } + // SetStaticAttributeCommand is fire-and-forget; the GetAttributeRequest + // round-trip below is the sync point — the FIFO mailbox guarantees all + // 50 sets are processed before the get is. // The last value should be the final one actor.Tell(new GetAttributeRequest( diff --git a/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorTests.cs b/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorTests.cs index 20b5254..e205f5e 100644 --- a/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorTests.cs +++ b/tests/ScadaLink.SiteRuntime.Tests/Actors/InstanceActorTests.cs @@ -113,13 +113,12 @@ public class InstanceActorTests : TestKit, IDisposable var actor = CreateInstanceActor("Pump1", config); - // Set a static attribute -- response comes async via PipeTo + // SetStaticAttributeCommand is fire-and-forget (no reply); the + // GetAttributeRequest round-trip below confirms it was applied — the + // actor mailbox is FIFO, so the set is processed before the get. actor.Tell(new SetStaticAttributeCommand( "corr-3", "Pump1", "Temperature", "100.0", DateTimeOffset.UtcNow)); - var setResponse = ExpectMsg(TimeSpan.FromSeconds(5)); - Assert.True(setResponse.Success); - // Verify the value changed in memory actor.Tell(new GetAttributeRequest( "corr-4", "Pump1", "Temperature", DateTimeOffset.UtcNow)); @@ -146,9 +145,12 @@ public class InstanceActorTests : TestKit, IDisposable actor.Tell(new SetStaticAttributeCommand( "corr-persist", "PumpPersist1", "Temperature", "100.0", DateTimeOffset.UtcNow)); - ExpectMsg(TimeSpan.FromSeconds(5)); - - // Give async persistence time to complete + // SetStaticAttributeCommand is fire-and-forget; round-trip a + // GetAttributeRequest to confirm the command was processed (FIFO + // mailbox), then wait for the async SQLite persist to complete. + actor.Tell(new GetAttributeRequest( + "corr-persist-get", "PumpPersist1", "Temperature", DateTimeOffset.UtcNow)); + ExpectMsg(TimeSpan.FromSeconds(5)); await Task.Delay(500); // Verify it persisted to SQLite