From dc2bd1d3b4e8681cc8825f077788c0062c0d8f70 Mon Sep 17 00:00:00 2001 From: Alex Feldgendler Date: Thu, 27 Aug 2026 09:55:01 +0300 Subject: [PATCH] Wait for the callbacks these tests assert on. (#4803) TestUnsubscribe checked that the changed-notifier observer was gone as soon as the unsubscribe had settled, but setDesired leaves the RemoveObserver call to a goroutine of its own and nothing the test waits on orders against it, so CI caught the assertion running first. TestSubscribe has the same defect on the unsubscribed callback, which unmarkSubscribedTo delivers with a bare go while the subscribed one is called inline. Wait for both, each with a message of its own, so that a leak that is real still says which of them broke. Co-authored-by: Claude Opus 5 --- pkg/rtc/subscriptionmanager_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/rtc/subscriptionmanager_test.go b/pkg/rtc/subscriptionmanager_test.go index fbbfc0428..28b1a4864 100644 --- a/pkg/rtc/subscriptionmanager_test.go +++ b/pkg/rtc/subscriptionmanager_test.go @@ -113,7 +113,10 @@ func TestSubscribe(t *testing.T) { require.Eventually(t, func() bool { return numParticipantSubscribed.Load() == 2 }, subSettleTimeout, subCheckInterval, "participant subscribe status was not updated twice") - require.Equal(t, int32(1), numParticipantUnsubscribed.Load()) + // the unsubscribed callback is delivered on a goroutine of its own + require.Eventually(t, func() bool { + return numParticipantUnsubscribed.Load() == 1 + }, subSettleTimeout, subCheckInterval, "participant unsubscribe status was not updated") }) t.Run("no track permission", func(t *testing.T) { @@ -248,7 +251,10 @@ func TestUnsubscribe(t *testing.T) { // no traces should be left require.Len(t, sm.GetSubscribedTracks(), 0) - require.False(t, res.TrackChangedNotifier.HasObservers()) + // the observer is dropped on a goroutine of its own + require.Eventually(t, func() bool { + return !res.TrackChangedNotifier.HasObservers() + }, subSettleTimeout, subCheckInterval, "observer was not removed") tl := sm.params.Participant.GetTelemetryListener().(*typesfakes.FakeParticipantTelemetryListener) require.Equal(t, 1, tl.OnTrackUnsubscribedCallCount())