Bug 1656438 - Simplify TestAudioTrackGraph.ErrorStateCrash. r=padenot

Depends on D89746

Differential Revision: https://phabricator.services.mozilla.com/D89747
This commit is contained in:
Andreas Pehrson 2020-09-15 11:53:52 +00:00
Родитель ec3f42e3a3
Коммит 102d6e1cc5
2 изменённых файлов: 21 добавлений и 16 удалений

Просмотреть файл

@ -201,6 +201,8 @@ class MockCubebStream {
return mFramesProcessedEvent; return mFramesProcessedEvent;
} }
MediaEventSource<void>& ErrorForcedEvent() { return mErrorForcedEvent; }
private: private:
// Simulates the audio thread. The thread is created at Start anda destroyed // Simulates the audio thread. The thread is created at Start anda destroyed
// at Stop. At next StreamStart a new thread is created. // at Stop. At next StreamStart a new thread is created.
@ -228,7 +230,9 @@ class MockCubebStream {
break; break;
} }
if (mForceErrorState) { if (mForceErrorState) {
mForceErrorState = false;
mStateCallback(stream, mUserPtr, CUBEB_STATE_ERROR); mStateCallback(stream, mUserPtr, CUBEB_STATE_ERROR);
mErrorForcedEvent.Notify();
break; break;
} }
uint32_t sampleRate(mInputParams.rate ? mInputParams.rate uint32_t sampleRate(mInputParams.rate ? mInputParams.rate
@ -280,6 +284,7 @@ class MockCubebStream {
AudioVerifier<AudioDataValue> mAudioVerifier; AudioVerifier<AudioDataValue> mAudioVerifier;
MediaEventProducer<uint32_t> mFramesProcessedEvent; MediaEventProducer<uint32_t> mFramesProcessedEvent;
MediaEventProducer<void> mErrorForcedEvent;
}; };
// This class has two facets: it is both a fake cubeb backend that is intended // This class has two facets: it is both a fake cubeb backend that is intended

Просмотреть файл

@ -247,25 +247,25 @@ TEST(TestAudioTrackGraph, ErrorStateCrash)
MediaTrackGraph::AUDIO_THREAD_DRIVER, /*window*/ nullptr, MediaTrackGraph::AUDIO_THREAD_DRIVER, /*window*/ nullptr,
MediaTrackGraph::REQUEST_DEFAULT_SAMPLE_RATE, nullptr); MediaTrackGraph::REQUEST_DEFAULT_SAMPLE_RATE, nullptr);
// Dummy track to make graph rolling. Add it and remove it to remove the RefPtr<SourceMediaTrack> dummySource;
// graph from the global hash table and let it shutdown. auto started = Invoke([&] {
RefPtr<SourceMediaTrack> dummySource = // Dummy track to make graph rolling. Add it and remove it to remove the
graph->CreateSourceTrack(MediaSegment::AUDIO); // graph from the global hash table and let it shutdown.
dummySource = graph->CreateSourceTrack(MediaSegment::AUDIO);
return graph->NotifyWhenDeviceStarted(dummySource);
});
RefPtr<GenericPromise> p = graph->NotifyWhenDeviceStarted(dummySource); MockCubebStream* stream = WaitFor(cubeb->StreamInitEvent());
Result<bool, nsresult> rv = WaitFor(started);
EXPECT_TRUE(rv.unwrapOr(false));
GMPTestMonitor mon; // Force a cubeb state_callback error and see that we don't crash.
DispatchFunction([&] { stream->ForceError(); });
WaitFor(stream->ErrorForcedEvent());
p->Then(GetMainThreadSerialEventTarget(), __func__, // Test has finished, destroy the track to shut down the MTG.
[&mon, dummySource, cubeb]() { DispatchMethod(dummySource, &SourceMediaTrack::Destroy);
cubeb->CurrentStream()->ForceError(); WaitFor(cubeb->StreamDestroyEvent());
std::this_thread::sleep_for(std::chrono::milliseconds(50));
// Test has finished, destroy the track to shutdown the MTG.
dummySource->Destroy();
mon.SetFinished();
});
mon.AwaitFinished();
} }
TEST(TestAudioTrackGraph, SourceTrack) TEST(TestAudioTrackGraph, SourceTrack)