test(jitter): seq_before wraparound + buffer overflow/resync
Add unit tests for the jitter buffer's untested pure logic: seq_before's wrapping u32 comparison — basic ordering, the u32::MAX→0 forward wrap, and the exact < (1<<31) half-range tipping point (0x7FFF_FFFF before, 0x8000_0000 not) — and insert's MAX_BUFFERED_FRAMES overflow path (caps depth, drops the oldest frame, resyncs the playout head next_seq to the new front). Tests-only; no production change. Implemented by Gemini (junior implementer), reviewed and verified by senior (cargo build + clippy --all-targets + cargo test all green). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -189,4 +189,38 @@ mod tests {
|
||||
jb.insert(5, frame(&mut enc, 600));
|
||||
assert_eq!(jb.packets.len(), 1); // only seq 7 remains buffered
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_seq_before_ordering() {
|
||||
// Basic ordering
|
||||
assert!(seq_before(0, 1));
|
||||
assert!(!seq_before(1, 0));
|
||||
assert!(!seq_before(5, 5));
|
||||
assert!(seq_before(100, 101));
|
||||
assert!(!seq_before(101, 100));
|
||||
|
||||
// Wraparound
|
||||
assert!(seq_before(u32::MAX, 0));
|
||||
assert!(!seq_before(0, u32::MAX));
|
||||
|
||||
// Half-range boundary
|
||||
assert!(seq_before(0, 0x7FFF_FFFF));
|
||||
assert!(!seq_before(0, 0x8000_0000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jitter_buffer_overflow_resync() {
|
||||
let mut jb = JitterBuffer::new().unwrap();
|
||||
assert!(jb.next_seq.is_none());
|
||||
|
||||
let count = MAX_BUFFERED_FRAMES + 1;
|
||||
for seq in 0..count {
|
||||
jb.insert(seq as u32, vec![0u8]);
|
||||
}
|
||||
|
||||
assert_eq!(jb.packets.len(), MAX_BUFFERED_FRAMES);
|
||||
assert!(!jb.packets.contains_key(&0));
|
||||
assert_eq!(jb.next_seq, Some(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user