Skip to content

Commit e1a5db9

Browse files
Matt Jorasmeta-codesync[bot]
authored andcommitted
Add comprehensive test suite for MoQ voice AI handler
Summary: Add complete test infrastructure and test suite for MoQVoiceAIHandler and RtGatewayVoiceEngine to validate MoQ protocol handling, audio/image processing, and multi-turn conversation state management. Test infrastructure added: - MockPredictorClient: Captures predictor requests for validation - MockRtGatewayVoiceEngine: Testable voice engine implementation - MockToken2WavClient, MockTrackConsumer: Supporting mocks - AudioTestUtils: Generate/encode realistic audio (sine waves, Opus frames) - waitForCondition: Deterministic async polling helper - test/README.md: Comprehensive testing guide and patterns MoQVoiceAIHandlerTest.cpp tests (11 total): - StreamingObjectHandling, ImageFrameProcessing, MultiTurnConversation - AudioFrameProcessing, TextMessageHandling, EndOfUtteranceHandling - UnsubscribeNotification, VoiceEngineDisabledConfig, EmptyAudioHandling - MultipleAudioFrames, ErrorHandling RtGatewayVoiceEngineTest.cpp tests (3 total): - BasicAudioAccumulation, AudioThresholdTriggering, MultipleAccumulationCycles Key test patterns: - Deterministic polling: waitForCondition replaces arbitrary sleeps - Data-driven validation: Inspect actual predictor requests, not mocks - Realistic test data: Real Opus codec, proper JPEG markers Differential Revision: D88224438 fbshipit-source-id: 3d0bb8e86c650fe39e0a732039294268839c9320
1 parent 385016e commit e1a5db9

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

moxygen/test/MockMoQSession.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
#pragma once
22

3+
#include <thread>
4+
35
#include <moxygen/MoQSession.h>
6+
#include <moxygen/events/MoQFollyExecutorImpl.h>
47

58
namespace moxygen::test {
69

710
// Mock MoQSession for testing relay behavior
811
class MockMoQSession : public MoQSession {
912
public:
13+
// Constructor that accepts an external executor
1014
explicit MockMoQSession(std::shared_ptr<MoQExecutor> exec)
1115
: MoQSession(
1216
folly::MaybeManagedPtr<proxygen::WebTransport>(nullptr),
13-
exec) {}
17+
exec),
18+
ownsEventBase_(false) {}
19+
20+
// Default constructor that creates and manages its own executor
21+
MockMoQSession()
22+
: MoQSession(
23+
folly::MaybeManagedPtr<proxygen::WebTransport>(nullptr),
24+
std::make_shared<MoQFollyExecutorImpl>(&evb_)),
25+
ownsEventBase_(true) {
26+
// Start EventBase in background thread for async operations
27+
evbThread_ = std::thread([this]() { evb_.loopForever(); });
28+
}
29+
30+
~MockMoQSession() {
31+
if (ownsEventBase_) {
32+
// Stop EventBase and wait for thread
33+
evb_.terminateLoopSoon();
34+
if (evbThread_.joinable()) {
35+
evbThread_.join();
36+
}
37+
}
38+
}
1439

1540
MOCK_METHOD(
1641
folly::coro::Task<AnnounceResult>,
@@ -41,6 +66,9 @@ class MockMoQSession : public MoQSession {
4166
}
4267

4368
private:
69+
folly::EventBase evb_;
70+
std::thread evbThread_;
71+
bool ownsEventBase_;
4472
uint64_t nextRequestID_{1};
4573
};
4674

0 commit comments

Comments
 (0)