@@ -9,6 +9,7 @@ use web_audio_api::context::{
9
9
use web_audio_api:: node:: AudioNode ;
10
10
11
11
use std:: sync:: atomic:: { AtomicBool , AtomicU32 , Ordering } ;
12
+ use std:: time:: Duration ;
12
13
use web_audio_api:: MAX_CHANNELS ;
13
14
14
15
fn require_send_sync_static < T : Send + Sync + ' static > ( _: T ) { }
@@ -94,7 +95,7 @@ fn test_none_sink_id() {
94
95
} ) ;
95
96
96
97
// give event thread some time to pick up events
97
- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 20 ) ) ;
98
+ std:: thread:: sleep ( Duration :: from_millis ( 5 ) ) ;
98
99
assert_eq ! ( state_changes. load( Ordering :: Relaxed ) , 1 ) ; // started
99
100
100
101
// changing sink_id to 'none' again should make no changes
@@ -107,15 +108,24 @@ fn test_none_sink_id() {
107
108
108
109
context. suspend_sync ( ) ;
109
110
assert_eq ! ( context. state( ) , AudioContextState :: Suspended ) ;
111
+
112
+ // give event thread some time to pick up events
113
+ std:: thread:: sleep ( Duration :: from_millis ( 5 ) ) ;
110
114
assert_eq ! ( state_changes. load( Ordering :: Relaxed ) , 2 ) ; // suspended
111
115
112
116
context. resume_sync ( ) ;
113
117
assert_eq ! ( context. state( ) , AudioContextState :: Running ) ;
118
+
119
+ // give event thread some time to pick up events
120
+ std:: thread:: sleep ( Duration :: from_millis ( 5 ) ) ;
114
121
assert_eq ! ( state_changes. load( Ordering :: Relaxed ) , 3 ) ; // resumed
115
122
116
123
context. close_sync ( ) ;
117
124
assert_eq ! ( context. state( ) , AudioContextState :: Closed ) ;
118
125
assert ! ( sink_stable. load( Ordering :: SeqCst ) ) ;
126
+
127
+ // give event thread some time to pick up events
128
+ std:: thread:: sleep ( Duration :: from_millis ( 5 ) ) ;
119
129
assert_eq ! ( state_changes. load( Ordering :: Relaxed ) , 4 ) ; // closed
120
130
}
121
131
@@ -160,15 +170,15 @@ fn test_panner_node_drop_panic() {
160
170
drop ( panner) ;
161
171
162
172
// allow the audio render thread to boot and handle adding and dropping the panner
163
- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 200 ) ) ;
173
+ std:: thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
164
174
165
175
// creating a new panner node should not crash the render thread
166
176
let mut _panner = context. create_panner ( ) ;
167
177
168
178
// A crashed thread will not fail the test (only if the main thread panics).
169
179
// Instead inspect if there is progression of time in the audio context.
170
180
let time = context. current_time ( ) ;
171
- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 200 ) ) ;
181
+ std:: thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
172
182
assert ! ( context. current_time( ) >= time + 0.15 ) ;
173
183
}
174
184
@@ -187,7 +197,7 @@ fn test_audioparam_outlives_audionode() {
187
197
188
198
// Start the audio graph, and give some time to drop the gain node (it has no inputs connected
189
199
// so dynamic lifetime will drop the node);
190
- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 200 ) ) ;
200
+ std:: thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
191
201
192
202
// We still have a handle to the param, so that should not be removed from the audio graph.
193
203
// So by updating the value, the render thread should not crash.
@@ -196,7 +206,7 @@ fn test_audioparam_outlives_audionode() {
196
206
// A crashed thread will not fail the test (only if the main thread panics).
197
207
// Instead inspect if there is progression of time in the audio context.
198
208
let time = context. current_time ( ) ;
199
- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 200 ) ) ;
209
+ std:: thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
200
210
assert ! ( context. current_time( ) >= time + 0.15 ) ;
201
211
}
202
212
@@ -214,7 +224,7 @@ fn test_closed() {
214
224
drop ( context) ;
215
225
216
226
// allow some time for the render thread to drop
217
- std:: thread:: sleep ( std :: time :: Duration :: from_millis ( 10 ) ) ;
227
+ std:: thread:: sleep ( Duration :: from_millis ( 10 ) ) ;
218
228
219
229
node. disconnect ( ) ; // should not panic
220
230
}
0 commit comments