Skip to content

Commit

Permalink
Wait for the BaseTrackPlayerImpl::newTrackLoaded() signal before perf…
Browse files Browse the repository at this point in the history
…orming tests.

This replaces the uncoditional 100 ms wait time which was not always enough.
  • Loading branch information
daschuer committed Dec 2, 2024
1 parent 98012f3 commit e54815d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/test/stemcontrolobjecttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,31 @@ class StemControlTest : public BaseSignalPathTest {
}

void loadTrack(Deck* pDeck, TrackPointer pTrack) {
BaseSignalPathTest::loadTrack(pDeck, pTrack);
// Because there is connection across the main thread in caching reader
// thread, we need to manually process the eventloop to trigger
// thread, we need to manually process the Qt event loop to trigger
// `BaseTrackPlayerImpl::slotTrackLoaded` Here is the chain of
// connections (Symbol (thread)) EngineDeck::slotLoadTrack (main) ->
// EngineBuffer::loadTrack (main) -> CachingReader*::newTrack (main) ->
// CachingReaderWorker::trackLoaded (CachingReader) ->
// EngineBuffer::loaded (CachingReader, direct) ->
// BaseTrackPlayerImpl::slotTrackLoaded (main)
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents, 100);

TrackPointer pLoadedTrack;
QMetaObject::Connection connection = QObject::connect(pDeck,
&BaseTrackPlayerImpl::newTrackLoaded,
[&pLoadedTrack](
TrackPointer pNewTrack) { pLoadedTrack = pNewTrack; });
BaseSignalPathTest::loadTrack(pDeck, pTrack);

for (int i = 0; i < 2000; ++i) {
if (pLoadedTrack == pTrack) {
break;
}
int maxtime = 1; // ms
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents, maxtime);
// 1 ms for waiting 2 s at max
}
QObject::disconnect(connection);
}

std::unique_ptr<PollingControlProxy> m_pPlay;
Expand Down

0 comments on commit e54815d

Please sign in to comment.