test setup

This commit is contained in:
Felix Ableitner 2024-05-22 12:30:22 +02:00
parent a39c19c9db
commit 7e949fcd43
4 changed files with 48 additions and 3 deletions

1
Cargo.lock generated
View File

@ -2913,6 +2913,7 @@ dependencies = [
"lemmy_apub",
"lemmy_db_schema",
"lemmy_db_views_actor",
"lemmy_utils",
"moka",
"once_cell",
"reqwest",

View File

@ -33,3 +33,6 @@ tokio = { workspace = true, features = ["full"] }
tracing.workspace = true
moka.workspace = true
tokio-util = "0.7.10"
[dev-dependencies]
lemmy_utils.workspace = true

View File

@ -201,3 +201,45 @@ async fn print_stats(pool: &mut DbPool<'_>, stats: &HashMap<String, FederationQu
}
tracing::info!("{ok_count} others up to date. {behind_count} instances behind.");
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
#[allow(clippy::indexing_slicing)]
mod test {
use super::*;
use lemmy_db_schema::utils::build_db_pool_for_tests;
use lemmy_utils::error::LemmyResult;
#[tokio::test]
async fn test_start_stop_federation_workers() -> LemmyResult<()> {
// initialization
let context = LemmyContext::init_test_context().await;
let pool = &mut context.pool();
let actual_pool = build_db_pool_for_tests().await;
let opts = Opts {
process_count: 1,
process_index: 1,
};
let federation_config = FederationConfig::builder()
.domain("local.com")
.app_data(context.clone())
.build()
.await?;
let instances = vec![
Instance::read_or_create(pool, "alpha.com".to_string()).await?,
Instance::read_or_create(pool, "beta.com".to_string()).await?,
Instance::read_or_create(pool, "gamma.com".to_string()).await?,
];
let task = start_stop_federation_workers_cancellable(opts, actual_pool, federation_config);
// cleanup
for i in instances {
Instance::delete(pool, i.id).await?;
}
task.cancel().await?;
Ok(())
}
}

View File

@ -20,11 +20,10 @@ then
cargo test -p $PACKAGE --all-features --no-fail-fast $TEST
else
cargo test --workspace --no-fail-fast
# Testing lemmy utils all features in particular (for ts-rs bindings)
cargo test -p lemmy_utils --all-features --no-fail-fast
fi
# Testing lemmy utils all features in particular (for ts-rs bindings)
cargo test -p lemmy_utils --all-features --no-fail-fast
# Add this to do printlns: -- --nocapture
pg_ctl stop --silent