source · Rust

Log

crates/vak-session/src/log.rs
Raw
80.7 KB2,022 lines75 anchorsSnapshot ed4ab258
  1. 2001
  2. 2002 /// A child being spawned holds a duplicate of every open descriptor
  3. 2003 /// until it execs; the duplicate here stands in for one.
  4. 2004 #[test]
  5. 2005 fn the_lock_lasts_exactly_as_long_as_the_handle() {
  6. 2006 let dir = tempfile::tempdir().unwrap();
  7. 2007 let path = dir.path().join("session.jsonl");
  8. 2008 std::fs::write(&path, "").unwrap();
  9. 2009
  10. 2010 let log = SessionLog::open(path.clone()).unwrap();
  11. 2011 assert!(matches!(
  12. 2012 SessionLog::open(path.clone()),
  13. 2013 Err(SessionError::Locked(_))
  14. 2014 ));
  15. 2015
  16. 2016 let duplicate = log.file.file.try_clone().unwrap();
  17. 2017 drop(log);
  18. 2018 SessionLog::open(path).expect("the dropped handle's lock stayed with a duplicate");
  19. 2019 drop(duplicate);
  20. 2020 }
  21. 2021}
  22. 2022