source · Rust

Log

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