Skip to content

Commit 86240ec

Browse files
thewrzclaude
andcommitted
refactor(tests): capture generation values instead of hardcoding literals
Addresses CodeRabbit nitpick on PR #186; keeps the concurrent-decode tests resilient to generation-counter changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ce256ee commit 86240ec

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/app/playback/cache_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ fn pcm_eviction_keeps_active_waveform_envelope() {
6666
// Two cold presses in concurrent mode: B is the newest press and its
6767
// decode lands first, so B owns the now-playing UI.
6868
let _ = app.request_play(&a, false);
69+
let a_generation = app.play_generation;
6970
let _ = app.request_play(&b, false);
70-
let _ = app.handle_decoded("b".into(), Ok(pcm(4)), dispatch(&app, 2));
71+
let b_generation = app.play_generation;
72+
let _ = app.handle_decoded("b".into(), Ok(pcm(4)), dispatch(&app, b_generation));
7173
assert!(app.now_playing.envelope("b").is_some());
7274

7375
// The late older decode for A lands and evicts B's PCM under cache
7476
// pressure while B is still the active now-playing sound.
75-
let _ = app.handle_decoded("a".into(), Ok(pcm(8)), dispatch(&app, 1));
77+
let _ = app.handle_decoded("a".into(), Ok(pcm(8)), dispatch(&app, a_generation));
7678

7779
assert!(
7880
app.audio_store.get_pcm("b").is_none(),

src/app/playback/tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,19 @@ fn late_concurrent_decode_keeps_newest_in_now_playing() {
201201
app.sounds = vec![sound("a"), sound("b")];
202202
// Default overlap mode is Concurrent, so superseded presses stay pending.
203203

204-
// Two cold presses: each bumps the generation (A=1, B=2) and, in
205-
// concurrent mode, both stay pending awaiting their decode.
204+
// Two cold presses: each bumps the generation and, in concurrent mode,
205+
// both stay pending awaiting their decode.
206206
let a = app.sounds[0].clone();
207207
let b = app.sounds[1].clone();
208208
let _ = app.request_play(&a, false);
209+
let a_generation = app.play_generation;
209210
let _ = app.request_play(&b, false);
211+
let b_generation = app.play_generation;
210212

211213
// Decodes land out of order: the newest press (B) finishes first, then
212214
// the older press (A).
213-
let _ = app.handle_decoded("b".into(), Ok(pcm(16)), dispatch(&app, 2));
214-
let _ = app.handle_decoded("a".into(), Ok(pcm(16)), dispatch(&app, 1));
215+
let _ = app.handle_decoded("b".into(), Ok(pcm(16)), dispatch(&app, b_generation));
216+
let _ = app.handle_decoded("a".into(), Ok(pcm(16)), dispatch(&app, a_generation));
215217

216218
// The older decode must still start its audio (cached + accepted, not
217219
// dropped as stale)...

0 commit comments

Comments
 (0)