Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
test(verify): cover the export encoder fallback with an injected encoder failure
Richie McIlroy65b2712e00b5
diff --git a/crates/verify/Cargo.toml b/crates/verify/Cargo.tomlindex f81f0e553..9266ed705 100644--- a/crates/verify/Cargo.toml+++ b/crates/verify/Cargo.toml@@ -33,7 +33,7 @@ cidre = { workspace = true }cap-recording = { path = "../recording", features = ["test-utils"] }cap-editor = { path = "../editor", features = ["test-hooks"] }cap-audio = { path = "../audio" }-cap-export = { path = "../export" }+cap-export = { path = "../export", features = ["test-hooks"] }cap-rendering = { path = "../rendering" }cpal = { workspace = true }tempfile = "3"diff --git a/crates/verify/tests/audio.rs b/crates/verify/tests/audio.rsindex 714ee5fbb..8789c9697 100644--- a/crates/verify/tests/audio.rs+++ b/crates/verify/tests/audio.rs@@ -161,7 +161,7 @@ const FPS: u32 = 30;const RES: (u32, u32) = (320, 180);fn export_case(spec: &FixtureSpec, variant: &Variant, path: ExportPath) -> Option<String> {- export_case_at(spec, variant, path, FPS)+ export_case_at(spec, variant, path, FPS, None)}fn export_case_at(@@ -169,6 +169,7 @@ fn export_case_at(variant: &Variant,path: ExportPath,fps: u32,+ video_encoder_failure_at: Option<u32>,) -> Option<String> {let id = format!("audio/{}/{}/{}{fps}", spec.name, variant.edit, path.label());if !report::selected(&id) {@@ -180,13 +181,14 @@ fn export_case_at((variant.apply)(&mut config);let mut case = Case::new(&id);let dir = common::scratch_dir(&id);- match rt.block_on(audio_support::export(+ match rt.block_on(audio_support::export_failing_encoder_at(&project,config.clone(),path,fps,RES,dir.path(),+ video_encoder_failure_at,)) {Err(e) => case.problem("error", format!("export failed: {e}")),Ok(out) => match path {@@ -201,6 +203,17 @@ fn export_case_at();}_ => {+ // libx264 tags its stream with a version SEI; the restarted+ // export must come from it.+ if video_encoder_failure_at.is_some()+ && !std::fs::read(&out)+ .is_ok_and(|bytes| bytes.windows(11).any(|w| w == b"x264 - core"))+ {+ case.problem(+ "error",+ "export after the video encoder failed was not encoded by libx264",+ );+ }let model = audio_support::audio_model(&project, &config);match audio_support::exported_mono(&out) {Err(e) => case.problem("error", e),@@ -266,12 +279,31 @@ fn export_studio_sound_low_fps() {},ExportPath::App,10,+ None,).into_iter().collect();assert!(failures.is_empty(), "{}", failures.join("\n"));}+/// A hardware video encoder can fail mid-export when the media engine is+/// busy or resets (VideoToolbox error -19092 on shared macOS runners). The+/// export restarts on libx264 and must still match the audio and video+/// models, on the streaming (app) and in-memory (plain) audio paths.+#[test]+fn encoder_fallback() {+ let spec = audio_fixture::mix(report::tier());+ let variant = Variant {+ edit: "encoder-fallback",+ apply: full,+ };+ let failures: Vec<String> = [ExportPath::App, ExportPath::Plain]+ .into_iter()+ .filter_map(|path| export_case_at(&spec, &variant, path, FPS, Some(FPS * 3)))+ .collect();+ assert!(failures.is_empty(), "{}", failures.join("\n"));+}+#[test]fn studio_sound_music() {let spec = audio_fixture::mix(report::tier());diff --git a/crates/verify/tests/audio_support/mod.rs b/crates/verify/tests/audio_support/mod.rsindex 07e8500e3..c92fe3db9 100644--- a/crates/verify/tests/audio_support/mod.rs+++ b/crates/verify/tests/audio_support/mod.rs@@ -265,6 +265,20 @@ pub async fn export(fps: u32,resolution: (u32, u32),dir: &Path,+) -> Result<PathBuf, String> {+ export_failing_encoder_at(project, config, path, fps, resolution, dir, None).await+}++/// [`export`], with the MP4 video encoder failing after+/// `video_encoder_failure_at` frames as a hardware encoder does at runtime.+pub async fn export_failing_encoder_at(+ project: &Project,+ config: ProjectConfiguration,+ path: ExportPath,+ fps: u32,+ resolution: (u32, u32),+ dir: &Path,+ video_encoder_failure_at: Option<u32>,) -> Result<PathBuf, String> {let out = dir.join(format!("out.{}", path.extension()));let builder = cap_export::ExporterBase::builder(project.path.clone())@@ -282,17 +296,23 @@ pub async fn export(match path {ExportPath::App => {let cancel = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));- let base = builder+ let mut base = builder.build_for_mp4(cancel).await.map_err(|e| format!("exporter build: {e}"))?;+ if let Some(frames) = video_encoder_failure_at {+ base.fail_video_encoder_at(frames);+ }mp4.export_prepared(base, |_| true).await}ExportPath::Plain => {- let base = builder+ let mut base = builder.build().await.map_err(|e| format!("exporter build: {e}"))?;+ if let Some(frames) = video_encoder_failure_at {+ base.fail_video_encoder_at(frames);+ }mp4.export(base, |_| true).await}ExportPath::Mov => {diff --git a/scripts/verify/suites.json b/scripts/verify/suites.jsonindex cdc47dadb..3f19a2759 100644--- a/scripts/verify/suites.json+++ b/scripts/verify/suites.json@@ -191,14 +191,14 @@"cases": {"prefix": "audio/","fast": {- "linux": 56,- "macos": 40,- "windows": 39+ "linux": 58,+ "macos": 41,+ "windows": 40},"full": {- "linux": 58,- "macos": 58,- "windows": 58+ "linux": 60,+ "macos": 60,+ "windows": 60}}},