From 6e94903aebf6e0a1b445d20e57b7d8ba65303524 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 25 May 2026 20:21:04 +0200 Subject: [PATCH] Protocol.Tests: MultipleObserversForSameSender: fix, add missing synchronization. --- test/Tmds.DBus.Protocol.Tests/SignalOwnerTests.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Tmds.DBus.Protocol.Tests/SignalOwnerTests.cs b/test/Tmds.DBus.Protocol.Tests/SignalOwnerTests.cs index 9583742..3d2adc6 100644 --- a/test/Tmds.DBus.Protocol.Tests/SignalOwnerTests.cs +++ b/test/Tmds.DBus.Protocol.Tests/SignalOwnerTests.cs @@ -462,6 +462,7 @@ await clientConnection.AddMatchAsync(methodReturnRule, // Add third observer with NoSubscribe var signals3 = 0; + var semaphore3 = new SemaphoreSlim(0); var observer3 = await clientConnection.AddMatchAsync(rule, (Message m, object? s) => m.GetBodyReader().ReadString(), (Exception? ex, string msg, object? rs, object? hs) => @@ -469,6 +470,7 @@ await clientConnection.AddMatchAsync(methodReturnRule, if (ex == null) { Interlocked.Increment(ref signals3); + semaphore3.Release(); } }, null, null, false, ObserverFlags.NoSubscribe); @@ -481,9 +483,11 @@ await clientConnection.AddMatchAsync(methodReturnRule, SendSignal(serviceConnection); await semaphore1.WaitAsync(TimeSpan.FromSeconds(5)); await semaphore2.WaitAsync(TimeSpan.FromSeconds(5)); + await semaphore3.WaitAsync(TimeSpan.FromSeconds(5)); Assert.Equal(1, signals1); Assert.Equal(1, signals2); + Assert.Equal(1, signals3); // Remove first observer - name owner watch should still exist observer1.Dispose(); @@ -493,6 +497,7 @@ await clientConnection.AddMatchAsync(methodReturnRule, SendSignal(serviceConnection); await semaphore2.WaitAsync(TimeSpan.FromSeconds(5)); + await semaphore3.WaitAsync(TimeSpan.FromSeconds(5)); Assert.Equal(1, signals1); // Unchanged (observer disposed) Assert.Equal(2, signals2); // Incremented