Skip to content

Commit 12a3955

Browse files
committed
Rewrite test for #369 so it can be run without a true audio backend
1 parent c30aa91 commit 12a3955

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/online.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,26 @@ fn test_channels() {
125125
#[test]
126126
fn test_panner_node_drop_panic() {
127127
// https://github.com/orottier/web-audio-api-rs/issues/369
128-
let context = AudioContext::default();
128+
let options = AudioContextOptions {
129+
sink_id: "none".into(),
130+
..AudioContextOptions::default()
131+
};
132+
let context = AudioContext::new(options);
129133

134+
// create a new panner and drop it
130135
let panner = context.create_panner();
131136
drop(panner);
132-
std::thread::sleep(std::time::Duration::from_millis(100));
137+
138+
// allow the audio render thread to boot and handle adding and dropping the panner
139+
std::thread::sleep(std::time::Duration::from_millis(200));
140+
141+
// creating a new panner node should not crash the render thread
133142
let mut _panner = context.create_panner();
134-
std::thread::sleep(std::time::Duration::from_millis(100));
143+
144+
// A crashed thread will not fail the test (only if the main thread panics).
145+
// Instead inspect if there is progression of time in the audio context.
146+
147+
let time = context.current_time();
148+
std::thread::sleep(std::time::Duration::from_millis(200));
149+
assert!(context.current_time() >= time + 0.15);
135150
}

0 commit comments

Comments
 (0)