diff --git a/Cargo.lock b/Cargo.lock index 39029c498..fd93b9c36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2913,6 +2913,7 @@ dependencies = [ "lemmy_apub", "lemmy_db_schema", "lemmy_db_views_actor", + "lemmy_utils", "moka", "once_cell", "reqwest", diff --git a/crates/federate/Cargo.toml b/crates/federate/Cargo.toml index 9ccd8adc3..d456854c4 100644 --- a/crates/federate/Cargo.toml +++ b/crates/federate/Cargo.toml @@ -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 \ No newline at end of file diff --git a/crates/federate/src/lib.rs b/crates/federate/src/lib.rs index fc5bd2387..d95551e34 100644 --- a/crates/federate/src/lib.rs +++ b/crates/federate/src/lib.rs @@ -201,3 +201,45 @@ async fn print_stats(pool: &mut DbPool<'_>, stats: &HashMap 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(()) + } +} diff --git a/scripts/test.sh b/scripts/test.sh index 3e0581fc7..9bb6acaa8 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -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