Use insta and criterion for main integration test and benches respectively.

docker/ci: Separate integration and unit tests and benches jobs.

Add directives to remove db before/after integration tests are performed.

Split start/run/stop phases; add more granular smoketests.

Split main integration tests into units for isolation.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-10-01 02:41:24 +00:00
parent 43f0882d83
commit 8d6bfde5a0
22 changed files with 373 additions and 100 deletions

View File

@@ -1,10 +1,15 @@
use std::{
collections::BTreeMap,
fs::remove_dir_all,
path::Path,
sync::{Arc, Mutex},
};
use rocksdb::{Cache, Env, LruCacheOptions};
use tuwunel_core::{Result, Server, debug, utils::math::usize_from_f64};
use tuwunel_core::{
Result, Server, debug,
utils::{math::usize_from_f64, result::LogErr},
};
use crate::{or_else, pool::Pool};
@@ -78,5 +83,55 @@ impl Drop for Context {
debug!("Joining background threads...");
env.join_all_threads();
after_close(self, &self.server.config.database_path)
.expect("Failed to execute after_close handler");
}
}
/// For unit and integration tests the 'fresh' directive deletes found db.
pub(super) fn before_open(ctx: &Arc<Context>, path: &Path) -> Result {
if ctx.server.config.test.contains("fresh") {
match delete_database_for_testing(ctx, path) {
| Err(e) if !e.is_not_found() => return Err(e),
| _ => (),
}
}
Ok(())
}
/// For unit and integration tests the 'cleanup' directive deletes after close
/// to cleanup.
fn after_close(ctx: &Context, path: &Path) -> Result {
if ctx.server.config.test.contains("cleanup") {
delete_database_for_testing(ctx, path)
.log_err()
.ok();
}
Ok(())
}
/// For unit and integration tests; removes the database directory when called.
/// To prevent misuse, cfg!(test) must be true for a unit test or the
/// integration test server is named localhost.
#[tracing::instrument(level = "debug", skip_all)]
fn delete_database_for_testing(ctx: &Context, path: &Path) -> Result {
let config = &ctx.server.config;
let localhost = config
.server_name
.as_str()
.starts_with("localhost");
if !cfg!(test) && !localhost {
return Ok(());
}
debug_assert!(
config.test.contains("cleanup") | config.test.contains("fresh"),
"missing any test directive legitimating this call.",
);
remove_dir_all(path).map_err(Into::into)
}

View File

@@ -10,6 +10,7 @@ use tuwunel_core::{Result, debug, implement, info, warn};
use super::{
Db, Engine,
cf_opts::cf_options,
context,
db_opts::db_options,
descriptor::{self, Descriptor},
repair::repair,
@@ -23,6 +24,7 @@ pub(crate) async fn open(ctx: Arc<Context>, desc: &[Descriptor]) -> Result<Arc<S
let config = &server.config;
let path = &config.database_path;
context::before_open(&ctx, path)?;
let db_opts = db_options(
config,
&ctx.env.lock().expect("environment locked"),