-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Discards clean_test_sqlite3 since it breaks parallel tests and i…
…ntroduces SqliteDatabaseCleaner (#154) Co-authored-by: workflow user <workflow@example.com>
- Loading branch information
Showing
19 changed files
with
111 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,11 @@ | ||
use apllodb_test_support::setup::setup_test_logger; | ||
use glob::glob; | ||
use std::env; | ||
pub mod sqlite_database_cleaner; | ||
pub mod util; | ||
|
||
pub use util::*; | ||
|
||
use apllodb_shared_components::ApllodbResult; | ||
use apllodb_test_support::setup::setup_test_logger; | ||
|
||
/// general test setup sequence | ||
pub fn test_setup() { | ||
setup_test_logger(); | ||
clean_test_sqlite3().unwrap(); | ||
} | ||
|
||
/// recursively rm all test sqlite3 files under PWD. | ||
pub fn clean_test_sqlite3() -> ApllodbResult<()> { | ||
let cd = env::current_dir()?; | ||
|
||
log::debug!( | ||
"clean_test_sqlite3(): searching .sqlite3* files under current dir: {}", | ||
cd.display() | ||
); | ||
|
||
// TODO prevent removing non-test database files | ||
for entry in glob("./**/*.sqlite3*").unwrap() { | ||
if let Ok(path) = entry { | ||
log::debug!( | ||
"clean_test_sqlite3(): found {}. removing...", | ||
path.display() | ||
); | ||
std::fs::remove_file(&path)?; | ||
} | ||
} | ||
|
||
log::debug!("clean_test_sqlite3(): done",); | ||
|
||
Ok(()) | ||
} |
34 changes: 34 additions & 0 deletions
34
apllodb-immutable-schema-engine-infra/src/test_support/sqlite_database_cleaner.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::sqlite::database::SqliteDatabase; | ||
use apllodb_shared_components::DatabaseName; | ||
use glob::glob; | ||
|
||
/// Removes sqlite3 database file on drop(). | ||
/// | ||
/// Use this in "panic guard" pattern. | ||
#[derive(Debug, new)] | ||
pub struct SqliteDatabaseCleaner(DatabaseName); | ||
|
||
impl Drop for SqliteDatabaseCleaner { | ||
fn drop(&mut self) { | ||
let sqlite3_path = SqliteDatabase::sqlite_db_path(&self.0); | ||
let sqlite3_files_pattern = format!("{}*", sqlite3_path.as_os_str().to_str().unwrap()); | ||
|
||
for entry in glob(&sqlite3_files_pattern).unwrap() { | ||
if let Ok(path) = entry { | ||
log::debug!( | ||
"SqliteDatabaseCleaner: found {}. removing...", | ||
path.as_os_str().to_str().unwrap() | ||
); | ||
|
||
std::fs::remove_file(&path) | ||
.or_else(|ioerr| match ioerr.kind() { | ||
std::io::ErrorKind::NotFound => Ok(()), | ||
_ => Err(ioerr), | ||
}) | ||
.unwrap(); | ||
|
||
log::debug!("SqliteDatabaseCleaner: done"); | ||
} | ||
} | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
...engine-interface/src/test_support/util.rs → ...ema-engine-infra/src/test_support/util.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
pub mod fixture; | ||
|
||
use apllodb_immutable_schema_engine_infra::test_support::clean_test_sqlite3; | ||
use apllodb_test_support::setup::setup_test_logger; | ||
|
||
/// general test setup sequence | ||
pub fn test_setup() { | ||
setup_test_logger(); | ||
clean_test_sqlite3().unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.