//! What more than one integration test of this crate needs (a test binary //! that uses it declares `mod common;`). use std::path::{Path, PathBuf}; use std::time::Duration; /// Wait until nothing has the SQLite database at `path` open any more, as when /// the process that had it has ended: SQLite deletes the write-ahead log /// (`-wal`) when the last connection closes. /// /// A dropped `Engine` is not that yet. Its task ends later, the history writer /// is joined there, and closing the connection checkpoints the log under an /// exclusive lock, with fsyncs. A connection opened meanwhile waits for the /// lock only as long as the busy timeout (5 s) and then fails with /// `DatabaseBusy`, which a loaded disk makes happen (with every fsync taking /// 6 s it happens every time). pub async fn closed(path: &Path) { let mut wal = path.as_os_str().to_owned(); wal.push("-wal"); let wal = PathBuf::from(wal); tokio::time::timeout(Duration::from_secs(120), async { while wal.exists() { tokio::time::sleep(Duration::from_millis(10)).await; } }) .await .expect("the engine's database connection closed"); }