diff --git a/sdks/csharp/examples~/regression-tests/client/Program.cs b/sdks/csharp/examples~/regression-tests/client/Program.cs index c3b88d1b05a..f4886f0e11b 100644 --- a/sdks/csharp/examples~/regression-tests/client/Program.cs +++ b/sdks/csharp/examples~/regression-tests/client/Program.cs @@ -23,6 +23,8 @@ DbConnection db = null!; uint waiting = 0; var runComplete = false; +var mainPhaseScheduled = false; +var mainUnsubscribeStarted = false; SubscriptionHandle? mainHandle = null; uint testEventInsertCount = 0; long viewPkIdCounter = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 10; @@ -1621,10 +1623,28 @@ ProcedureCallbackResult> result } ); + // The unsubscribe phase clears the subscribed cache. + // Start it only after the reducer and procedure callbacks above + // have finished validating rows in that cache. + mainPhaseScheduled = true; +} + +void StartMainUnsubscribe() +{ + if (mainUnsubscribeStarted) + { + return; + } + mainUnsubscribeStarted = true; + + var handle = + mainHandle + ?? throw new InvalidOperationException("Main subscription handle was not initialised."); + // Now unsubscribe and check that the unsubscribing is actually applied. Log.Debug("Calling Unsubscribe"); waiting++; - mainHandle?.UnsubscribeThen( + handle.UnsubscribeThen( (ctx) => { Log.Debug("Received Unsubscribe"); @@ -1638,6 +1658,18 @@ ProcedureCallbackResult> result RegressionTestHarness.RegisterUnhandledExceptionExitHandler(); db = RegressionTestHarness.ConnectToDatabase(HOST, DBNAME, OnConnected); const int TIMEOUT = 20; // seconds; -RegressionTestHarness.FrameTickUntilComplete(db, () => runComplete && waiting == 0, TIMEOUT); +RegressionTestHarness.FrameTickUntilComplete( + db, + () => + { + if (mainPhaseScheduled && !mainUnsubscribeStarted && waiting == 0) + { + StartMainUnsubscribe(); + } + + return runComplete && waiting == 0; + }, + TIMEOUT +); Log.Info("Success"); Environment.Exit(0);