Files
oak-editor/crates/oaktask/tests/customcache_test.rs
T
Mike-Solar 18ff60f147 feat(engine): clip move, clip effect_input, mandatory static FFmpeg
- oakengine_sequence_move_clip implemented for real (oaktimeline
  TrackMoveBlockCommand; fixes the graph-ownership/gap-anchor/ripple
  trim bugs the stub was hiding); same-track via the frozen C ABI,
  cross-track supported by the module command
- oaknode clip blocks now declare a tex_in texture input and set
  effect_input to it, so timeline clips can host effect chains; facade
  test covers effect insert/remove on a real clip
- oakffmpeg-link: FFMPEG_DIR is now mandatory with a clear panic (a
  Homebrew upgrade left the system ffmpeg .pc pointing at a deleted
  dav1d Cellar path, breaking links); reads a git-ignored workspace
  .env for IDEs that cannot inject env vars (RustRover); links the C++
  stdlib for C++ codec libs (svt-av1)
- oakengine re-exports oaknode so tests share one crate instance;
  it_node uses the direct instance's value type where it calls the
  module FFI (the --workspace dev-dependency feature split builds
  oaknode twice)
2026-08-11 23:04:48 +08:00

124 lines
4.0 KiB
Rust

// Oak Video Editor - Non-Linear Video Editor
// Copyright (C) 2026 Oak Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! CustomCacheTask lifecycle tests: the task parks until `finish()` (success)
//! or a real cancellation (`Err(Cancelled)`); the cancelled callback fires
//! only for real cancellations.
mod common;
use common::*;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use oaktask::customcache::CustomCacheTask;
use oaktask::task::Task;
fn spawn_parked(
cc: CustomCacheTask,
) -> (
std::thread::JoinHandle<oaktask::error::Result<()>>,
Arc<oaktask::customcache::CustomCacheState>,
) {
let state = cc.state();
let atom = cc.base.get_cancel_atom();
let title = cc.base.title().to_string();
let mut outer = Task::new(&title, atom);
outer.set_behavior(Box::new(cc));
let handle = std::thread::spawn(move || outer.start());
// Let the worker park on the condvar.
std::thread::sleep(std::time::Duration::from_millis(50));
(handle, state)
}
/// The task title mirrors the C++ constructor; finishing wakes the parked
/// task which then reports success.
#[test]
fn finish_completes_parked_task() {
let _guard = MANAGER_LOCK.lock().unwrap();
reset_stubs();
let cc = CustomCacheTask::new("my-sequence");
assert_eq!(cc.base.title(), "Caching custom range for \"my-sequence\"");
let (handle, state) = spawn_parked(cc);
state.finish();
let result = handle.join().expect("worker panicked");
assert!(
result.is_ok(),
"finish should complete the task successfully"
);
// Re-run: a real cancel (no finish) reports Err(Cancelled).
let cc = CustomCacheTask::new("cancel-seq");
let (handle, state) = spawn_parked(cc);
state.cancel();
let result = handle.join().expect("worker panicked");
assert!(result.is_err(), "real cancellation should fail the task");
}
/// The cancelled callback fires only for a real cancellation, not for
/// `finish()`.
#[test]
fn cancelled_callback_fires_only_on_real_cancel() {
let _guard = MANAGER_LOCK.lock().unwrap();
reset_stubs();
// finish(): the callback must NOT fire.
let fired_on_finish = Arc::new(AtomicBool::new(false));
let mut cc = CustomCacheTask::new("finish-seq");
cc.set_cancelled_callback(Box::new({
let flag = fired_on_finish.clone();
move || flag.store(true, Ordering::SeqCst)
}));
let (handle, state) = spawn_parked(cc);
state.finish();
assert!(handle.join().expect("worker panicked").is_ok());
assert!(
!fired_on_finish.load(Ordering::SeqCst),
"finish must not fire the cancelled callback"
);
// real cancel: the callback fires.
let fired_on_cancel = Arc::new(AtomicBool::new(false));
let mut cc = CustomCacheTask::new("cancel-seq");
cc.set_cancelled_callback(Box::new({
let flag = fired_on_cancel.clone();
move || flag.store(true, Ordering::SeqCst)
}));
let (handle, state) = spawn_parked(cc);
state.cancel();
assert!(handle.join().expect("worker panicked").is_err());
assert!(
fired_on_cancel.load(Ordering::SeqCst),
"real cancel must fire the cancelled callback"
);
}
/// The cancel hook wakes the parked task even without finish().
#[test]
fn cancel_hook_wakes_parked_task() {
let _guard = MANAGER_LOCK.lock().unwrap();
reset_stubs();
let cc = CustomCacheTask::new("wake-seq");
let (handle, state) = spawn_parked(cc);
// Simulate the manager's cancel path (base.cancel -> atom + hook).
state.cancel();
let result = handle.join().expect("worker panicked");
assert!(result.is_err());
}