Skip to content

Commit 6790a69

Browse files
committed
Tests: Wait for PulseAudio context destruction in TestPlaybackStream
The stream was being kept alive until the moment before we check if the context is still alive. The stream's control thread holds a reference to the PulseAudioContext, so that should almost never be destroyed before the VERIFY in the test. Instead, wait at most 100ms for it to be destroyed.
1 parent 69cede4 commit 6790a69

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Tests/LibMedia/TestPlaybackStream.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ TEST_CASE(create_and_destroy_playback_stream)
3838
return buffer.trim(writing_stream.offset());
3939
});
4040
EXPECT_EQ(!stream_result.is_error(), has_implementation);
41-
MUST(Core::System::sleep_ms(100));
4241
}
4342

4443
#if defined(HAVE_PULSEAUDIO)
45-
VERIFY(!Audio::PulseAudioContext::is_connected());
44+
// The PulseAudio context is kept alive by the PlaybackStream's control thread, which blocks on
45+
// some operations, so it won't necessarily be destroyed immediately.
46+
auto wait_start = MonotonicTime::now_coarse();
47+
while (Audio::PulseAudioContext::is_connected()) {
48+
if (MonotonicTime::now_coarse() - wait_start > AK::Duration::from_milliseconds(100))
49+
VERIFY_NOT_REACHED();
50+
}
4651
#endif
4752
}

0 commit comments

Comments
 (0)