@@ -79,6 +79,14 @@ class SubscriptionThreadDispatcherTest : public ::testing::Test {
7979 static auto & activeDataReaders (SubscriptionThreadDispatcher& dispatcher) { return dispatcher.active_data_readers_ ; }
8080 static auto & remoteDataTracks (SubscriptionThreadDispatcher& dispatcher) { return dispatcher.remote_data_tracks_ ; }
8181 static int maxActiveReaders () { return SubscriptionThreadDispatcher::kMaxActiveReaders ; }
82+ static std::size_t activeReaderCount (SubscriptionThreadDispatcher& dispatcher) {
83+ const std::scoped_lock<std::mutex> lock (dispatcher.lock_ );
84+ return dispatcher.active_readers_ .size ();
85+ }
86+ static std::size_t activeDataReaderCount (SubscriptionThreadDispatcher& dispatcher) {
87+ const std::scoped_lock<std::mutex> lock (dispatcher.lock_ );
88+ return dispatcher.active_data_readers_ .size ();
89+ }
8290
8391 static std::thread extractDataReader (SubscriptionThreadDispatcher& dispatcher, DataFrameCallbackId id) {
8492 const std::scoped_lock<std::mutex> lock (dispatcher.lock_ );
@@ -592,14 +600,14 @@ TEST_F(SubscriptionThreadDispatcherTest, DuplicateSubscribeWithSameAudioSidDoesN
592600 // Simulate an already-running reader for this subscription.
593601 const CallbackKey key{" alice" , " mic" };
594602 activeReaders (dispatcher)[key].track_sid = " TR_audio_1" ;
595- ASSERT_EQ (dispatcher. activeReaderCount (), 1u );
603+ ASSERT_EQ (activeReaderCount (dispatcher ), 1u );
596604
597605 // A duplicate track_subscribed carrying the same SID must be a no-op: no
598606 // extract, no new stream/thread.
599607 auto track = std::make_shared<FakeMediaTrack>(" TR_audio_1" , TrackKind::KIND_AUDIO );
600608 dispatcher.handleTrackSubscribed (" alice" , " mic" , track);
601609
602- EXPECT_EQ (dispatcher. activeReaderCount (), 1u );
610+ EXPECT_EQ (activeReaderCount (dispatcher ), 1u );
603611 EXPECT_EQ (activeReaders (dispatcher)[key].track_sid , " TR_audio_1" );
604612 EXPECT_EQ (activeReaders (dispatcher)[key].audio_stream , nullptr ) << " Reader must not have been rebuilt" ;
605613}
@@ -610,12 +618,12 @@ TEST_F(SubscriptionThreadDispatcherTest, DuplicateSubscribeWithSameVideoSidDoesN
610618
611619 const CallbackKey key{" alice" , " cam" };
612620 activeReaders (dispatcher)[key].track_sid = " TR_video_1" ;
613- ASSERT_EQ (dispatcher. activeReaderCount (), 1u );
621+ ASSERT_EQ (activeReaderCount (dispatcher ), 1u );
614622
615623 auto track = std::make_shared<FakeMediaTrack>(" TR_video_1" , TrackKind::KIND_VIDEO );
616624 dispatcher.handleTrackSubscribed (" alice" , " cam" , track);
617625
618- EXPECT_EQ (dispatcher. activeReaderCount (), 1u );
626+ EXPECT_EQ (activeReaderCount (dispatcher ), 1u );
619627 EXPECT_EQ (activeReaders (dispatcher)[key].track_sid , " TR_video_1" );
620628 EXPECT_EQ (activeReaders (dispatcher)[key].video_stream , nullptr ) << " Reader must not have been rebuilt" ;
621629}
@@ -635,7 +643,7 @@ TEST_F(SubscriptionThreadDispatcherTest, DuplicateDataPublishWithSameSidDoesNotR
635643 auto old_thread = startDataReader (dispatcher, 7 , DataCallbackKey{" alice" , " foo" }, incoming);
636644
637645 EXPECT_FALSE (old_thread.joinable ());
638- EXPECT_EQ (dispatcher. activeDataReaderCount (), 1u );
646+ EXPECT_EQ (activeDataReaderCount (dispatcher ), 1u );
639647 EXPECT_EQ (activeDataReaders (dispatcher)[7 ], reader) << " Same-SID publish must not replace the reader" ;
640648 EXPECT_FALSE (reader->cancelled .load ()) << " A skipped reader must not be cancelled" ;
641649}
@@ -658,7 +666,7 @@ TEST_F(SubscriptionThreadDispatcherTest, RepublishWithNewDataSidStopsPreviousRea
658666
659667 // The replacement reader has an invalid FFI handle, so its subscribe fails
660668 // fast and it removes its own slot. Confirm nothing is left behind.
661- EXPECT_TRUE (waitFor ([&] { return dispatcher. activeDataReaderCount () == 0 ; }, 2s));
669+ EXPECT_TRUE (waitFor ([&] { return activeDataReaderCount (dispatcher ) == 0 ; }, 2s));
662670}
663671
664672// ============================================================================
0 commit comments