//! Synthetic performance contract for the upstream media queues. //! //! Scope: deterministic backpressure simulation without physical devices. //! Targets: `client/src/uplink_latency_harness.rs`. //! Why: A/V sync depends on dropping stale media under stalls instead of //! preserving a growing delay buffer. #[path = "../../client/src/uplink_latency_harness.rs"] #[allow(warnings)] mod uplink_latency_harness; use std::time::Duration; use uplink_latency_harness::{UplinkHarnessConfig, UplinkQueuePolicy, run_uplink_harness}; fn camera_stall_config() -> UplinkHarnessConfig { UplinkHarnessConfig { capture_interval: Duration::from_millis(33), consume_interval: Duration::from_millis(33), queue_capacity: 32, freshness_max_age: Some(Duration::from_millis(350)), total_packets: 240, stall_after: Some(Duration::from_millis(800)), stall_duration: Duration::from_secs(2), } } fn microphone_stall_config() -> UplinkHarnessConfig { UplinkHarnessConfig { capture_interval: Duration::from_millis(20), consume_interval: Duration::from_millis(20), queue_capacity: 16, freshness_max_age: Some(Duration::from_millis(400)), total_packets: 320, stall_after: Some(Duration::from_millis(600)), stall_duration: Duration::from_secs(2), } } #[test] fn freshness_first_camera_policy_keeps_video_delivery_age_bounded_under_stall() { let result = run_uplink_harness(camera_stall_config(), UplinkQueuePolicy::DropOldestWhenFull); assert!( result.dropped_packets > 0, "camera stall should drop stale frames instead of preserving backlog" ); assert!( result.max_delivery_age <= Duration::from_millis(350), "camera delivery age must stay <=350ms under synthetic stall, got {:?}", result.max_delivery_age ); } #[test] fn freshness_first_microphone_policy_keeps_audio_delivery_age_bounded_under_stall() { let result = run_uplink_harness( microphone_stall_config(), UplinkQueuePolicy::DropOldestWhenFull, ); assert!( result.dropped_packets > 0, "microphone stall should drop stale chunks instead of preserving backlog" ); assert!( result.max_delivery_age <= Duration::from_millis(400), "microphone delivery age must stay <=400ms under synthetic stall, got {:?}", result.max_delivery_age ); } #[test] fn preserve_backlog_policy_would_violate_the_lip_sync_budget() { let mut config = camera_stall_config(); config.freshness_max_age = None; let result = run_uplink_harness(config, UplinkQueuePolicy::PreserveBacklog); assert!( result.max_delivery_age >= Duration::from_secs(1), "preserve-backlog policy should demonstrate the regression class, got {:?}", result.max_delivery_age ); }