Skip to content

Commit c2bd1be

Browse files
move functions to test
1 parent d62ec8e commit c2bd1be

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

include/livekit/subscription_thread_dispatcher.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,6 @@ class LIVEKIT_API SubscriptionThreadDispatcher {
234234
/// thread survives beyond the lifetime of the owning @ref Room.
235235
void stopAll();
236236

237-
/// @brief Number of active audio/video reader threads. Intended for tests.
238-
/// @return Count of currently active audio and video reader slots.
239-
std::size_t activeReaderCount() const;
240-
241-
/// @brief Number of active data track reader threads. Intended for tests.
242-
/// @return Count of currently active data reader slots.
243-
std::size_t activeDataReaderCount() const;
244-
245237
private:
246238
friend class SubscriptionThreadDispatcherTest;
247239

src/subscription_thread_dispatcher.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,6 @@ void SubscriptionThreadDispatcher::stopAll() {
339339
LK_LOG_DEBUG("Stopped {} subscription reader threads", threads.size());
340340
}
341341

342-
std::size_t SubscriptionThreadDispatcher::activeReaderCount() const {
343-
const std::scoped_lock<std::mutex> lock(lock_);
344-
return active_readers_.size();
345-
}
346-
347-
std::size_t SubscriptionThreadDispatcher::activeDataReaderCount() const {
348-
const std::scoped_lock<std::mutex> lock(lock_);
349-
return active_data_readers_.size();
350-
}
351-
352342
std::thread SubscriptionThreadDispatcher::extractReaderThreadLocked(const CallbackKey& key) {
353343
auto it = active_readers_.find(key);
354344
if (it == active_readers_.end()) {

src/tests/unit/test_subscription_thread_dispatcher.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)