Skip to content

Commit 35abb49

Browse files
committed
Fix unstable audio console test
Use a one-shot test stream instead of a stream with an arbitrary five-second expiration. This prevents slow CI runners from expiring the stream before URLAudioStream connects to it. Assert the captured stream type explicitly and close it after verification so failures are clearer and resources are released. Fixes #3405 Signed-off-by: Wouter Born <github@maindrain.net>
1 parent 8eda103 commit 35abb49

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

bundles/org.openhab.core.audio/src/test/java/org/openhab/core/audio/internal/AudioConsoleTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.hamcrest.CoreMatchers.*;
1616
import static org.hamcrest.MatcherAssert.assertThat;
17+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
1718
import static org.mockito.Mockito.mock;
1819
import static org.mockito.Mockito.when;
1920

@@ -70,8 +71,6 @@ public void print(String s) {
7071
}
7172
};
7273

73-
private final int testTimeout = 5;
74-
7574
@BeforeEach
7675
public void setUp() throws IOException {
7776
fileHandler = new BundledSoundFileHandler();
@@ -146,25 +145,29 @@ public void audioConsolePlaysStream() throws Exception {
146145
AudioStream audioStream = getByteArrayAudioStream(testByteArray, AudioFormat.CONTAINER_WAVE,
147146
AudioFormat.CODEC_PCM_SIGNED);
148147

149-
String url = serveStream(audioStream, testTimeout);
148+
String url = serveStream(audioStream);
150149

151150
String[] args = { AudioConsoleCommandExtension.SUBCMD_STREAM, url };
152151
audioConsoleCommandExtension.execute(args, consoleMock);
153152

154-
assertThat("The streamed URL was not as expected", ((URLAudioStream) audioSink.audioStream).getURL(), is(url));
153+
URLAudioStream urlAudioStream = assertInstanceOf(URLAudioStream.class, audioSink.audioStream);
154+
assertThat("The streamed URL was not as expected", urlAudioStream.getURL(), is(url));
155+
urlAudioStream.close();
155156
}
156157

157158
@Test
158159
public void audioConsolePlaysStreamForASpecifiedSink() throws Exception {
159160
AudioStream audioStream = getByteArrayAudioStream(testByteArray, AudioFormat.CONTAINER_WAVE,
160161
AudioFormat.CODEC_PCM_SIGNED);
161162

162-
String url = serveStream(audioStream, testTimeout);
163+
String url = serveStream(audioStream);
163164

164165
String[] args = { AudioConsoleCommandExtension.SUBCMD_STREAM, audioSink.getId(), url };
165166
audioConsoleCommandExtension.execute(args, consoleMock);
166167

167-
assertThat("The streamed URL was not as expected", ((URLAudioStream) audioSink.audioStream).getURL(), is(url));
168+
URLAudioStream urlAudioStream = assertInstanceOf(URLAudioStream.class, audioSink.audioStream);
169+
assertThat("The streamed URL was not as expected", urlAudioStream.getURL(), is(url));
170+
urlAudioStream.close();
168171
}
169172

170173
@Test

0 commit comments

Comments
 (0)