Skip to content

Commit ae41894

Browse files
refactor(audio): fix flaky test
test_seek_commands was being flaky bc of the relative timing of the "lock" and "sleep" within the duration watch loop
1 parent 9051fa3 commit ae41894

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/audio/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,8 @@ impl AudioKernel {
238238
) {
239239
break;
240240
}
241-
std::thread::sleep(DURATION_WATCHER_TICK);
242-
241+
let mut duration_info = duration_info.lock().unwrap();
243242
if *status.lock().unwrap() == Status::Playing {
244-
let mut duration_info = duration_info.lock().unwrap();
245243
// if we aren't paused, increment the time played
246244
duration_info.time_played += DURATION_WATCHER_TICK;
247245
// if we're within the threshold of the end of the song,
@@ -256,6 +254,8 @@ impl AudioKernel {
256254
}
257255
}
258256
}
257+
drop(duration_info);
258+
std::thread::sleep(DURATION_WATCHER_TICK);
259259
}
260260
});
261261

@@ -1593,17 +1593,18 @@ mod tests {
15931593
OneOrMany::One(song.clone()),
15941594
))));
15951595
sender.send(AudioCommand::Stop);
1596-
let state: StateAudio = get_state(sender.clone()).await;
15971596
sender.send(AudioCommand::Seek(
15981597
SeekType::Absolute,
15991598
Duration::from_secs(0),
16001599
));
1600+
let state: StateAudio = get_state(sender.clone()).await;
16011601
assert_eq!(state.queue_position, Some(0));
16021602
assert_eq!(state.status, Status::Stopped);
16031603
assert_eq!(
16041604
state.runtime.unwrap().duration,
16051605
Duration::from_secs(10) + Duration::from_nanos(6)
16061606
);
1607+
assert_eq!(state.runtime.unwrap().seek_position, Duration::from_secs(0));
16071608

16081609
// skip ahead a bit
16091610
sender.send(AudioCommand::Seek(

0 commit comments

Comments
 (0)