From 1443731a15dea70787434361eebeefd7ce82d4c8 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Fri, 4 Jul 2025 18:14:57 +0300 Subject: [PATCH 01/40] draft: using db-pool form a 2021 branch --- Cargo.lock | 33 +++++++++++++- Cargo.toml | 2 +- crates/api/api_utils/src/context.rs | 2 +- crates/db_schema/Cargo.toml | 2 + crates/db_schema/src/utils.rs | 54 +++++++++++++++++++++- crates/db_schema_file/src/schema_setup.rs | 55 ++++++++++++++++------- 6 files changed, 126 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f23109faab..62f42cbf7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,6 +599,18 @@ version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" +[[package]] +name = "bb8" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89aabfae550a5c44b43ab941844ffcd2e993cb6900b342debf59e9ea74acdb8" +dependencies = [ + "async-trait", + "futures-util", + "parking_lot", + "tokio", +] + [[package]] name = "bcrypt" version = "0.17.0" @@ -1376,6 +1388,22 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "db-pool" +version = "0.6.0" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021#39f31b40483257b6ce2adcc8fe632546cb6d45c8" +dependencies = [ + "async-trait", + "bb8", + "deadpool", + "diesel", + "diesel-async", + "futures", + "parking_lot", + "tokio", + "uuid", +] + [[package]] name = "deadpool" version = "0.12.2" @@ -1549,9 +1577,9 @@ dependencies = [ [[package]] name = "diesel" -version = "2.2.10" +version = "2.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff3e1edb1f37b4953dd5176916347289ed43d7119cc2e6c7c3f7849ff44ea506" +checksum = "a917a9209950404d5be011c81d081a2692a822f73c3d6af586f0cab5ff50f614" dependencies = [ "bitflags 2.9.1", "byteorder", @@ -3377,6 +3405,7 @@ dependencies = [ "activitypub_federation", "bcrypt", "chrono", + "db-pool", "deadpool", "derive-new", "diesel", diff --git a/Cargo.toml b/Cargo.toml index 24a011311f..e8ddedc827 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,7 +143,7 @@ lemmy_db_views_vote = { version = "=1.0.0-alpha.5", path = "./crates/db_views/vo activitypub_federation = { version = "0.7.0-beta.4", default-features = false, features = [ "actix-web", ] } -diesel = { version = "2.2.10", features = [ +diesel = { version = "2.2.11", features = [ "chrono", "postgres", "serde_json", diff --git a/crates/api/api_utils/src/context.rs b/crates/api/api_utils/src/context.rs index 99590770cf..4d090ba4ea 100644 --- a/crates/api/api_utils/src/context.rs +++ b/crates/api/api_utils/src/context.rs @@ -66,7 +66,7 @@ impl LemmyContext { #[allow(clippy::expect_used)] pub async fn init_test_federation_config() -> FederationConfig { // call this to run migrations - let pool = build_db_pool_for_tests(); + let pool = build_db_pool_for_tests().await; let client = client_builder(&SETTINGS).build().expect("build client"); diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 874b020216..4899c9f510 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -57,6 +57,7 @@ diesel-derive-newtype = { workspace = true, optional = true } diesel-async = { workspace = true, features = [ "deadpool", "postgres", + "async-connection-wrapper", ], optional = true } regex = { workspace = true, optional = true } diesel_ltree = { workspace = true, optional = true } @@ -73,6 +74,7 @@ i-love-jesus = { workspace = true, optional = true } derive-new.workspace = true tuplex = { workspace = true, optional = true } moka = { workspace = true, optional = true } +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021", features = ["diesel-async-postgres", "diesel-async-deadpool"] } [dev-dependencies] diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 4a24facfe3..c37c0de05c 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -3,6 +3,12 @@ pub mod uplete; use crate::newtypes::DbUrl; use chrono::TimeDelta; +use db_pool::{ + r#async::{ + DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool, + }, + PrivilegedPostgresConfig, +}; use deadpool::Runtime; use diesel::{ dsl, @@ -21,6 +27,7 @@ use diesel::{ IntoSql, }; use diesel_async::{ + async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, @@ -57,6 +64,7 @@ use std::{ sync::{Arc, LazyLock, OnceLock}, time::Duration, }; +use tokio::sync::OnceCell; use tracing::error; use url::Url; @@ -518,8 +526,50 @@ pub fn build_db_pool() -> LemmyResult { } #[allow(clippy::expect_used)] -pub fn build_db_pool_for_tests() -> ActualDbPool { - build_db_pool().expect("db pool missing") +pub async fn build_db_pool_for_tests() -> ActualDbPool { + static POOL: OnceCell>> = + OnceCell::const_new(); + let db_pool = POOL + .get_or_init(|| async { + let conn_string = SETTINGS.get_database_url(); + + let db_url = Url::parse(conn_string.as_str()).unwrap(); + + let config = PrivilegedPostgresConfig::new() + .host(db_url.host().unwrap().to_string()) + .port(db_url.port().unwrap()) + .username(db_url.username().to_string()) + .password(Some(db_url.password().unwrap().to_string())); + + let backend = DieselAsyncPostgresBackend::new( + config, + |manager| Pool::builder(manager).max_size(SETTINGS.database.pool_size), + |manager| Pool::builder(manager).max_size(2), + None, + move |conn| { + Box::pin(async { + let async_wrapper: AsyncConnectionWrapper = + AsyncConnectionWrapper::from(conn); + + schema_setup::run_with_connection( + schema_setup::Options::default().run(), + async_wrapper, + ) + .expect("run migrations"); + + None + }) + }, + ) + .await + .unwrap(); + + backend.create_database_pool().await.unwrap() + }) + .await; + + // TODO make compatible with ActualDbPool + db_pool.pull_immutable().await } #[allow(clippy::expect_used)] diff --git a/crates/db_schema_file/src/schema_setup.rs b/crates/db_schema_file/src/schema_setup.rs index ac90ec986b..b91dfe79c8 100644 --- a/crates/db_schema_file/src/schema_setup.rs +++ b/crates/db_schema_file/src/schema_setup.rs @@ -4,7 +4,6 @@ use crate::schema::previously_run_sql; use anyhow::{anyhow, Context}; use chrono::TimeDelta; use diesel::{ - connection::SimpleConnection, dsl::exists, migration::{Migration, MigrationVersion}, pg::Pg, @@ -20,6 +19,7 @@ use diesel::{ use diesel_migrations::MigrationHarness; use lemmy_utils::{error::LemmyResult, settings::SETTINGS}; use std::time::Instant; +use diesel::connection::LoadConnection; use tracing::debug; diesel::table! { @@ -48,14 +48,20 @@ fn replaceable_schema() -> String { const REPLACEABLE_SCHEMA_PATH: &str = "crates/db_schema/replaceable_schema"; -struct MigrationHarnessWrapper<'a> { - conn: &'a mut PgConnection, +struct MigrationHarnessWrapper<'a, Conn> +where + Conn: MigrationHarness, +{ + conn: &'a mut Conn, #[cfg(test)] enable_diff_check: bool, options: &'a Options, } -impl MigrationHarnessWrapper<'_> { +impl MigrationHarnessWrapper<'_, Conn> +where + Conn: MigrationHarness, +{ fn run_migration_inner( &mut self, migration: &dyn Migration, @@ -74,7 +80,10 @@ impl MigrationHarnessWrapper<'_> { } } -impl MigrationHarness for MigrationHarnessWrapper<'_> { +impl MigrationHarness for MigrationHarnessWrapper<'_, Conn> +where + Conn: MigrationHarness, +{ fn run_migration( &mut self, migration: &dyn Migration, @@ -178,12 +187,10 @@ pub enum Branch { ReplaceableSchemaNotRebuilt, } -pub fn run(options: Options) -> LemmyResult { - let db_url = SETTINGS.get_database_url(); - - // Migrations don't support async connection, and this function doesn't need to be async - let mut conn = PgConnection::establish(&db_url)?; - +pub fn run_with_connection(options: Options, mut conn: Conn) -> LemmyResult +where + Conn: Connection + MigrationHarness + LoadConnection, +{ // If possible, skip getting a lock and recreating the "r" schema, so // lemmy_server processes in a horizontally scaled setup can start without causing locks if !options.revert @@ -250,7 +257,17 @@ pub fn run(options: Options) -> LemmyResult { Ok(output) } -fn run_replaceable_schema(conn: &mut PgConnection) -> LemmyResult<()> { +pub fn run(options: Options) -> LemmyResult { + let db_url = SETTINGS.get_database_url(); + + // Migrations don't support async connection, and this function doesn't need to be async + run_with_connection(options, PgConnection::establish(&db_url)?) +} + +fn run_replaceable_schema(conn: &mut Conn) -> LemmyResult<()> +where + Conn: Connection, +{ conn.transaction(|conn| { conn .batch_execute(&replaceable_schema()) @@ -266,7 +283,10 @@ fn run_replaceable_schema(conn: &mut PgConnection) -> LemmyResult<()> { }) } -fn revert_replaceable_schema(conn: &mut PgConnection) -> LemmyResult<()> { +fn revert_replaceable_schema(conn: &mut Conn) -> LemmyResult<()> +where + Conn: Connection, +{ conn .batch_execute("DROP SCHEMA IF EXISTS r CASCADE;") .with_context(|| format!("Failed to revert SQL files in {REPLACEABLE_SCHEMA_PATH}"))?; @@ -277,10 +297,13 @@ fn revert_replaceable_schema(conn: &mut PgConnection) -> LemmyResult<()> { Ok(()) } -fn run_selected_migrations( - conn: &mut PgConnection, +fn run_selected_migrations( + conn: &mut Conn, options: &Options, -) -> diesel::migration::Result<()> { +) -> diesel::migration::Result<()> +where + Conn: MigrationHarness, +{ let mut wrapper = MigrationHarnessWrapper { conn, options, From 91613fb203501aa0642c3b2811c5471f9fc283f5 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Fri, 11 Jul 2025 14:32:21 +0300 Subject: [PATCH 02/40] fix --- crates/db_schema_setup/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index e90f62ff70..0c9f04bc5e 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -18,6 +18,7 @@ use diesel_migrations::MigrationHarness; use std::time::Instant; use diesel::connection::LoadConnection; use tracing::debug; +use lemmy_utils::settings::SETTINGS; diesel::table! { pg_namespace (nspname) { @@ -261,7 +262,7 @@ where Ok(output) } -pub fn run(options: Options) -> LemmyResult { +pub fn run(options: Options) -> anyhow::Result { let db_url = SETTINGS.get_database_url(); // Migrations don't support async connection, and this function doesn't need to be async From 618f635b9ad026cd8fbb752542685bbf0929fa0b Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Fri, 11 Jul 2025 14:47:41 +0300 Subject: [PATCH 03/40] some renaming --- crates/db_schema/src/utils.rs | 5 +++-- crates/db_schema_setup/src/lib.rs | 5 +---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 5711a63b5f..8b06dd2b2c 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -63,6 +63,7 @@ use std::{ sync::{Arc, LazyLock, OnceLock}, time::Duration, }; +use db_pool::async::ReusableConnectionPool; use tokio::sync::OnceCell; use tracing::error; use url::Url; @@ -550,8 +551,8 @@ pub async fn build_db_pool_for_tests() -> ActualDbPool { let async_wrapper: AsyncConnectionWrapper = AsyncConnectionWrapper::from(conn); - schema_setup::run_with_connection( - schema_setup::Options::default().run(), + lemmy_db_schema_setup::run_with_connection( + lemmy_db_schema_setup::Options::default().run(), async_wrapper, ) .expect("run migrations"); diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index 0c9f04bc5e..362f4cb6cd 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -18,7 +18,6 @@ use diesel_migrations::MigrationHarness; use std::time::Instant; use diesel::connection::LoadConnection; use tracing::debug; -use lemmy_utils::settings::SETTINGS; diesel::table! { pg_namespace (nspname) { @@ -262,9 +261,7 @@ where Ok(output) } -pub fn run(options: Options) -> anyhow::Result { - let db_url = SETTINGS.get_database_url(); - +pub fn run(options: Options, db_url: &str) -> anyhow::Result { // Migrations don't support async connection, and this function doesn't need to be async run_with_connection(options, PgConnection::establish(&db_url)?) } From ef155c5a7489487cd5a80f075b95d3996a9d3ea7 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 15 Jul 2025 00:28:48 +0300 Subject: [PATCH 04/40] reusable pool integrated except everywhere, some tests adapted --- Cargo.lock | 2 +- crates/api/api_utils/src/context.rs | 20 +++++++--- crates/db_schema/Cargo.toml | 2 +- crates/db_schema/src/impls/activity.rs | 6 +-- crates/db_schema/src/impls/actor_language.rs | 18 +++------ crates/db_schema/src/impls/captcha_answer.rs | 6 +-- crates/db_schema/src/impls/comment.rs | 6 +-- crates/db_schema/src/impls/community.rs | 6 +-- .../src/impls/federation_allowlist.rs | 3 +- crates/db_schema/src/impls/language.rs | 3 +- crates/db_schema/src/impls/local_site.rs | 6 +-- crates/db_schema/src/impls/local_user.rs | 6 +-- .../db_schema/src/impls/mod_log/moderator.rs | 3 +- crates/db_schema/src/impls/multi_community.rs | 3 +- .../src/impls/password_reset_request.rs | 3 +- crates/db_schema/src/impls/person.rs | 9 ++--- crates/db_schema/src/impls/post.rs | 9 ++--- crates/db_schema/src/impls/post_report.rs | 6 +-- crates/db_schema/src/impls/private_message.rs | 3 +- crates/db_schema/src/utils.rs | 39 ++++++++++--------- crates/db_schema/src/utils/uplete.rs | 6 +-- crates/db_views/comment/src/impls.rs | 36 ++++++----------- crates/db_views/community/src/impls.rs | 15 +++---- .../db_views/community_follower/src/impls.rs | 3 +- crates/db_views/inbox_combined/src/impls.rs | 15 +++---- crates/db_views/local_user/src/impls.rs | 3 +- crates/db_views/modlog_combined/src/impls.rs | 9 ++--- crates/db_views/person/src/impls.rs | 9 ++--- .../person_content_combined/src/impls.rs | 3 +- .../person_liked_combined/src/impls.rs | 3 +- .../person_saved_combined/src/impls.rs | 3 +- .../registration_applications/src/impls.rs | 3 +- crates/db_views/report_combined/src/impls.rs | 21 ++++------ crates/db_views/search_combined/src/impls.rs | 24 ++++-------- crates/db_views/vote/src/impls.rs | 3 +- 35 files changed, 121 insertions(+), 194 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7753f13bf8..a826f14ac2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,7 +1391,7 @@ dependencies = [ [[package]] name = "db-pool" version = "0.6.0" -source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021#39f31b40483257b6ce2adcc8fe632546cb6d45c8" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-test#aba15f15f194ce4d0b7a313cf8f077b8b3bec81c" dependencies = [ "async-trait", "bb8", diff --git a/crates/api/api_utils/src/context.rs b/crates/api/api_utils/src/context.rs index 4d090ba4ea..553d91dd16 100644 --- a/crates/api/api_utils/src/context.rs +++ b/crates/api/api_utils/src/context.rs @@ -10,10 +10,17 @@ use lemmy_utils::{ }; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use std::sync::Arc; +use lemmy_db_schema::utils::ReusableDbPool; + +#[derive(Clone)] +pub enum ContextPool { + Actual(ActualDbPool), + Reusable(ReusableDbPool), // TODO it's not cloneable +} #[derive(Clone)] pub struct LemmyContext { - pool: ActualDbPool, + pool: ContextPool, client: Arc, /// Pictrs requests must bypass proxy. Unfortunately no_proxy can only be set on ClientBuilder /// and not on RequestBuilder, so we need a separate client here. @@ -24,7 +31,7 @@ pub struct LemmyContext { impl LemmyContext { pub fn create( - pool: ActualDbPool, + pool: ContextPool, client: ClientWithMiddleware, pictrs_client: ClientWithMiddleware, secret: Secret, @@ -39,9 +46,12 @@ impl LemmyContext { } } pub fn pool(&self) -> DbPool<'_> { - DbPool::Pool(&self.pool) + match &self.pool { + ContextPool::Actual(pool) => DbPool::Pool(pool), + ContextPool::Reusable(pool) => DbPool::ReusablePool(pool), + } } - pub fn inner_pool(&self) -> &ActualDbPool { + pub fn inner_pool(&self) -> &ContextPool { &self.pool } pub fn client(&self) -> &ClientWithMiddleware { @@ -79,7 +89,7 @@ impl LemmyContext { let rate_limit_cell = RateLimit::with_test_config(); let context = LemmyContext::create( - pool, + ContextPool::Reusable(pool), client.clone(), client, secret, diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index be8643f173..7f005e16a3 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -76,7 +76,7 @@ i-love-jesus = { workspace = true, optional = true } derive-new.workspace = true tuplex = { workspace = true, optional = true } moka = { workspace = true, optional = true } -db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021", features = ["diesel-async-postgres", "diesel-async-deadpool"] } +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test", features = ["diesel-async-postgres", "diesel-async-deadpool"] } [dev-dependencies] diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index 2382a34b66..a28bda6aca 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -71,9 +71,8 @@ mod tests { use url::Url; #[tokio::test] - #[serial] async fn receive_activity_duplicate() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let ap_id: DbUrl = Url::parse("http://example.com/activity/531")?.into(); @@ -86,9 +85,8 @@ mod tests { } #[tokio::test] - #[serial] async fn sent_activity_write_read() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let ap_id: DbUrl = Url::parse("http://example.com/activity/412")?.into(); let data = json!({ diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 589863b83b..1c8bec391a 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -427,9 +427,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_convert_update_languages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // call with empty vec, returns all languages @@ -445,10 +444,9 @@ mod tests { Ok(()) } #[tokio::test] - #[serial] async fn test_convert_read_languages() -> LemmyResult<()> { use lemmy_db_schema_file::schema::language::dsl::{id, language}; - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // call with all languages, returns empty vec @@ -466,9 +464,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_site_languages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = TestData::create(pool).await?; @@ -489,9 +486,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_user_languages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = TestData::create(pool).await?; @@ -521,9 +517,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_community_languages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = TestData::create(pool).await?; let test_langs = test_langs1(pool).await?; @@ -576,9 +571,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_validate_post_language() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = TestData::create(pool).await?; let test_langs = test_langs1(pool).await?; diff --git a/crates/db_schema/src/impls/captcha_answer.rs b/crates/db_schema/src/impls/captcha_answer.rs index f9a8999456..269c69404f 100644 --- a/crates/db_schema/src/impls/captcha_answer.rs +++ b/crates/db_schema/src/impls/captcha_answer.rs @@ -54,9 +54,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_captcha_happy_path() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted = CaptchaAnswer::insert( @@ -81,9 +80,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_captcha_repeat_answer_fails() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted = CaptchaAnswer::insert( diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 32295757c6..bf6b896308 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -394,9 +394,8 @@ mod tests { use url::Url; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -507,9 +506,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_aggregates() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 1dd314aae4..15c1f250d6 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -703,9 +703,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -864,9 +863,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_aggregates() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index 226cffa6b9..ebdae2d813 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -35,9 +35,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_allowlist_insert_and_clear() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let instances = vec![ Instance::read_or_create(pool, "tld1.xyz".to_string()).await?, diff --git a/crates/db_schema/src/impls/language.rs b/crates/db_schema/src/impls/language.rs index 9d60401371..8778a31fa0 100644 --- a/crates/db_schema/src/impls/language.rs +++ b/crates/db_schema/src/impls/language.rs @@ -52,9 +52,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_languages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let all = Language::read_all(pool).await?; diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index 34c024e380..df0dc0126c 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -85,9 +85,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_aggregates() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let (data, inserted_person, inserted_community) = prepare_site_with_community(pool).await?; @@ -155,9 +154,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_soft_delete() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let (data, inserted_person, inserted_community) = prepare_site_with_community(pool).await?; diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index ec45f2c7f8..440cf4adcb 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -400,9 +400,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_admin_higher_check() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -439,9 +438,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_email_taken() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let darwin_email = "charles.darwin@gmail.com"; diff --git a/crates/db_schema/src/impls/mod_log/moderator.rs b/crates/db_schema/src/impls/mod_log/moderator.rs index ef34e51818..b7196f78fc 100644 --- a/crates/db_schema/src/impls/mod_log/moderator.rs +++ b/crates/db_schema/src/impls/mod_log/moderator.rs @@ -411,9 +411,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/impls/multi_community.rs b/crates/db_schema/src/impls/multi_community.rs index b2fca2b5bc..0d83daee9c 100644 --- a/crates/db_schema/src/impls/multi_community.rs +++ b/crates/db_schema/src/impls/multi_community.rs @@ -361,9 +361,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_multi_community_apub() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = setup(pool).await?; diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 7a06e26c1d..b01bc8b258 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -61,9 +61,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_password_reset() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Setup diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 3ffc75ad99..6d046aeaeb 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -469,9 +469,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -525,9 +524,8 @@ mod tests { } #[tokio::test] - #[serial] async fn follow() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -553,9 +551,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_aggregates() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index d67ba0f5d4..528fccbb7b 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -597,9 +597,8 @@ mod tests { use url::Url; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -736,9 +735,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_aggregates() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; @@ -840,9 +838,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_aggregates_soft_delete() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index 9a6f435432..5429d81fa9 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -149,9 +149,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_resolve_post_report() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let (person, report) = init(pool).await?; @@ -169,9 +168,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_resolve_all_post_reports() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let (person, report) = init(pool).await?; diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index 3a970ce389..e21bea8d36 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -132,9 +132,8 @@ mod tests { use url::Url; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 8b06dd2b2c..6e671ec971 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -3,10 +3,9 @@ pub mod uplete; use crate::newtypes::DbUrl; use chrono::TimeDelta; +use db_pool::r#async::ReusableConnectionPool; use db_pool::{ - r#async::{ - DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool, - }, + r#async::{DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool}, PrivilegedPostgresConfig, }; use deadpool::Runtime; @@ -18,21 +17,18 @@ use diesel::{ query_builder::{Query, QueryFragment}, query_dsl::methods::LimitDsl, result::{ - ConnectionError, - ConnectionResult, + ConnectionError, ConnectionResult, Error::{self as DieselError, QueryBuilderError}, }, sql_types::{self, Timestamptz}, - Expression, - IntoSql, + Expression, IntoSql, }; use diesel_async::{ async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, - ManagerConfig, + AsyncDieselConnectionManager, ManagerConfig, }, scoped_futures::ScopedBoxFuture, AsyncConnection, @@ -47,23 +43,17 @@ use lemmy_utils::{ use regex::Regex; use rustls::{ client::danger::{ - DangerousClientConfigBuilder, - HandshakeSignatureValid, - ServerCertVerified, - ServerCertVerifier, + DangerousClientConfigBuilder, HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier, }, crypto::{self, verify_tls12_signature, verify_tls13_signature}, pki_types::{CertificateDer, ServerName, UnixTime}, - ClientConfig, - DigitallySignedStruct, - SignatureScheme, + ClientConfig, DigitallySignedStruct, SignatureScheme, }; use std::{ ops::{Deref, DerefMut}, sync::{Arc, LazyLock, OnceLock}, time::Duration, }; -use db_pool::async::ReusableConnectionPool; use tokio::sync::OnceCell; use tracing::error; use url::Url; @@ -77,6 +67,7 @@ pub const RANK_DEFAULT: f64 = 0.0001; /// Some connection options to speed up queries const CONNECTION_OPTIONS: [&str; 1] = ["geqo_threshold=12"]; pub type ActualDbPool = Pool; +pub type ReusableDbPool = ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; /// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit /// reborrowing. @@ -84,6 +75,7 @@ pub type ActualDbPool = Pool; /// https://github.com/rust-lang/rfcs/issues/1403 pub enum DbPool<'a> { Pool(&'a ActualDbPool), + ReusablePool(&'a ReusableDbPool), Conn(&'a mut AsyncPgConnection), } @@ -96,6 +88,9 @@ pub async fn get_conn<'a, 'b: 'a>(pool: &'a mut DbPool<'b>) -> Result Ok(match pool { DbPool::Pool(pool) => DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?), DbPool::Conn(conn) => DbConn::Conn(conn), + DbPool::ReusablePool(pool) => { + DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?) + } }) } @@ -154,6 +149,12 @@ impl<'a> From<&'a ActualDbPool> for DbPool<'a> { } } +impl<'a> From<&'a ReusableDbPool> for DbPool<'a> { + fn from(value: &'a ReusableDbPool) -> Self { + DbPool::ReusablePool(value) + } +} + /// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only /// works when the `futures` crate is listed in `Cargo.toml`. /// @@ -526,7 +527,8 @@ pub fn build_db_pool() -> LemmyResult { } #[allow(clippy::expect_used)] -pub async fn build_db_pool_for_tests() -> ActualDbPool { +pub async fn build_db_pool_for_tests( +) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend> { static POOL: OnceCell>> = OnceCell::const_new(); let db_pool = POOL @@ -568,7 +570,6 @@ pub async fn build_db_pool_for_tests() -> ActualDbPool { }) .await; - // TODO make compatible with ActualDbPool db_pool.pull_immutable().await } diff --git a/crates/db_schema/src/utils/uplete.rs b/crates/db_schema/src/utils/uplete.rs index dddbfe8ea6..25204cff67 100644 --- a/crates/db_schema/src/utils/uplete.rs +++ b/crates/db_schema/src/utils/uplete.rs @@ -292,9 +292,8 @@ mod tests { // Main purpose of this test is to check accuracy of the returned `Count`, which other modules' // tests rely on #[tokio::test] - #[serial] async fn test_count() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let mut conn = get_conn(pool).await?; @@ -401,9 +400,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_all_null() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let mut conn = get_conn(pool).await?; diff --git a/crates/db_views/comment/src/impls.rs b/crates/db_views/comment/src/impls.rs index f28fdc1699..16625704ad 100644 --- a/crates/db_views/comment/src/impls.rs +++ b/crates/db_views/comment/src/impls.rs @@ -478,9 +478,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -530,9 +529,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_comment_tree() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -607,9 +605,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_languages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -666,9 +663,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_distinguished_first() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -691,9 +687,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_creator_is_moderator() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -720,9 +715,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_creator_is_admin() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -765,9 +759,8 @@ mod tests { } #[tokio::test] - #[serial] async fn local_only_instance() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -813,9 +806,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment_listing_local_user_banned_from_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -854,9 +846,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment_listing_local_user_not_banned_from_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -874,9 +865,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment_listings_hide_nsfw() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -903,9 +893,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment_listing_private_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let mut data = init_data(pool).await?; @@ -996,9 +985,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment_removed() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let mut data = init_data(pool).await?; diff --git a/crates/db_views/community/src/impls.rs b/crates/db_views/community/src/impls.rs index e4b45d27ab..f79f45fb91 100644 --- a/crates/db_views/community/src/impls.rs +++ b/crates/db_views/community/src/impls.rs @@ -360,9 +360,8 @@ mod tests { } #[tokio::test] - #[serial] async fn follow_state() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; let community = &data.communities[0]; @@ -426,9 +425,8 @@ mod tests { } #[tokio::test] - #[serial] async fn local_only_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -471,9 +469,8 @@ mod tests { } #[tokio::test] - #[serial] async fn community_sort_name() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -501,9 +498,8 @@ mod tests { } #[tokio::test] - #[serial] async fn can_mod() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -548,9 +544,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_multi_community_list() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/community_follower/src/impls.rs b/crates/db_views/community_follower/src/impls.rs index 840f1729a5..b8c5d6951b 100644 --- a/crates/db_views/community_follower/src/impls.rs +++ b/crates/db_views/community_follower/src/impls.rs @@ -313,9 +313,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_has_followers_from_instance() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // insert local community diff --git a/crates/db_views/inbox_combined/src/impls.rs b/crates/db_views/inbox_combined/src/impls.rs index c82f2a8472..d9adc1c4eb 100644 --- a/crates/db_views/inbox_combined/src/impls.rs +++ b/crates/db_views/inbox_combined/src/impls.rs @@ -555,9 +555,8 @@ mod tests { } #[tokio::test] - #[serial] async fn replies() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -612,9 +611,8 @@ mod tests { } #[tokio::test] - #[serial] async fn mentions() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -765,9 +763,8 @@ mod tests { } #[tokio::test] - #[serial] async fn read_private_messages() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; setup_private_messages(&data, pool).await?; @@ -814,9 +811,8 @@ mod tests { } #[tokio::test] - #[serial] async fn ensure_private_message_person_block() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; setup_private_messages(&data, pool).await?; @@ -857,9 +853,8 @@ mod tests { } #[tokio::test] - #[serial] async fn ensure_private_message_instance_block() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; setup_private_messages(&data, pool).await?; diff --git a/crates/db_views/local_user/src/impls.rs b/crates/db_views/local_user/src/impls.rs index b5b9223031..ba6be26103 100644 --- a/crates/db_views/local_user/src/impls.rs +++ b/crates/db_views/local_user/src/impls.rs @@ -273,9 +273,8 @@ mod tests { } #[tokio::test] - #[serial] async fn list_banned() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/modlog_combined/src/impls.rs b/crates/db_views/modlog_combined/src/impls.rs index 4f8c5289c4..2e292e1d94 100644 --- a/crates/db_views/modlog_combined/src/impls.rs +++ b/crates/db_views/modlog_combined/src/impls.rs @@ -759,9 +759,8 @@ mod tests { } #[tokio::test] - #[serial] async fn admin_types() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -982,9 +981,8 @@ mod tests { } #[tokio::test] - #[serial] async fn mod_types() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1384,9 +1382,8 @@ mod tests { } #[tokio::test] - #[serial] async fn hide_modlog_names() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/person/src/impls.rs b/crates/db_views/person/src/impls.rs index b0edcc1e13..706f6fe4a9 100644 --- a/crates/db_views/person/src/impls.rs +++ b/crates/db_views/person/src/impls.rs @@ -186,9 +186,8 @@ mod tests { } #[tokio::test] - #[serial] async fn exclude_deleted() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -213,9 +212,8 @@ mod tests { } #[tokio::test] - #[serial] async fn list_admins() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -252,9 +250,8 @@ mod tests { } #[tokio::test] - #[serial] async fn note() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/person_content_combined/src/impls.rs b/crates/db_views/person_content_combined/src/impls.rs index e8b00f0ef9..97f968b687 100644 --- a/crates/db_views/person_content_combined/src/impls.rs +++ b/crates/db_views/person_content_combined/src/impls.rs @@ -363,9 +363,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_combined() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/person_liked_combined/src/impls.rs b/crates/db_views/person_liked_combined/src/impls.rs index 23640bb78b..6acf77524d 100644 --- a/crates/db_views/person_liked_combined/src/impls.rs +++ b/crates/db_views/person_liked_combined/src/impls.rs @@ -357,9 +357,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_combined() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/person_saved_combined/src/impls.rs b/crates/db_views/person_saved_combined/src/impls.rs index 0cdfc08d0a..d8e468ca75 100644 --- a/crates/db_views/person_saved_combined/src/impls.rs +++ b/crates/db_views/person_saved_combined/src/impls.rs @@ -346,9 +346,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_combined() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/registration_applications/src/impls.rs b/crates/db_views/registration_applications/src/impls.rs index 56bdf1cc6d..3d40323937 100644 --- a/crates/db_views/registration_applications/src/impls.rs +++ b/crates/db_views/registration_applications/src/impls.rs @@ -158,9 +158,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_views/report_combined/src/impls.rs b/crates/db_views/report_combined/src/impls.rs index d1bfad762d..756c7b4931 100644 --- a/crates/db_views/report_combined/src/impls.rs +++ b/crates/db_views/report_combined/src/impls.rs @@ -591,9 +591,8 @@ mod tests { } #[tokio::test] - #[serial] async fn combined() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -762,9 +761,8 @@ mod tests { } #[tokio::test] - #[serial] async fn private_message_reports() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -826,9 +824,8 @@ mod tests { } #[tokio::test] - #[serial] async fn post_reports() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -958,9 +955,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment_reports() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1074,9 +1070,8 @@ mod tests { } #[tokio::test] - #[serial] async fn community_reports() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1141,9 +1136,8 @@ mod tests { } #[tokio::test] - #[serial] async fn violates_instance_rules() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1231,9 +1225,8 @@ mod tests { } #[tokio::test] - #[serial] async fn my_reports_only() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/search_combined/src/impls.rs b/crates/db_views/search_combined/src/impls.rs index e8838916f3..a89a1695e2 100644 --- a/crates/db_views/search_combined/src/impls.rs +++ b/crates/db_views/search_combined/src/impls.rs @@ -653,9 +653,8 @@ mod tests { } #[tokio::test] - #[serial] async fn combined() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -830,9 +829,8 @@ mod tests { } #[tokio::test] - #[serial] async fn community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -904,9 +902,8 @@ mod tests { } #[tokio::test] - #[serial] async fn person() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -986,9 +983,8 @@ mod tests { } #[tokio::test] - #[serial] async fn post() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1117,9 +1113,8 @@ mod tests { } #[tokio::test] - #[serial] async fn nsfw_post() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1146,9 +1141,8 @@ mod tests { } #[tokio::test] - #[serial] async fn nsfw_comment() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1176,9 +1170,8 @@ mod tests { } #[tokio::test] - #[serial] async fn comment() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -1283,9 +1276,8 @@ mod tests { } #[tokio::test] - #[serial] async fn multi_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/vote/src/impls.rs b/crates/db_views/vote/src/impls.rs index 389bbee519..3d0bfaecbc 100644 --- a/crates/db_views/vote/src/impls.rs +++ b/crates/db_views/vote/src/impls.rs @@ -220,9 +220,8 @@ mod tests { use serial_test::serial; #[tokio::test] - #[serial] async fn post_and_comment_vote_views() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; From 6b13d21ccef125c4bafc27144413a8e7639c0682 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 16 Jul 2025 02:57:53 +0300 Subject: [PATCH 05/40] generic pool in context and stat modules, now it compiles --- crates/api/api_utils/src/context.rs | 21 +++------ crates/apub/src/lib.rs | 4 +- crates/db_schema/src/utils.rs | 66 ++++++++++++++++++++++++----- crates/db_schema_setup/src/lib.rs | 2 +- crates/federate/src/inboxes.rs | 12 +++--- crates/federate/src/stats.rs | 6 +-- crates/federate/src/worker.rs | 11 +++-- src/lib.rs | 7 ++- 8 files changed, 85 insertions(+), 44 deletions(-) diff --git a/crates/api/api_utils/src/context.rs b/crates/api/api_utils/src/context.rs index 553d91dd16..382b09b3a5 100644 --- a/crates/api/api_utils/src/context.rs +++ b/crates/api/api_utils/src/context.rs @@ -2,7 +2,7 @@ use crate::request::client_builder; use activitypub_federation::config::{Data, FederationConfig}; use lemmy_db_schema::{ source::secret::Secret, - utils::{build_db_pool_for_tests, ActualDbPool, DbPool}, + utils::{build_db_pool_for_tests, DbPool, GenericDbPool}, }; use lemmy_utils::{ rate_limit::RateLimit, @@ -10,17 +10,10 @@ use lemmy_utils::{ }; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use std::sync::Arc; -use lemmy_db_schema::utils::ReusableDbPool; - -#[derive(Clone)] -pub enum ContextPool { - Actual(ActualDbPool), - Reusable(ReusableDbPool), // TODO it's not cloneable -} #[derive(Clone)] pub struct LemmyContext { - pool: ContextPool, + pool: GenericDbPool, client: Arc, /// Pictrs requests must bypass proxy. Unfortunately no_proxy can only be set on ClientBuilder /// and not on RequestBuilder, so we need a separate client here. @@ -31,7 +24,7 @@ pub struct LemmyContext { impl LemmyContext { pub fn create( - pool: ContextPool, + pool: GenericDbPool, client: ClientWithMiddleware, pictrs_client: ClientWithMiddleware, secret: Secret, @@ -47,11 +40,11 @@ impl LemmyContext { } pub fn pool(&self) -> DbPool<'_> { match &self.pool { - ContextPool::Actual(pool) => DbPool::Pool(pool), - ContextPool::Reusable(pool) => DbPool::ReusablePool(pool), + GenericDbPool::Actual(pool) => DbPool::Pool(pool), + GenericDbPool::Reusable(pool) => DbPool::ReusablePool(pool), } } - pub fn inner_pool(&self) -> &ContextPool { + pub fn inner_pool(&self) -> &GenericDbPool { &self.pool } pub fn client(&self) -> &ClientWithMiddleware { @@ -89,7 +82,7 @@ impl LemmyContext { let rate_limit_cell = RateLimit::with_test_config(); let context = LemmyContext::create( - ContextPool::Reusable(pool), + GenericDbPool::Reusable(Arc::new(pool)), client.clone(), client, secret, diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 1fb7e4a462..c054873559 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -1,7 +1,7 @@ use activitypub_federation::{config::UrlVerifier, error::Error as ActivityPubError}; use async_trait::async_trait; use lemmy_apub_objects::utils::functions::{check_apub_id_valid, local_site_data_cached}; -use lemmy_db_schema::utils::ActualDbPool; +use lemmy_db_schema::utils::GenericDbPool; use lemmy_utils::error::{FederationError, LemmyError, LemmyErrorType}; use url::Url; @@ -18,7 +18,7 @@ pub mod protocol; pub const FEDERATION_HTTP_FETCH_LIMIT: u32 = 100; #[derive(Clone)] -pub struct VerifyUrlData(pub ActualDbPool); +pub struct VerifyUrlData(pub GenericDbPool); #[async_trait] impl UrlVerifier for VerifyUrlData { diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 93a1e3cadc..ef9f8547a0 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -2,12 +2,17 @@ pub mod queries; use crate::newtypes::DbUrl; use chrono::TimeDelta; -use db_pool::r#async::ReusableConnectionPool; use db_pool::{ - r#async::{DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool}, + r#async::{ + DatabasePool, + DatabasePoolBuilderTrait, + DieselAsyncPostgresBackend, + DieselDeadpool, + ReusableConnectionPool, + }, PrivilegedPostgresConfig, }; -use deadpool::Runtime; +use deadpool::{Runtime, Status}; use diesel::{ dsl, expression::AsExpression, @@ -16,18 +21,21 @@ use diesel::{ query_builder::{Query, QueryFragment}, query_dsl::methods::LimitDsl, result::{ - ConnectionError, ConnectionResult, + ConnectionError, + ConnectionResult, Error::{self as DieselError, QueryBuilderError}, }, sql_types::{self, Timestamptz}, - Expression, IntoSql, + Expression, + IntoSql, }; use diesel_async::{ async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, ManagerConfig, + AsyncDieselConnectionManager, + ManagerConfig, }, scoped_futures::ScopedBoxFuture, AsyncConnection, @@ -42,11 +50,16 @@ use lemmy_utils::{ use regex::Regex; use rustls::{ client::danger::{ - DangerousClientConfigBuilder, HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier, + DangerousClientConfigBuilder, + HandshakeSignatureValid, + ServerCertVerified, + ServerCertVerifier, }, crypto::{self, verify_tls12_signature, verify_tls13_signature}, pki_types::{CertificateDer, ServerName, UnixTime}, - ClientConfig, DigitallySignedStruct, SignatureScheme, + ClientConfig, + DigitallySignedStruct, + SignatureScheme, }; use std::{ ops::{Deref, DerefMut}, @@ -66,7 +79,8 @@ pub const RANK_DEFAULT: f64 = 0.0001; /// Some connection options to speed up queries const CONNECTION_OPTIONS: [&str; 1] = ["geqo_threshold=12"]; pub type ActualDbPool = Pool; -pub type ReusableDbPool = ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; +pub type ReusableDbPool = + ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; /// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit /// reborrowing. @@ -83,6 +97,21 @@ pub enum DbConn<'a> { Conn(&'a mut AsyncPgConnection), } +#[derive(Clone)] +pub enum GenericDbPool { + Actual(ActualDbPool), + Reusable(Arc), +} + +impl GenericDbPool { + pub fn status(&self) -> Status { + match self { + GenericDbPool::Actual(pool) => pool.status(), + GenericDbPool::Reusable(pool) => pool.status(), + } + } +} + pub async fn get_conn<'a, 'b: 'a>(pool: &'a mut DbPool<'b>) -> Result, DieselError> { Ok(match pool { DbPool::Pool(pool) => DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?), @@ -154,6 +183,15 @@ impl<'a> From<&'a ReusableDbPool> for DbPool<'a> { } } +impl<'a> From<&'a GenericDbPool> for DbPool<'a> { + fn from(value: &'a GenericDbPool) -> Self { + match value { + GenericDbPool::Actual(pool) => DbPool::Pool(pool), + GenericDbPool::Reusable(pool) => DbPool::ReusablePool(pool), + } + } +} + /// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only /// works when the `futures` crate is listed in `Cargo.toml`. /// @@ -162,7 +200,8 @@ impl<'a> From<&'a ReusableDbPool> for DbPool<'a> { /// A `Result` is returned (not in a `Future`, so don't use `.await`). The `Ok` variant contains a /// tuple with the values returned by the given functions. /// -/// The functions run concurrently if `$pool` has the `DbPool::Pool` variant. +/// The functions run concurrently if `$pool` has the `DbPool::Pool` or `DbPool::ReusablePool` +/// variant. #[macro_export] macro_rules! try_join_with_pool { ($pool:ident => ($($func:expr),+)) => {{ @@ -188,6 +227,13 @@ macro_rules! try_join_with_pool { } }),+)) }.await, + // Run concurrently with `try_join` + $crate::utils::DbPool::ReusablePool(__pool) => ::futures_util::try_join!( + $(async { + let mut __dbpool = $crate::utils::DbPool::ReusablePool(__pool); + ($func)(&mut __dbpool).await + }),+ + ), } }}; } diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index 362f4cb6cd..ffc0101749 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -2,6 +2,7 @@ mod diff_check; use anyhow::{anyhow, Context}; use chrono::TimeDelta; use diesel::{ + connection::LoadConnection, dsl::exists, migration::{Migration, MigrationVersion}, pg::Pg, @@ -16,7 +17,6 @@ use diesel::{ }; use diesel_migrations::MigrationHarness; use std::time::Instant; -use diesel::connection::LoadConnection; use tracing::debug; diesel::table! { diff --git a/crates/federate/src/inboxes.rs b/crates/federate/src/inboxes.rs index 9e00f161af..46c12c021d 100644 --- a/crates/federate/src/inboxes.rs +++ b/crates/federate/src/inboxes.rs @@ -3,7 +3,7 @@ use chrono::{DateTime, TimeZone, Utc}; use lemmy_db_schema::{ newtypes::{CommunityId, DbUrl, InstanceId}, source::{activity::SentActivity, site::Site}, - utils::{ActualDbPool, DbPool}, + utils::{DbPool, GenericDbPool}, }; use lemmy_db_views_community_follower::CommunityFollowerView; use lemmy_utils::error::LemmyResult; @@ -46,18 +46,18 @@ pub trait DataSource: Send + Sync { ) -> LemmyResult>; } pub struct DbDataSource { - pool: ActualDbPool, + pool: GenericDbPool, } impl DbDataSource { - pub fn new(pool: ActualDbPool) -> Self { + pub fn new(pool: GenericDbPool) -> Self { Self { pool } } } impl DataSource for DbDataSource { async fn read_site_from_instance_id(&self, instance_id: InstanceId) -> LemmyResult { - Site::read_from_instance_id(&mut DbPool::Pool(&self.pool), instance_id).await + Site::read_from_instance_id(&mut DbPool::from(&self.pool), instance_id).await } async fn get_instance_followed_community_inboxes( @@ -66,7 +66,7 @@ impl DataSource for DbDataSource { last_fetch: DateTime, ) -> LemmyResult> { CommunityFollowerView::get_instance_followed_community_inboxes( - &mut DbPool::Pool(&self.pool), + &mut DbPool::from(&self.pool), instance_id, last_fetch, ) @@ -93,7 +93,7 @@ pub type RealCommunityInboxCollector = CommunityInboxCollector; impl CommunityInboxCollector { pub fn new_real( - pool: ActualDbPool, + pool: GenericDbPool, instance_id: InstanceId, domain: String, ) -> RealCommunityInboxCollector { diff --git a/crates/federate/src/stats.rs b/crates/federate/src/stats.rs index a8fc578d91..148291c9ac 100644 --- a/crates/federate/src/stats.rs +++ b/crates/federate/src/stats.rs @@ -2,7 +2,7 @@ use crate::util::{get_latest_activity_id, FederationQueueStateWithDomain}; use chrono::Local; use lemmy_db_schema::{ newtypes::InstanceId, - utils::{ActualDbPool, DbPool}, + utils::{DbPool, GenericDbPool}, }; use lemmy_utils::{error::LemmyResult, federate_retry_sleep_duration}; use std::{collections::HashMap, time::Duration}; @@ -12,10 +12,10 @@ use tracing::{debug, info, warn}; /// every 60s, print the state for every instance. exits if the receiver is done (all senders /// dropped) pub(crate) async fn receive_print_stats( - pool: ActualDbPool, + pool: GenericDbPool, mut receiver: UnboundedReceiver, ) { - let pool = &mut DbPool::Pool(&pool); + let pool = &mut DbPool::from(&pool); let mut printerval = interval(Duration::from_secs(60)); let mut stats = HashMap::new(); loop { diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index 7c3a23fab3..926d910f0c 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -18,7 +18,7 @@ use lemmy_db_schema::{ federation_queue_state::FederationQueueState, instance::{Instance, InstanceForm}, }, - utils::{ActualDbPool, DbPool}, + utils::{DbPool, GenericDbPool}, }; use lemmy_utils::{ error::LemmyResult, @@ -65,7 +65,7 @@ pub(crate) struct InstanceWorker { federation_worker_config: FederationWorkerConfig, state: FederationQueueState, last_state_insert: DateTime, - pool: ActualDbPool, + pool: GenericDbPool, inbox_collector: RealCommunityInboxCollector, // regularily send stats back to the SendManager stats_sender: UnboundedSender, @@ -89,9 +89,8 @@ impl InstanceWorker { stats_sender: UnboundedSender, ) -> LemmyResult<()> { let pool = config.to_request_data().inner_pool().clone(); - let state = FederationQueueState::load(&mut DbPool::Pool(&pool), instance.id).await?; - let (report_send_result, receive_send_result) = - tokio::sync::mpsc::unbounded_channel::(); + let state = FederationQueueState::load(&mut DbPool::from(&pool), instance.id).await?; + let (report_send_result, receive_send_result) = mpsc::unbounded_channel::(); let mut worker = InstanceWorker { inbox_collector: RealCommunityInboxCollector::new_real( pool.clone(), @@ -442,7 +441,7 @@ impl InstanceWorker { } fn pool(&self) -> DbPool<'_> { - DbPool::Pool(&self.pool) + DbPool::from(&self.pool) } } diff --git a/src/lib.rs b/src/lib.rs index 61ae702a98..4177a3950e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,10 @@ use lemmy_apub::{ FEDERATION_HTTP_FETCH_LIMIT, }; use lemmy_apub_objects::objects::{community::FETCH_COMMUNITY_COLLECTIONS, instance::ApubSite}; -use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool}; +use lemmy_db_schema::{ + source::secret::Secret, + utils::{build_db_pool, GenericDbPool}, +}; use lemmy_db_views_site::SiteView; use lemmy_federate::{Opts, SendManager}; use lemmy_routes::{ @@ -205,7 +208,7 @@ pub async fn start_lemmy_server(args: CmdArgs) -> LemmyResult<()> { .with(TracingMiddleware::default()) .build(); let context = LemmyContext::create( - pool.clone(), + GenericDbPool::Actual(pool.clone()), client.clone(), pictrs_client, secret.clone(), From e90c8bee4c1f464540bdb807d185fab17b6d47a4 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 16 Jul 2025 03:03:57 +0300 Subject: [PATCH 06/40] fix taplo --- crates/db_schema/Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 4e13459fbf..232cdfc801 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -76,7 +76,10 @@ uuid.workspace = true i-love-jesus = { workspace = true, optional = true } derive-new.workspace = true moka = { workspace = true, optional = true } -db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test", features = ["diesel-async-postgres", "diesel-async-deadpool"] } +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test", features = [ + "diesel-async-postgres", + "diesel-async-deadpool", +] } [dev-dependencies] From 5d6fe0cddf77a08a2d78f65076b048ef4f87224b Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 16 Jul 2025 03:12:48 +0300 Subject: [PATCH 07/40] clippy fix --- crates/db_schema_setup/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index ffc0101749..68b19a1185 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -263,7 +263,7 @@ where pub fn run(options: Options, db_url: &str) -> anyhow::Result { // Migrations don't support async connection, and this function doesn't need to be async - run_with_connection(options, PgConnection::establish(&db_url)?) + run_with_connection(options, PgConnection::establish(db_url)?) } fn run_replaceable_schema(conn: &mut Conn) -> anyhow::Result<()> From 418e91bad4bd10009797d9183e8a19644f8c6528 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Sun, 20 Jul 2025 00:14:48 +0300 Subject: [PATCH 08/40] clippy fix --- crates/db_schema/src/impls/activity.rs | 1 - crates/db_schema/src/impls/actor_language.rs | 1 - crates/db_schema/src/impls/captcha_answer.rs | 1 - crates/db_schema/src/impls/comment.rs | 1 - crates/db_schema/src/impls/community.rs | 1 - .../src/impls/federation_allowlist.rs | 1 - crates/db_schema/src/impls/language.rs | 1 - crates/db_schema/src/impls/local_site.rs | 1 - crates/db_schema/src/impls/local_user.rs | 1 - .../db_schema/src/impls/mod_log/moderator.rs | 1 - crates/db_schema/src/impls/multi_community.rs | 1 - .../src/impls/password_reset_request.rs | 1 - crates/db_schema/src/impls/person.rs | 1 - crates/db_schema/src/impls/post.rs | 1 - crates/db_schema/src/impls/post_report.rs | 1 - crates/db_schema/src/impls/private_message.rs | 1 - crates/db_schema/src/utils.rs | 40 ++++++++----------- 17 files changed, 17 insertions(+), 39 deletions(-) diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index a28bda6aca..0962c0b35f 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -67,7 +67,6 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; use serde_json::json; - use serial_test::serial; use url::Url; #[tokio::test] diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index 1c8bec391a..00bdf2a4b5 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -410,7 +410,6 @@ mod tests { utils::build_db_pool_for_tests, }; use pretty_assertions::assert_eq; - use serial_test::serial; async fn test_langs1(pool: &mut DbPool<'_>) -> LemmyResult> { Ok(vec![ diff --git a/crates/db_schema/src/impls/captcha_answer.rs b/crates/db_schema/src/impls/captcha_answer.rs index 269c69404f..b010b43943 100644 --- a/crates/db_schema/src/impls/captcha_answer.rs +++ b/crates/db_schema/src/impls/captcha_answer.rs @@ -51,7 +51,6 @@ mod tests { utils::build_db_pool_for_tests, }; use lemmy_utils::error::LemmyResult; - use serial_test::serial; #[tokio::test] async fn test_captcha_happy_path() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 93cd922116..eb00553423 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -388,7 +388,6 @@ mod tests { use diesel_ltree::Ltree; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; use url::Url; #[tokio::test] diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 4a53e43bde..80563e19cc 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -723,7 +723,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_crud() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index ebdae2d813..56249cba4f 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -32,7 +32,6 @@ mod tests { use super::*; use crate::{source::instance::Instance, utils::build_db_pool_for_tests}; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_allowlist_insert_and_clear() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/language.rs b/crates/db_schema/src/impls/language.rs index 8778a31fa0..f774fd2a32 100644 --- a/crates/db_schema/src/impls/language.rs +++ b/crates/db_schema/src/impls/language.rs @@ -49,7 +49,6 @@ mod tests { use crate::{source::language::Language, utils::build_db_pool_for_tests}; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_languages() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index df0dc0126c..403fa43100 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -54,7 +54,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; async fn read_local_site(pool: &mut DbPool<'_>) -> LemmyResult { let conn = &mut get_conn(pool).await?; diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index 440cf4adcb..b09196dc55 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -397,7 +397,6 @@ mod tests { utils::build_db_pool_for_tests, }; use lemmy_utils::error::LemmyResult; - use serial_test::serial; #[tokio::test] async fn test_admin_higher_check() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/mod_log/moderator.rs b/crates/db_schema/src/impls/mod_log/moderator.rs index b7196f78fc..cd662f3228 100644 --- a/crates/db_schema/src/impls/mod_log/moderator.rs +++ b/crates/db_schema/src/impls/mod_log/moderator.rs @@ -408,7 +408,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_crud() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/multi_community.rs b/crates/db_schema/src/impls/multi_community.rs index 0d83daee9c..9cc8e50a1f 100644 --- a/crates/db_schema/src/impls/multi_community.rs +++ b/crates/db_schema/src/impls/multi_community.rs @@ -325,7 +325,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { multi: MultiCommunity, diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index b01bc8b258..fb67263176 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -58,7 +58,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_password_reset() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 780ebd8020..f934d43390 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -468,7 +468,6 @@ mod tests { use diesel_uplete::UpleteCount; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_crud() -> LemmyResult<()> { diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 372e86f50d..a9bf1d2ce6 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -618,7 +618,6 @@ mod tests { use diesel_uplete::UpleteCount; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; use url::Url; #[tokio::test] diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index 5410a00c8d..234ab94c9d 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -103,7 +103,6 @@ mod tests { traits::Crud, utils::build_db_pool_for_tests, }; - use serial_test::serial; async fn init(pool: &mut DbPool<'_>) -> LemmyResult<(Person, PostReport)> { let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index 603b115ea9..141ded0c3b 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -112,7 +112,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; use url::Url; #[tokio::test] diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 2c62fa9d8e..956ef5fe54 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -4,10 +4,7 @@ use crate::newtypes::DbUrl; use chrono::TimeDelta; use db_pool::{ r#async::{ - DatabasePool, - DatabasePoolBuilderTrait, - DieselAsyncPostgresBackend, - DieselDeadpool, + DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool, ReusableConnectionPool, }, PrivilegedPostgresConfig, @@ -20,21 +17,18 @@ use diesel::{ query_builder::{Query, QueryFragment}, query_dsl::methods::LimitDsl, result::{ - ConnectionError, - ConnectionResult, + ConnectionError, ConnectionResult, Error::{self as DieselError, QueryBuilderError}, }, sql_types::{self, Timestamptz}, - Expression, - IntoSql, + Expression, IntoSql, }; use diesel_async::{ async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, - ManagerConfig, + AsyncDieselConnectionManager, ManagerConfig, }, scoped_futures::ScopedBoxFuture, AsyncConnection, @@ -48,16 +42,11 @@ use lemmy_utils::{ }; use rustls::{ client::danger::{ - DangerousClientConfigBuilder, - HandshakeSignatureValid, - ServerCertVerified, - ServerCertVerifier, + DangerousClientConfigBuilder, HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier, }, crypto::{self, verify_tls12_signature, verify_tls13_signature}, pki_types::{CertificateDer, ServerName, UnixTime}, - ClientConfig, - DigitallySignedStruct, - SignatureScheme, + ClientConfig, DigitallySignedStruct, SignatureScheme, }; use std::{ ops::{Deref, DerefMut}, @@ -574,13 +563,18 @@ pub async fn build_db_pool_for_tests( .get_or_init(|| async { let conn_string = SETTINGS.get_database_url(); - let db_url = Url::parse(conn_string.as_str()).unwrap(); + let db_url = Url::parse(conn_string.as_str()).expect("db url"); let config = PrivilegedPostgresConfig::new() - .host(db_url.host().unwrap().to_string()) - .port(db_url.port().unwrap()) + .host(db_url.host().expect("db host").to_string()) + .port(db_url.port().expect("db port")) .username(db_url.username().to_string()) - .password(Some(db_url.password().unwrap().to_string())); + .password(Some( + db_url + .password() + .expect("db password") + .to_string(), + )); let backend = DieselAsyncPostgresBackend::new( config, @@ -603,9 +597,9 @@ pub async fn build_db_pool_for_tests( }, ) .await - .unwrap(); + .expect("diesel postgres backend"); - backend.create_database_pool().await.unwrap() + backend.create_database_pool().await.expect("create db pool") }) .await; From fe3305b4aeb39d92de6389ec8bce043446307741 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Sun, 20 Jul 2025 03:10:18 +0300 Subject: [PATCH 09/40] fmt fix --- crates/db_schema/src/utils.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 956ef5fe54..fb010714b4 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -4,7 +4,10 @@ use crate::newtypes::DbUrl; use chrono::TimeDelta; use db_pool::{ r#async::{ - DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool, + DatabasePool, + DatabasePoolBuilderTrait, + DieselAsyncPostgresBackend, + DieselDeadpool, ReusableConnectionPool, }, PrivilegedPostgresConfig, @@ -17,18 +20,21 @@ use diesel::{ query_builder::{Query, QueryFragment}, query_dsl::methods::LimitDsl, result::{ - ConnectionError, ConnectionResult, + ConnectionError, + ConnectionResult, Error::{self as DieselError, QueryBuilderError}, }, sql_types::{self, Timestamptz}, - Expression, IntoSql, + Expression, + IntoSql, }; use diesel_async::{ async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, ManagerConfig, + AsyncDieselConnectionManager, + ManagerConfig, }, scoped_futures::ScopedBoxFuture, AsyncConnection, @@ -42,11 +48,16 @@ use lemmy_utils::{ }; use rustls::{ client::danger::{ - DangerousClientConfigBuilder, HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier, + DangerousClientConfigBuilder, + HandshakeSignatureValid, + ServerCertVerified, + ServerCertVerifier, }, crypto::{self, verify_tls12_signature, verify_tls13_signature}, pki_types::{CertificateDer, ServerName, UnixTime}, - ClientConfig, DigitallySignedStruct, SignatureScheme, + ClientConfig, + DigitallySignedStruct, + SignatureScheme, }; use std::{ ops::{Deref, DerefMut}, @@ -569,12 +580,7 @@ pub async fn build_db_pool_for_tests( .host(db_url.host().expect("db host").to_string()) .port(db_url.port().expect("db port")) .username(db_url.username().to_string()) - .password(Some( - db_url - .password() - .expect("db password") - .to_string(), - )); + .password(Some(db_url.password().expect("db password").to_string())); let backend = DieselAsyncPostgresBackend::new( config, @@ -599,7 +605,10 @@ pub async fn build_db_pool_for_tests( .await .expect("diesel postgres backend"); - backend.create_database_pool().await.expect("create db pool") + backend + .create_database_pool() + .await + .expect("create db pool") }) .await; From 4377da8280d7f85821c24f1754d5cd165ef390ff Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 23 Jul 2025 22:53:44 +0300 Subject: [PATCH 10/40] shear fix --- Cargo.lock | 1 - crates/db_schema/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b3914cdcc..d5217c8f5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3391,7 +3391,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "strum", "tokio", "tokio-postgres", diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 232cdfc801..af3d4e2435 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -83,5 +83,4 @@ db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "ed [dev-dependencies] -serial_test = { workspace = true } pretty_assertions = { workspace = true } From e18c7f7ce405a3aaff970bf33d4f007727598837 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 23 Jul 2025 23:21:46 +0300 Subject: [PATCH 11/40] clippy + shear fixes --- Cargo.lock | 13 ------------- crates/api/api_utils/src/notify.rs | 6 +----- crates/db_schema_setup/src/lib.rs | 1 + crates/db_views/comment/Cargo.toml | 1 - crates/db_views/comment/src/impls.rs | 1 - crates/db_views/community/Cargo.toml | 1 - crates/db_views/community/src/impls.rs | 1 - crates/db_views/community_follower/Cargo.toml | 1 - crates/db_views/community_follower/src/impls.rs | 1 - crates/db_views/local_user/Cargo.toml | 1 - crates/db_views/local_user/src/impls.rs | 1 - crates/db_views/modlog_combined/Cargo.toml | 1 - crates/db_views/modlog_combined/src/impls.rs | 1 - crates/db_views/person/Cargo.toml | 1 - crates/db_views/person/src/impls.rs | 1 - crates/db_views/person_content_combined/Cargo.toml | 1 - .../db_views/person_content_combined/src/impls.rs | 1 - crates/db_views/person_liked_combined/Cargo.toml | 1 - crates/db_views/person_liked_combined/src/impls.rs | 1 - crates/db_views/person_saved_combined/Cargo.toml | 1 - crates/db_views/person_saved_combined/src/impls.rs | 1 - .../db_views/registration_applications/Cargo.toml | 1 - .../db_views/registration_applications/src/impls.rs | 1 - crates/db_views/report_combined/Cargo.toml | 1 - crates/db_views/report_combined/src/impls.rs | 1 - crates/db_views/search_combined/Cargo.toml | 1 - crates/db_views/search_combined/src/impls.rs | 1 - crates/db_views/vote/Cargo.toml | 1 - crates/db_views/vote/src/impls.rs | 1 - 29 files changed, 2 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5217c8f5b..4c72908817 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3449,7 +3449,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3468,7 +3467,6 @@ dependencies = [ "lemmy_utils", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -3487,7 +3485,6 @@ dependencies = [ "lemmy_utils", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3562,7 +3559,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3580,7 +3576,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3617,7 +3612,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3639,7 +3633,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3660,7 +3653,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3681,7 +3673,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3750,7 +3741,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3770,7 +3760,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3793,7 +3782,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -3837,7 +3825,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] diff --git a/crates/api/api_utils/src/notify.rs b/crates/api/api_utils/src/notify.rs index 237c6681ac..a12703dd93 100644 --- a/crates/api/api_utils/src/notify.rs +++ b/crates/api/api_utils/src/notify.rs @@ -491,9 +491,8 @@ mod tests { } #[tokio::test] - #[serial] async fn mentions() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -632,7 +631,6 @@ mod tests { } #[tokio::test] - #[serial] async fn read_private_messages() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -681,7 +679,6 @@ mod tests { } #[tokio::test] - #[serial] async fn ensure_private_message_person_block() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -723,7 +720,6 @@ mod tests { } #[tokio::test] - #[serial] async fn ensure_private_message_instance_block() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index e5144b5d35..56ce1f058f 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -352,6 +352,7 @@ mod tests { dsl::{not, sql}, sql_types, }; + use diesel::connection::SimpleConnection; use diesel_ltree::Ltree; use lemmy_utils::{error::LemmyResult, settings::SETTINGS}; use serial_test::serial; diff --git a/crates/db_views/comment/Cargo.toml b/crates/db_views/comment/Cargo.toml index c9937e8a0e..c9ee5bf3cc 100644 --- a/crates/db_views/comment/Cargo.toml +++ b/crates/db_views/comment/Cargo.toml @@ -48,6 +48,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/comment/src/impls.rs b/crates/db_views/comment/src/impls.rs index 2b1079997f..444a6af6cf 100644 --- a/crates/db_views/comment/src/impls.rs +++ b/crates/db_views/comment/src/impls.rs @@ -349,7 +349,6 @@ mod tests { use lemmy_db_views_local_user::LocalUserView; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; // TODO rename these struct Data { diff --git a/crates/db_views/community/Cargo.toml b/crates/db_views/community/Cargo.toml index 7fe6f9f540..fc6648bce2 100644 --- a/crates/db_views/community/Cargo.toml +++ b/crates/db_views/community/Cargo.toml @@ -48,6 +48,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } url = { workspace = true } diff --git a/crates/db_views/community/src/impls.rs b/crates/db_views/community/src/impls.rs index c3a15df181..45b1101e95 100644 --- a/crates/db_views/community/src/impls.rs +++ b/crates/db_views/community/src/impls.rs @@ -266,7 +266,6 @@ mod tests { }; use lemmy_db_schema_file::enums::{CommunityFollowerState, CommunityVisibility}; use lemmy_utils::error::{LemmyErrorType, LemmyResult}; - use serial_test::serial; use std::collections::HashSet; use url::Url; diff --git a/crates/db_views/community_follower/Cargo.toml b/crates/db_views/community_follower/Cargo.toml index 8b4283d55c..990bcb037c 100644 --- a/crates/db_views/community_follower/Cargo.toml +++ b/crates/db_views/community_follower/Cargo.toml @@ -39,5 +39,4 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/community_follower/src/impls.rs b/crates/db_views/community_follower/src/impls.rs index 4f4936dbda..1cc4da5e6c 100644 --- a/crates/db_views/community_follower/src/impls.rs +++ b/crates/db_views/community_follower/src/impls.rs @@ -294,7 +294,6 @@ mod tests { traits::{Crud, Followable}, utils::build_db_pool_for_tests, }; - use serial_test::serial; #[tokio::test] async fn test_has_followers_from_instance() -> LemmyResult<()> { diff --git a/crates/db_views/local_user/Cargo.toml b/crates/db_views/local_user/Cargo.toml index 214be75d96..8abf7fa985 100644 --- a/crates/db_views/local_user/Cargo.toml +++ b/crates/db_views/local_user/Cargo.toml @@ -40,6 +40,5 @@ actix-web = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/local_user/src/impls.rs b/crates/db_views/local_user/src/impls.rs index ba6be26103..b87306e786 100644 --- a/crates/db_views/local_user/src/impls.rs +++ b/crates/db_views/local_user/src/impls.rs @@ -247,7 +247,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { alice: Person, diff --git a/crates/db_views/modlog_combined/Cargo.toml b/crates/db_views/modlog_combined/Cargo.toml index e59aec95cd..84fd10134a 100644 --- a/crates/db_views/modlog_combined/Cargo.toml +++ b/crates/db_views/modlog_combined/Cargo.toml @@ -39,5 +39,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/modlog_combined/src/impls.rs b/crates/db_views/modlog_combined/src/impls.rs index 2e292e1d94..0085333cf6 100644 --- a/crates/db_views/modlog_combined/src/impls.rs +++ b/crates/db_views/modlog_combined/src/impls.rs @@ -680,7 +680,6 @@ mod tests { use lemmy_db_schema_file::enums::CommunityVisibility; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, diff --git a/crates/db_views/person/Cargo.toml b/crates/db_views/person/Cargo.toml index 0477a26627..dfbcf4e4af 100644 --- a/crates/db_views/person/Cargo.toml +++ b/crates/db_views/person/Cargo.toml @@ -44,6 +44,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/person/src/impls.rs b/crates/db_views/person/src/impls.rs index 706f6fe4a9..ee59b1e1e3 100644 --- a/crates/db_views/person/src/impls.rs +++ b/crates/db_views/person/src/impls.rs @@ -139,7 +139,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { alice: Person, diff --git a/crates/db_views/person_content_combined/Cargo.toml b/crates/db_views/person_content_combined/Cargo.toml index b646982794..03f4424fa3 100644 --- a/crates/db_views/person_content_combined/Cargo.toml +++ b/crates/db_views/person_content_combined/Cargo.toml @@ -49,5 +49,4 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/person_content_combined/src/impls.rs b/crates/db_views/person_content_combined/src/impls.rs index 97f968b687..079039667b 100644 --- a/crates/db_views/person_content_combined/src/impls.rs +++ b/crates/db_views/person_content_combined/src/impls.rs @@ -291,7 +291,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, diff --git a/crates/db_views/person_liked_combined/Cargo.toml b/crates/db_views/person_liked_combined/Cargo.toml index 46c0b48116..f80943194a 100644 --- a/crates/db_views/person_liked_combined/Cargo.toml +++ b/crates/db_views/person_liked_combined/Cargo.toml @@ -49,5 +49,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/person_liked_combined/src/impls.rs b/crates/db_views/person_liked_combined/src/impls.rs index 6acf77524d..3e231dc6d5 100644 --- a/crates/db_views/person_liked_combined/src/impls.rs +++ b/crates/db_views/person_liked_combined/src/impls.rs @@ -282,7 +282,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, diff --git a/crates/db_views/person_saved_combined/Cargo.toml b/crates/db_views/person_saved_combined/Cargo.toml index 9fe1f51707..852afcd519 100644 --- a/crates/db_views/person_saved_combined/Cargo.toml +++ b/crates/db_views/person_saved_combined/Cargo.toml @@ -49,5 +49,4 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/person_saved_combined/src/impls.rs b/crates/db_views/person_saved_combined/src/impls.rs index d8e468ca75..8c51514889 100644 --- a/crates/db_views/person_saved_combined/src/impls.rs +++ b/crates/db_views/person_saved_combined/src/impls.rs @@ -271,7 +271,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, diff --git a/crates/db_views/registration_applications/Cargo.toml b/crates/db_views/registration_applications/Cargo.toml index ac6d14e0e0..b713e9dd3b 100644 --- a/crates/db_views/registration_applications/Cargo.toml +++ b/crates/db_views/registration_applications/Cargo.toml @@ -38,6 +38,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/registration_applications/src/impls.rs b/crates/db_views/registration_applications/src/impls.rs index 3d40323937..7894eeb144 100644 --- a/crates/db_views/registration_applications/src/impls.rs +++ b/crates/db_views/registration_applications/src/impls.rs @@ -155,7 +155,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn test_crud() -> LemmyResult<()> { diff --git a/crates/db_views/report_combined/Cargo.toml b/crates/db_views/report_combined/Cargo.toml index 199f8a7668..17cc25cdd8 100644 --- a/crates/db_views/report_combined/Cargo.toml +++ b/crates/db_views/report_combined/Cargo.toml @@ -41,5 +41,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/report_combined/src/impls.rs b/crates/db_views/report_combined/src/impls.rs index 7471c409d0..22af2fb1e0 100644 --- a/crates/db_views/report_combined/src/impls.rs +++ b/crates/db_views/report_combined/src/impls.rs @@ -600,7 +600,6 @@ mod tests { use lemmy_db_schema_file::schema::report_combined; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, diff --git a/crates/db_views/search_combined/Cargo.toml b/crates/db_views/search_combined/Cargo.toml index da7bbe36ca..aab4fe4a3b 100644 --- a/crates/db_views/search_combined/Cargo.toml +++ b/crates/db_views/search_combined/Cargo.toml @@ -56,6 +56,5 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } url = { workspace = true } diff --git a/crates/db_views/search_combined/src/impls.rs b/crates/db_views/search_combined/src/impls.rs index a89a1695e2..95318207c6 100644 --- a/crates/db_views/search_combined/src/impls.rs +++ b/crates/db_views/search_combined/src/impls.rs @@ -510,7 +510,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; use url::Url; struct Data { diff --git a/crates/db_views/vote/Cargo.toml b/crates/db_views/vote/Cargo.toml index 43b64b8a30..c4c48168af 100644 --- a/crates/db_views/vote/Cargo.toml +++ b/crates/db_views/vote/Cargo.toml @@ -38,6 +38,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/vote/src/impls.rs b/crates/db_views/vote/src/impls.rs index 3d0bfaecbc..db95f36a46 100644 --- a/crates/db_views/vote/src/impls.rs +++ b/crates/db_views/vote/src/impls.rs @@ -217,7 +217,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] async fn post_and_comment_vote_views() -> LemmyResult<()> { From 5264ab11276a141e35ff5a9c5f7d334160610f2f Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 23 Jul 2025 23:24:47 +0300 Subject: [PATCH 12/40] fmt fix --- crates/db_schema_setup/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index 56ce1f058f..f2adfd8c86 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -349,10 +349,10 @@ mod tests { *, }; use diesel::{ + connection::SimpleConnection, dsl::{not, sql}, sql_types, }; - use diesel::connection::SimpleConnection; use diesel_ltree::Ltree; use lemmy_utils::{error::LemmyResult, settings::SETTINGS}; use serial_test::serial; From 6e795ea17dd13ac5765025e6ae3e369f4361989e Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 28 Jul 2025 01:17:13 +0300 Subject: [PATCH 13/40] fix merge issues --- crates/db_schema/src/utils.rs | 4 ++-- crates/db_schema_setup/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 51e6984a11..764717e464 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -557,12 +557,12 @@ pub async fn build_db_pool_for_tests( None, move |conn| { Box::pin(async { - let async_wrapper: AsyncConnectionWrapper = + let mut async_wrapper: AsyncConnectionWrapper = AsyncConnectionWrapper::from(conn); lemmy_db_schema_setup::run_with_connection( lemmy_db_schema_setup::Options::default().run(), - async_wrapper, + &mut async_wrapper, ) .expect("run migrations"); diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index 4b0e12b2ce..14e27ec4a1 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -191,7 +191,7 @@ pub enum Branch { ReplaceableSchemaNotRebuilt, } -pub fn run_with_connection(options: Options, &mut conn: Conn) -> anyhow::Result +pub fn run_with_connection(options: Options, conn: &mut Conn) -> anyhow::Result where Conn: Connection + MigrationHarness + LoadConnection, { From 603efb33d59ca6e39563e5970bcb079fd4130e38 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 28 Jul 2025 01:51:58 +0300 Subject: [PATCH 14/40] config forrunning new tests locally --- scripts/start_test_db.sh | 7 +++++++ scripts/test.sh | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 scripts/start_test_db.sh diff --git a/scripts/start_test_db.sh b/scripts/start_test_db.sh new file mode 100644 index 0000000000..ab9e2f2490 --- /dev/null +++ b/scripts/start_test_db.sh @@ -0,0 +1,7 @@ +export PGUSER=postgres +export LEMMY_DATABASE_HOST=localhost +export LEMMY_DATABASE_PORT=5433 +export LEMMY_DATABASE_URL="postgresql://lemmy:password@$LEMMY_DATABASE_HOST:$LEMMY_DATABASE_PORT/lemmy" +export PGDATABASE=lemmy + +docker-compose -f docker/docker-compose.yml up -d postgres diff --git a/scripts/test.sh b/scripts/test.sh index 85d4ea1655..e36561978b 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -8,7 +8,7 @@ cd "$CWD/../" PACKAGE="$1" TEST="$2" -source scripts/start_dev_db.sh +source scripts/start_test_db.sh # tests are executed in working directory crates/api (or similar), # so to load the config we need to traverse to the repo root @@ -24,5 +24,4 @@ fi # Add this to do printlns: -- --nocapture -pg_ctl stop --silent -rm -rf $PGDATA +docker-compose -f docker/docker-compose.yml down postgres From 64bc9e62a0a9fa4f937d48c61a39df3e8980c57e Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 13 Aug 2025 01:24:21 +0300 Subject: [PATCH 15/40] removing the rest of serial tests --- Cargo.lock | 48 ------------------- crates/api/api/Cargo.toml | 1 - crates/api/api/src/site/mod_log.rs | 2 - .../site/registration_applications/tests.rs | 2 - crates/api/api_utils/Cargo.toml | 1 - crates/api/api_utils/src/claims.rs | 2 - crates/api/api_utils/src/notify.rs | 2 - crates/api/api_utils/src/request.rs | 2 - crates/api/api_utils/src/utils.rs | 2 - crates/apub/Cargo.toml | 1 - crates/apub/src/api/resolve_object.rs | 2 - crates/apub/src/api/user_settings_backup.rs | 4 -- .../src/collections/community_moderators.rs | 2 - crates/apub/src/http/community.rs | 5 -- crates/apub_objects/Cargo.toml | 1 - crates/apub_objects/src/objects/comment.rs | 4 -- crates/apub_objects/src/objects/community.rs | 2 - crates/apub_objects/src/objects/instance.rs | 2 - crates/apub_objects/src/objects/person.rs | 3 -- crates/apub_objects/src/objects/post.rs | 3 -- .../src/objects/private_message.rs | 3 -- .../apub_objects/src/utils/markdown_links.rs | 3 -- crates/db_schema/src/impls/mod_log/mod.rs | 4 +- crates/db_schema/src/utils.rs | 37 ++++++-------- crates/db_schema_setup/Cargo.toml | 1 - crates/db_schema_setup/src/lib.rs | 2 - crates/db_views/post/Cargo.toml | 1 - crates/db_views/post/src/db_perf/mod.rs | 2 - crates/db_views/post/src/impls.rs | 30 ------------ crates/federate/Cargo.toml | 1 - crates/federate/src/lib.rs | 6 --- crates/federate/src/worker.rs | 6 --- crates/routes/Cargo.toml | 1 - crates/routes/src/middleware/session.rs | 2 - crates/routes/src/utils/scheduled_tasks.rs | 2 - 35 files changed, 16 insertions(+), 176 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f064a21801..627a30220d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3152,7 +3152,6 @@ dependencies = [ "lemmy_utils", "pretty_assertions", "regex", - "serial_test", "sitemap-rs", "tokio", "totp-rs", @@ -3273,7 +3272,6 @@ dependencies = [ "reqwest-middleware", "serde", "serde_json", - "serial_test", "tokio", "tracing", "url", @@ -3318,7 +3316,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "strum", "tokio", "tracing", @@ -3357,7 +3354,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "stringreader", "tokio", "tracing", @@ -3427,7 +3423,6 @@ dependencies = [ "lemmy_db_schema_file", "lemmy_utils", "pathfinding", - "serial_test", "tracing", "unified-diff", ] @@ -3694,7 +3689,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "test-context", "tokio", "tracing", @@ -3867,7 +3861,6 @@ dependencies = [ "reqwest 0.12.19", "serde", "serde_json", - "serial_test", "test-context", "tokio", "tokio-util", @@ -3914,7 +3907,6 @@ dependencies = [ "reqwest-middleware", "rss", "serde", - "serial_test", "tokio", "tracing", "url", @@ -5803,15 +5795,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scc" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22b2d775fb28f245817589471dd49c5edf64237f4a19d10ce9a92ff4651a27f4" -dependencies = [ - "sdd", -] - [[package]] name = "scoped-futures" version = "0.1.4" @@ -5843,12 +5826,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "sdd" -version = "3.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584e070911c7017da6cb2eb0788d09f43d789029b5877d3e5ecc8acf86ceee21" - [[package]] name = "select" version = "0.6.1" @@ -5959,31 +5936,6 @@ dependencies = [ "syn 2.0.102", ] -[[package]] -name = "serial_test" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9" -dependencies = [ - "futures", - "log", - "once_cell", - "parking_lot", - "scc", - "serial_test_derive", -] - -[[package]] -name = "serial_test_derive" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.102", -] - [[package]] name = "sha1" version = "0.10.6" diff --git a/crates/api/api/Cargo.toml b/crates/api/api/Cargo.toml index 9e66d52988..16407b231b 100644 --- a/crates/api/api/Cargo.toml +++ b/crates/api/api/Cargo.toml @@ -66,7 +66,6 @@ diesel-async = { workspace = true, features = ["deadpool", "postgres"] } either = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } elementtree = "1.2.3" pretty_assertions = { workspace = true } diff --git a/crates/api/api/src/site/mod_log.rs b/crates/api/api/src/site/mod_log.rs index 11f7a32658..d473c89ce0 100644 --- a/crates/api/api/src/site/mod_log.rs +++ b/crates/api/api/src/site/mod_log.rs @@ -107,10 +107,8 @@ mod tests { }; use lemmy_db_views_post::PostView; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_mod_remove_or_restore_data() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api/src/site/registration_applications/tests.rs b/crates/api/api/src/site/registration_applications/tests.rs index 94135d981b..cd574f7b0a 100644 --- a/crates/api/api/src/site/registration_applications/tests.rs +++ b/crates/api/api/src/site/registration_applications/tests.rs @@ -28,7 +28,6 @@ use lemmy_db_views_registration_applications::api::{ }; use lemmy_db_views_site::api::EditSite; use lemmy_utils::{error::LemmyResult, CACHE_DURATION_API}; -use serial_test::serial; async fn create_test_site(context: &Data) -> LemmyResult<(TestData, LocalUserView)> { let pool = &mut context.pool(); @@ -118,7 +117,6 @@ async fn get_application_statuses( Ok((application_count, unread_applications, all_applications)) } -#[serial] #[tokio::test] #[expect(clippy::indexing_slicing)] async fn test_application_approval() -> LemmyResult<()> { diff --git a/crates/api/api_utils/Cargo.toml b/crates/api/api_utils/Cargo.toml index 63544cae75..c3df087ed3 100644 --- a/crates/api/api_utils/Cargo.toml +++ b/crates/api/api_utils/Cargo.toml @@ -80,7 +80,6 @@ either.workspace = true derive-new.workspace = true [dev-dependencies] -serial_test = { workspace = true } pretty_assertions = { workspace = true } lemmy_db_views_notification = { workspace = true, features = ["full"] } diesel_ltree = { workspace = true } diff --git a/crates/api/api_utils/src/claims.rs b/crates/api/api_utils/src/claims.rs index 5063ea8fe1..462dea71ab 100644 --- a/crates/api/api_utils/src/claims.rs +++ b/crates/api/api_utils/src/claims.rs @@ -83,10 +83,8 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_should_not_validate_user_token_after_password_change() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api_utils/src/notify.rs b/crates/api/api_utils/src/notify.rs index 00159e3cfd..7126290f1b 100644 --- a/crates/api/api_utils/src/notify.rs +++ b/crates/api/api_utils/src/notify.rs @@ -303,7 +303,6 @@ mod tests { use lemmy_db_views_private_message::PrivateMessageView; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, @@ -413,7 +412,6 @@ mod tests { } #[tokio::test] - #[serial] async fn replies() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api_utils/src/request.rs b/crates/api/api_utils/src/request.rs index ca0470ba97..d4d8cddf13 100644 --- a/crates/api/api_utils/src/request.rs +++ b/crates/api/api_utils/src/request.rs @@ -568,12 +568,10 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; use url::Url; // These helped with testing #[tokio::test] - #[serial] async fn test_link_metadata() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let sample_url = Url::parse("https://gitlab.com/IzzyOnDroid/repo/-/wikis/FAQ")?; diff --git a/crates/api/api_utils/src/utils.rs b/crates/api/api_utils/src/utils.rs index bd12edf83e..13ae06eddf 100644 --- a/crates/api/api_utils/src/utils.rs +++ b/crates/api/api_utils/src/utils.rs @@ -1034,7 +1034,6 @@ mod tests { use diesel_ltree::Ltree; use lemmy_db_schema::newtypes::LanguageId; use pretty_assertions::assert_eq; - use serial_test::serial; #[test] #[rustfmt::skip] @@ -1071,7 +1070,6 @@ mod tests { } #[tokio::test] - #[serial] async fn test_proxy_image_link() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index f66eaf1bdd..3888587ccd 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -62,7 +62,6 @@ enum_delegate = "0.2.0" either = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } pretty_assertions = { workspace = true } [package.metadata.cargo-shear] diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index 32ef8a9590..153d05ead4 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -82,10 +82,8 @@ mod tests { test_data::TestData, traits::Crud, }; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_object_visibility() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index e6bed68182..b3fc1869b5 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -280,12 +280,10 @@ pub(crate) mod tests { use lemmy_db_views_community_follower::CommunityFollowerView; use lemmy_db_views_local_user::LocalUserView; use lemmy_utils::error::{LemmyErrorType, LemmyResult}; - use serial_test::serial; use std::time::Duration; use tokio::time::sleep; #[tokio::test] - #[serial] async fn test_settings_export_import() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -336,7 +334,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn disallow_large_backup() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -373,7 +370,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn import_partial_backup() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index c2e85b2f44..ad9256fae4 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -79,10 +79,8 @@ mod tests { traits::Crud, }; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_parse_lemmy_community_moderators() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (new_mod, site) = parse_lemmy_person(&context).await?; diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index 1a0a0438a9..1dfee655d4 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -242,7 +242,6 @@ pub(crate) mod tests { traits::Crud, }; use serde::de::DeserializeOwned; - use serial_test::serial; use url::Url; async fn init( @@ -278,7 +277,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_get_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, community, path) = init(false, CommunityVisibility::Public, &context).await?; @@ -317,7 +315,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_get_deleted_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, _, path) = init(true, CommunityVisibility::Public, &context).await?; @@ -347,7 +344,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_get_local_only_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, _, path) = init(false, CommunityVisibility::LocalOnlyPrivate, &context).await?; @@ -373,7 +369,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_outbox_deleted_user() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, community, path) = init(false, CommunityVisibility::Public, &context).await?; diff --git a/crates/apub_objects/Cargo.toml b/crates/apub_objects/Cargo.toml index 89f1afa6ad..1348324e2b 100644 --- a/crates/apub_objects/Cargo.toml +++ b/crates/apub_objects/Cargo.toml @@ -54,7 +54,6 @@ assert-json-diff = "2.0.2" once_cell = { version = "1.21.3" } [dev-dependencies] -serial_test = { workspace = true } pretty_assertions = { workspace = true } [package.metadata.cargo-shear] diff --git a/crates/apub_objects/src/objects/comment.rs b/crates/apub_objects/src/objects/comment.rs index 3a3b7094b6..56ffb4e743 100644 --- a/crates/apub_objects/src/objects/comment.rs +++ b/crates/apub_objects/src/objects/comment.rs @@ -259,7 +259,6 @@ pub(crate) mod tests { test_data::TestData, }; use pretty_assertions::assert_eq; - use serial_test::serial; async fn prepare_comment_test( url: &Url, @@ -288,7 +287,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] pub(crate) async fn test_parse_lemmy_comment() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; @@ -315,7 +313,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_parse_pleroma_comment() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; @@ -343,7 +340,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_html_to_markdown_sanitize() { let parsed = parse_html("hello"); assert_eq!(parsed, "**hello**"); diff --git a/crates/apub_objects/src/objects/community.rs b/crates/apub_objects/src/objects/community.rs index 0917ea1748..a37a546787 100644 --- a/crates/apub_objects/src/objects/community.rs +++ b/crates/apub_objects/src/objects/community.rs @@ -294,10 +294,8 @@ pub(crate) mod tests { use crate::utils::test::{parse_lemmy_community, parse_lemmy_instance}; use lemmy_db_schema::source::site::Site; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_parse_lemmy_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let site = parse_lemmy_instance(&context).await?; diff --git a/crates/apub_objects/src/objects/instance.rs b/crates/apub_objects/src/objects/instance.rs index c71d2a0bdf..dda01c26e6 100644 --- a/crates/apub_objects/src/objects/instance.rs +++ b/crates/apub_objects/src/objects/instance.rs @@ -223,10 +223,8 @@ pub(crate) mod tests { use super::*; use crate::utils::test::parse_lemmy_instance; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_parse_lemmy_instance() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let site = parse_lemmy_instance(&context).await?; diff --git a/crates/apub_objects/src/objects/person.rs b/crates/apub_objects/src/objects/person.rs index a5d1bb65ed..2718e6511a 100644 --- a/crates/apub_objects/src/objects/person.rs +++ b/crates/apub_objects/src/objects/person.rs @@ -223,10 +223,8 @@ pub(crate) mod tests { use activitypub_federation::fetch::object_id::ObjectId; use lemmy_db_schema::source::site::Site; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_parse_lemmy_person() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (person, site) = parse_lemmy_person(&context).await?; @@ -240,7 +238,6 @@ pub(crate) mod tests { } #[tokio::test] - #[serial] async fn test_parse_pleroma_person() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/apub_objects/src/objects/post.rs b/crates/apub_objects/src/objects/post.rs index 15f4e296f2..684d202565 100644 --- a/crates/apub_objects/src/objects/post.rs +++ b/crates/apub_objects/src/objects/post.rs @@ -375,10 +375,8 @@ mod tests { }; use lemmy_db_schema::source::{community::Community, person::Person, site::Site}; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_parse_lemmy_post() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (person, site) = parse_lemmy_person(&context).await?; @@ -405,7 +403,6 @@ mod tests { } #[tokio::test] - #[serial] async fn test_convert_mastodon_post_title() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let community = parse_lemmy_community(&context).await?; diff --git a/crates/apub_objects/src/objects/private_message.rs b/crates/apub_objects/src/objects/private_message.rs index 388d176594..76702d010c 100644 --- a/crates/apub_objects/src/objects/private_message.rs +++ b/crates/apub_objects/src/objects/private_message.rs @@ -183,7 +183,6 @@ mod tests { use assert_json_diff::assert_json_include; use lemmy_db_schema::{source::site::Site, test_data::TestData}; use pretty_assertions::assert_eq; - use serial_test::serial; async fn prepare_comment_test( url: &Url, @@ -212,7 +211,6 @@ mod tests { } #[tokio::test] - #[serial] async fn test_parse_lemmy_pm() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; @@ -238,7 +236,6 @@ mod tests { } #[tokio::test] - #[serial] async fn test_parse_pleroma_pm() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; diff --git a/crates/apub_objects/src/utils/markdown_links.rs b/crates/apub_objects/src/utils/markdown_links.rs index ccb776c0b6..cd37b7e35d 100644 --- a/crates/apub_objects/src/utils/markdown_links.rs +++ b/crates/apub_objects/src/utils/markdown_links.rs @@ -78,10 +78,7 @@ mod tests { use lemmy_db_views_local_user::LocalUserView; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; - #[serial] - #[tokio::test] async fn test_markdown_rewrite_remote_links() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let data = TestData::create(&mut context.pool()).await?; diff --git a/crates/db_schema/src/impls/mod_log/mod.rs b/crates/db_schema/src/impls/mod_log/mod.rs index acccac72ba..ac34e2595f 100644 --- a/crates/db_schema/src/impls/mod_log/mod.rs +++ b/crates/db_schema/src/impls/mod_log/mod.rs @@ -18,12 +18,10 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_crud() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 764717e464..05b006247b 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -4,10 +4,7 @@ use crate::newtypes::DbUrl; use chrono::TimeDelta; use db_pool::{ r#async::{ - DatabasePool, - DatabasePoolBuilderTrait, - DieselAsyncPostgresBackend, - DieselDeadpool, + DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool, ReusableConnectionPool, }, PrivilegedPostgresConfig, @@ -20,21 +17,18 @@ use diesel::{ query_builder::{Query, QueryFragment}, query_dsl::methods::LimitDsl, result::{ - ConnectionError, - ConnectionResult, + ConnectionError, ConnectionResult, Error::{self as DieselError, QueryBuilderError}, }, sql_types::{self, Timestamptz}, - Expression, - IntoSql, + Expression, IntoSql, }; use diesel_async::{ async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, - ManagerConfig, + AsyncDieselConnectionManager, ManagerConfig, }, scoped_futures::ScopedBoxFuture, AsyncConnection, @@ -48,16 +42,11 @@ use lemmy_utils::{ }; use rustls::{ client::danger::{ - DangerousClientConfigBuilder, - HandshakeSignatureValid, - ServerCertVerified, - ServerCertVerifier, + DangerousClientConfigBuilder, HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier, }, crypto::{self, verify_tls12_signature, verify_tls13_signature}, pki_types::{CertificateDer, ServerName, UnixTime}, - ClientConfig, - DigitallySignedStruct, - SignatureScheme, + ClientConfig, DigitallySignedStruct, SignatureScheme, }; use std::{ ops::{Deref, DerefMut}, @@ -560,11 +549,15 @@ pub async fn build_db_pool_for_tests( let mut async_wrapper: AsyncConnectionWrapper = AsyncConnectionWrapper::from(conn); - lemmy_db_schema_setup::run_with_connection( - lemmy_db_schema_setup::Options::default().run(), - &mut async_wrapper, - ) - .expect("run migrations"); + tokio::task::spawn_blocking(move || { + lemmy_db_schema_setup::run_with_connection( + lemmy_db_schema_setup::Options::default().run(), + &mut async_wrapper, + ) + .expect("run migrations") + }) + .await + .expect("task panicked"); None }) diff --git a/crates/db_schema_setup/Cargo.toml b/crates/db_schema_setup/Cargo.toml index 998c92f157..df85bc7004 100644 --- a/crates/db_schema_setup/Cargo.toml +++ b/crates/db_schema_setup/Cargo.toml @@ -28,7 +28,6 @@ tracing = { workspace = true } anyhow = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } diff = "0.1.13" itertools = { workspace = true } pathfinding = "4.14.0" diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index 14e27ec4a1..27cdf2d9cf 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -355,7 +355,6 @@ mod tests { }; use diesel_ltree::Ltree; use lemmy_utils::{error::LemmyResult, settings::SETTINGS}; - use serial_test::serial; // The number of migrations that should be run to set up some test data. // Currently, this includes migrations until // 2020-04-07-135912_add_user_community_apub_constraints, since there are some mandatory apub @@ -403,7 +402,6 @@ mod tests { const COMMENT2_AP_ID: &str = "https://fedi.example/comment/12346"; #[test] - #[serial] fn test_schema_setup() -> LemmyResult<()> { let o = Options::default(); let db_url = SETTINGS.get_database_url(); diff --git a/crates/db_views/post/Cargo.toml b/crates/db_views/post/Cargo.toml index ccaf2015b3..6f3f7a3a83 100644 --- a/crates/db_views/post/Cargo.toml +++ b/crates/db_views/post/Cargo.toml @@ -51,7 +51,6 @@ tracing = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } url = { workspace = true } diff --git a/crates/db_views/post/src/db_perf/mod.rs b/crates/db_views/post/src/db_perf/mod.rs index e2deadc8ae..c9921ae739 100644 --- a/crates/db_views/post/src/db_perf/mod.rs +++ b/crates/db_views/post/src/db_perf/mod.rs @@ -20,7 +20,6 @@ use lemmy_db_schema::{ }; use lemmy_db_schema_file::{enums::PostSortType, schema::post}; use lemmy_utils::error::LemmyResult; -use serial_test::serial; use std::{fmt::Display, num::NonZeroU32, str::FromStr}; use url::Url; @@ -44,7 +43,6 @@ fn get_option(suffix: &str, default: T) -> Result LemmyResult<()> { let args = CmdArgs { communities: get_option("COMMUNITIES", 3.try_into()?)?, diff --git a/crates/db_views/post/src/impls.rs b/crates/db_views/post/src/impls.rs index 33b4e29eb6..f07ec9d89e 100644 --- a/crates/db_views/post/src/impls.rs +++ b/crates/db_views/post/src/impls.rs @@ -620,7 +620,6 @@ mod tests { use lemmy_db_views_local_user::LocalUserView; use lemmy_utils::error::{LemmyErrorType, LemmyResult}; use pretty_assertions::assert_eq; - use serial_test::serial; use std::{ collections::HashSet, time::{Duration, Instant}, @@ -844,7 +843,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_with_person(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -903,7 +901,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_no_person(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -934,7 +931,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_block_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -957,7 +953,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_like(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1024,7 +1019,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn person_note(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1072,7 +1066,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_person_vote_totals(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1224,7 +1217,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_read_only(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1250,7 +1242,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn creator_info(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1373,7 +1364,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_person_language(data: &mut Data) -> LemmyResult<()> { const EL_POSTO: &str = "el posto"; @@ -1440,7 +1430,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_removed(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1474,7 +1463,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_deleted(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1513,7 +1501,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_hidden_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1550,7 +1537,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_COMMS: &str = "post on blocked instance"; const HOWARD_POST: &str = "howard post"; @@ -1638,7 +1624,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_USERS: &str = "post from blocked instance user"; const POST_TO_UNBLOCKED_COMM: &str = "post to unblocked comm"; @@ -1719,7 +1704,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn pagination_includes_each_post_once(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1826,7 +1810,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_hide_read(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1875,7 +1858,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_hide_hidden(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1921,7 +1903,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_hide_nsfw(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1966,7 +1947,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn local_only_instance(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2015,7 +1995,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_local_user_banned_from_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2057,7 +2036,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_local_user_not_banned_from_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2078,7 +2056,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_local_user_banned(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2123,7 +2100,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn speed_check(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2175,7 +2151,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2205,7 +2180,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_private_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2304,7 +2278,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listings_hide_media(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2364,7 +2337,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_with_blocked_keywords(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2437,7 +2409,6 @@ mod tests { } #[test_context(Data)] #[tokio::test] - #[serial] async fn post_tags_present(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2465,7 +2436,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_multi_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); diff --git a/crates/federate/Cargo.toml b/crates/federate/Cargo.toml index dd54e6ce0a..7288ec28df 100644 --- a/crates/federate/Cargo.toml +++ b/crates/federate/Cargo.toml @@ -47,7 +47,6 @@ moka.workspace = true tokio-util = "0.7.15" [dev-dependencies] -serial_test = { workspace = true } url.workspace = true actix-web.workspace = true tracing-test = "0.2.5" diff --git a/crates/federate/src/lib.rs b/crates/federate/src/lib.rs index 1a9318f9d8..50d2f40ebc 100644 --- a/crates/federate/src/lib.rs +++ b/crates/federate/src/lib.rs @@ -206,7 +206,6 @@ mod test { traits::Crud, }; use lemmy_utils::error::LemmyError; - use serial_test::serial; use std::{ collections::HashSet, sync::{Arc, Mutex}, @@ -274,7 +273,6 @@ mod test { /// Basic test with default params and only active/allowed instances #[tokio::test] - #[serial] async fn test_send_manager() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; @@ -290,7 +288,6 @@ mod test { /// Running with multiple processes should start correct workers #[tokio::test] - #[serial] async fn test_send_manager_processes() -> LemmyResult<()> { let active = Arc::new(Mutex::new(vec![])); let execute = |count, index, active: Arc>>| async move { @@ -315,7 +312,6 @@ mod test { /// Use blocklist, should not send to blocked instances #[tokio::test] - #[serial] async fn test_send_manager_blocked() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; @@ -341,7 +337,6 @@ mod test { /// Use allowlist, should only send to allowed instance #[tokio::test] - #[serial] async fn test_send_manager_allowed() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; @@ -365,7 +360,6 @@ mod test { /// Mark instance as dead, there should be no worker created for it #[tokio::test] - #[serial] async fn test_send_manager_dead() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index 926d910f0c..9cb4107617 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -469,7 +469,6 @@ mod test { use lemmy_db_schema_file::enums::ActorType; use lemmy_utils::error::LemmyResult; use serde_json::{json, Value}; - use serial_test::serial; use std::sync::{Arc, RwLock}; use test_context::{test_context, AsyncTestContext}; use tokio::{ @@ -575,7 +574,6 @@ mod test { #[test_context(Data)] #[tokio::test] #[traced_test] - #[serial] async fn test_stats(data: &mut Data) -> LemmyResult<()> { tracing::debug!("hello world"); @@ -615,7 +613,6 @@ mod test { #[test_context(Data)] #[tokio::test] #[traced_test] - #[serial] async fn test_send_40(data: &mut Data) -> LemmyResult<()> { tracing::debug!("hello world"); @@ -638,7 +635,6 @@ mod test { #[test_context(Data)] #[tokio::test] #[traced_test] - #[serial] /// this test sends 15 activities, waits and checks they have all been received, then sends 50, /// etc async fn test_send_15_20_30(data: &mut Data) -> LemmyResult<()> { @@ -667,7 +663,6 @@ mod test { #[test_context(Data)] #[tokio::test] - #[serial] async fn test_update_instance(data: &mut Data) -> LemmyResult<()> { let form = InstanceForm::new(data.instance.domain.clone()); Instance::update(&mut data.context.pool(), data.instance.id, form).await?; @@ -685,7 +680,6 @@ mod test { #[test_context(Data)] #[tokio::test] - #[serial] async fn test_errors(data: &mut Data) -> LemmyResult<()> { let form = InstanceForm::new(data.instance.domain.clone()); Instance::update(&mut data.context.pool(), data.instance.id, form).await?; diff --git a/crates/routes/Cargo.toml b/crates/routes/Cargo.toml index b69cd8babd..888d262948 100644 --- a/crates/routes/Cargo.toml +++ b/crates/routes/Cargo.toml @@ -61,4 +61,3 @@ diesel-uplete.workspace = true [dev-dependencies] pretty_assertions.workspace = true -serial_test.workspace = true diff --git a/crates/routes/src/middleware/session.rs b/crates/routes/src/middleware/session.rs index f57211da3d..7452ba73ab 100644 --- a/crates/routes/src/middleware/session.rs +++ b/crates/routes/src/middleware/session.rs @@ -112,10 +112,8 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_session_auth() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/routes/src/utils/scheduled_tasks.rs b/crates/routes/src/utils/scheduled_tasks.rs index 800ddc1358..248fee1603 100644 --- a/crates/routes/src/utils/scheduled_tasks.rs +++ b/crates/routes/src/utils/scheduled_tasks.rs @@ -698,7 +698,6 @@ mod tests { }; use pretty_assertions::assert_eq; use reqwest_middleware::ClientBuilder; - use serial_test::serial; #[tokio::test] async fn test_nodeinfo_lemmy_ml() -> LemmyResult<()> { @@ -721,7 +720,6 @@ mod tests { } #[tokio::test] - #[serial] async fn test_scheduled_tasks_no_errors() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let data = TestData::create(&mut context.pool()).await?; From 6534cbc22f56070bfe46544696f3422923717c1c Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 13 Aug 2025 01:43:13 +0300 Subject: [PATCH 16/40] fmt --- crates/db_schema/src/utils.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 05b006247b..fa28ed28a9 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -4,7 +4,10 @@ use crate::newtypes::DbUrl; use chrono::TimeDelta; use db_pool::{ r#async::{ - DatabasePool, DatabasePoolBuilderTrait, DieselAsyncPostgresBackend, DieselDeadpool, + DatabasePool, + DatabasePoolBuilderTrait, + DieselAsyncPostgresBackend, + DieselDeadpool, ReusableConnectionPool, }, PrivilegedPostgresConfig, @@ -17,18 +20,21 @@ use diesel::{ query_builder::{Query, QueryFragment}, query_dsl::methods::LimitDsl, result::{ - ConnectionError, ConnectionResult, + ConnectionError, + ConnectionResult, Error::{self as DieselError, QueryBuilderError}, }, sql_types::{self, Timestamptz}, - Expression, IntoSql, + Expression, + IntoSql, }; use diesel_async::{ async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, ManagerConfig, + AsyncDieselConnectionManager, + ManagerConfig, }, scoped_futures::ScopedBoxFuture, AsyncConnection, @@ -42,11 +48,16 @@ use lemmy_utils::{ }; use rustls::{ client::danger::{ - DangerousClientConfigBuilder, HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier, + DangerousClientConfigBuilder, + HandshakeSignatureValid, + ServerCertVerified, + ServerCertVerifier, }, crypto::{self, verify_tls12_signature, verify_tls13_signature}, pki_types::{CertificateDer, ServerName, UnixTime}, - ClientConfig, DigitallySignedStruct, SignatureScheme, + ClientConfig, + DigitallySignedStruct, + SignatureScheme, }; use std::{ ops::{Deref, DerefMut}, From 12037dfa4d2ae068b0dfc09b28d3c414a8a01a75 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 13 Aug 2025 01:47:19 +0300 Subject: [PATCH 17/40] excluding serial_test dep --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 41bb6bae5d..46bd839618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -187,7 +187,6 @@ uuid = { version = "1.17.0", features = ["serde"] } captcha = "1.0.0" anyhow = { version = "1.0.98", features = ["backtrace"] } diesel_ltree = "0.4.0" -serial_test = "3.2.0" tokio = { version = "1.45.1", features = ["full"] } regex = "1.11.1" diesel-derive-newtype = "2.1.2" From b8c283691fa40cda00f823f3a283c4af6be52384 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Wed, 13 Aug 2025 10:52:28 +0300 Subject: [PATCH 18/40] fix --- crates/apub_objects/src/utils/markdown_links.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/apub_objects/src/utils/markdown_links.rs b/crates/apub_objects/src/utils/markdown_links.rs index cd37b7e35d..796fd556d0 100644 --- a/crates/apub_objects/src/utils/markdown_links.rs +++ b/crates/apub_objects/src/utils/markdown_links.rs @@ -79,6 +79,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; + #[tokio::test] async fn test_markdown_rewrite_remote_links() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let data = TestData::create(&mut context.pool()).await?; From 3abdada19ca9cef4436d04fe88d1580a9ff01aa4 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 14 Oct 2025 01:23:11 +0300 Subject: [PATCH 19/40] add tokio-shared-rt library --- Cargo.lock | 55 ++++++++++++++++++++++--------- Cargo.toml | 1 + crates/db_schema/Cargo.toml | 2 +- crates/db_views/vote/Cargo.toml | 1 + crates/db_views/vote/src/impls.rs | 2 +- docker/docker-compose-test.yml | 10 ++++++ scripts/start_test_db.sh | 4 +-- scripts/test.sh | 2 +- 8 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 docker/docker-compose-test.yml diff --git a/Cargo.lock b/Cargo.lock index 10420c3dcd..16a4e321fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -768,7 +768,7 @@ dependencies = [ "cap-primitives", "cap-std", "io-lifetimes", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -785,7 +785,7 @@ dependencies = [ "maybe-owned", "rustix 1.0.7", "rustix-linux-procfs", - "windows-sys 0.52.0", + "windows-sys 0.59.0", "winx", ] @@ -1391,7 +1391,7 @@ dependencies = [ [[package]] name = "db-pool" version = "0.6.0" -source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-test#aba15f15f194ce4d0b7a313cf8f077b8b3bec81c" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021#39f31b40483257b6ce2adcc8fe632546cb6d45c8" dependencies = [ "async-trait", "bb8", @@ -1932,7 +1932,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2058,7 +2058,7 @@ checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78" dependencies = [ "cfg-if", "rustix 1.0.7", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2121,7 +2121,7 @@ checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a" dependencies = [ "io-lifetimes", "rustix 1.0.7", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2968,7 +2968,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2285ddfe3054097ef4b2fe909ef8c3bcd1ea52a8f0d274416caebeef39f04a65" dependencies = [ "io-lifetimes", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3826,6 +3826,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4028,7 +4029,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -5226,7 +5227,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5676,7 +5677,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5689,7 +5690,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6124,7 +6125,7 @@ dependencies = [ "cfg-if", "libc", "psm", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6318,7 +6319,7 @@ dependencies = [ "fd-lock", "io-lifetimes", "rustix 0.38.44", - "windows-sys 0.52.0", + "windows-sys 0.59.0", "winx", ] @@ -6344,7 +6345,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix 1.0.7", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6617,6 +6618,28 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-shared-rt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a6bb03ec682a0bb16ce93d19301abc5b98a0d7936477175a156a213dcc47d85" +dependencies = [ + "once_cell", + "tokio", + "tokio-shared-rt-macro", +] + +[[package]] +name = "tokio-shared-rt-macro" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe49a94e3a984b0d0ab97343dc3dcd52baae1ee13f005bfad39faea47d051dc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.102", +] + [[package]] name = "tokio-util" version = "0.7.15" @@ -7751,7 +7774,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -8063,7 +8086,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d" dependencies = [ "bitflags 2.9.1", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3edbbb0fc5..ad21b61055 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -188,6 +188,7 @@ captcha = "1.0.0" anyhow = { version = "1.0.98", features = ["backtrace"] } diesel_ltree = "0.4.0" tokio = { version = "1.45.1", features = ["full"] } +tokio-shared-rt = "0.1.0" regex = "1.11.1" diesel-derive-newtype = "2.1.2" diesel-derive-enum = { version = "2.1.0", features = ["postgres"] } diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 676417deff..57d67f1430 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -74,7 +74,7 @@ uuid.workspace = true i-love-jesus = { workspace = true, optional = true } derive-new.workspace = true moka = { workspace = true, optional = true } -db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test", features = [ +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021", features = [ "diesel-async-postgres", "diesel-async-deadpool", ] } diff --git a/crates/db_views/vote/Cargo.toml b/crates/db_views/vote/Cargo.toml index c4c48168af..237c0e05bd 100644 --- a/crates/db_views/vote/Cargo.toml +++ b/crates/db_views/vote/Cargo.toml @@ -39,4 +39,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/vote/src/impls.rs b/crates/db_views/vote/src/impls.rs index 70efd81114..10c183f13a 100644 --- a/crates/db_views/vote/src/impls.rs +++ b/crates/db_views/vote/src/impls.rs @@ -203,7 +203,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_and_comment_vote_views() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/docker/docker-compose-test.yml b/docker/docker-compose-test.yml new file mode 100644 index 0000000000..b7dfa66fef --- /dev/null +++ b/docker/docker-compose-test.yml @@ -0,0 +1,10 @@ +services: + postgres: + image: pgautoupgrade/pgautoupgrade:16-alpine + ports: + # use a different port so it doesn't conflict with potential postgres db running on the host + - "5433:5432" + environment: + - POSTGRES_USER=lemmy + - POSTGRES_PASSWORD=password + - POSTGRES_DB=lemmy \ No newline at end of file diff --git a/scripts/start_test_db.sh b/scripts/start_test_db.sh index ab9e2f2490..5c79c2b663 100644 --- a/scripts/start_test_db.sh +++ b/scripts/start_test_db.sh @@ -1,7 +1,7 @@ -export PGUSER=postgres +export PGUSER=lemmy export LEMMY_DATABASE_HOST=localhost export LEMMY_DATABASE_PORT=5433 export LEMMY_DATABASE_URL="postgresql://lemmy:password@$LEMMY_DATABASE_HOST:$LEMMY_DATABASE_PORT/lemmy" export PGDATABASE=lemmy -docker-compose -f docker/docker-compose.yml up -d postgres +docker-compose -f docker/docker-compose-test.yml up -d postgres diff --git a/scripts/test.sh b/scripts/test.sh index e36561978b..d7835034e4 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -24,4 +24,4 @@ fi # Add this to do printlns: -- --nocapture -docker-compose -f docker/docker-compose.yml down postgres +docker-compose -f docker/docker-compose-test.yml down From 355e6fe0f431a62e4634da5717cc6bf8fbd55f4e Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 14 Oct 2025 01:49:07 +0300 Subject: [PATCH 20/40] updated lock --- Cargo.lock | 73 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00783c1658..ee866140e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,6 +599,18 @@ version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" +[[package]] +name = "bb8" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89aabfae550a5c44b43ab941844ffcd2e993cb6900b342debf59e9ea74acdb8" +dependencies = [ + "async-trait", + "futures-util", + "parking_lot", + "tokio", +] + [[package]] name = "bcrypt" version = "0.17.1" @@ -1393,6 +1405,22 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "db-pool" +version = "0.6.0" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021#39f31b40483257b6ce2adcc8fe632546cb6d45c8" +dependencies = [ + "async-trait", + "bb8", + "deadpool", + "diesel", + "diesel-async", + "futures", + "parking_lot", + "tokio", + "uuid", +] + [[package]] name = "deadpool" version = "0.12.3" @@ -3170,7 +3198,6 @@ dependencies = [ "regex", "serde", "serde_json", - "serial_test", "sitemap-rs", "tokio", "totp-rs", @@ -3301,7 +3328,6 @@ dependencies = [ "reqwest-middleware", "serde", "serde_json", - "serial_test", "tokio", "tracing", "url", @@ -3403,7 +3429,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "stringreader", "tokio", "tracing", @@ -3434,7 +3459,6 @@ dependencies = [ "reqwest 0.12.23", "serde", "serde_json", - "serial_test", "test-context", "tokio", "tokio-util", @@ -3451,6 +3475,7 @@ dependencies = [ "activitypub_federation", "bcrypt", "chrono", + "db-pool", "deadpool", "derive-new", "diesel", @@ -3469,7 +3494,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "strum", "tokio", "tokio-postgres", @@ -3507,7 +3531,6 @@ dependencies = [ "lemmy_db_schema_file", "lemmy_utils", "pathfinding", - "serial_test", "tracing", "unified-diff", ] @@ -3529,7 +3552,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3548,7 +3570,6 @@ dependencies = [ "lemmy_utils", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -3567,7 +3588,6 @@ dependencies = [ "lemmy_utils", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3642,7 +3662,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3660,7 +3679,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3702,7 +3720,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3725,7 +3742,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3747,7 +3763,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3769,7 +3784,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3791,7 +3805,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "test-context", "tokio", "tracing", @@ -3837,7 +3850,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3857,7 +3869,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3881,7 +3892,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -3923,8 +3933,8 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -3979,7 +3989,6 @@ dependencies = [ "reqwest-middleware", "rss", "serde", - "serial_test", "tokio", "tracing", "url", @@ -6768,6 +6777,28 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-shared-rt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a6bb03ec682a0bb16ce93d19301abc5b98a0d7936477175a156a213dcc47d85" +dependencies = [ + "once_cell", + "tokio", + "tokio-shared-rt-macro", +] + +[[package]] +name = "tokio-shared-rt-macro" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe49a94e3a984b0d0ab97343dc3dcd52baae1ee13f005bfad39faea47d051dc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + [[package]] name = "tokio-util" version = "0.7.16" From f936ec368150efff6ee79bff586869e9dd091e17 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 14 Oct 2025 03:27:08 +0300 Subject: [PATCH 21/40] removing serial --- Cargo.lock | 42 ----------------------- Cargo.toml | 1 - crates/apub/apub/Cargo.toml | 1 - crates/db_schema/src/impls/comment.rs | 3 +- crates/db_views/notification/Cargo.toml | 1 - crates/db_views/notification/src/tests.rs | 7 ++-- crates/db_views/post/src/impls.rs | 4 +-- 7 files changed, 5 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee866140e9..a62ca3f08e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3358,7 +3358,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_json", - "serial_test", "tokio", "tracing", "url", @@ -3700,7 +3699,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -5877,15 +5875,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scc" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46e6f046b7fef48e2660c57ed794263155d713de679057f2d0c169bfc6e756cc" -dependencies = [ - "sdd", -] - [[package]] name = "schemars" version = "0.9.0" @@ -5941,12 +5930,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "sdd" -version = "3.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490dcfcbfef26be6800d11870ff2df8774fa6e86d047e3e8c8a76b25655e41ca" - [[package]] name = "select" version = "0.6.1" @@ -6070,31 +6053,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "serial_test" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9" -dependencies = [ - "futures", - "log", - "once_cell", - "parking_lot", - "scc", - "serial_test_derive", -] - -[[package]] -name = "serial_test_derive" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "sha1" version = "0.10.6" diff --git a/Cargo.toml b/Cargo.toml index 5c59e3faaf..7a1ed85086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,7 +175,6 @@ uuid = { version = "1.18.1", features = ["serde"] } captcha = "1.0.0" anyhow = { version = "1.0.99", features = ["backtrace"] } diesel_ltree = "0.4.0" -serial_test = "3.2.0" tokio = { version = "1.47.1", features = ["full"] } tokio-shared-rt = "0.1.0" regex = "1.11.2" diff --git a/crates/apub/apub/Cargo.toml b/crates/apub/apub/Cargo.toml index 1706afad02..50c606db4a 100644 --- a/crates/apub/apub/Cargo.toml +++ b/crates/apub/apub/Cargo.toml @@ -44,7 +44,6 @@ async-trait = { workspace = true } either = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } pretty_assertions = { workspace = true } [package.metadata.cargo-shear] diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 796fcd9d76..55928d604f 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -643,9 +643,8 @@ mod tests { } #[tokio::test] - #[serial] async fn test_update_children() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let inserted_instance = Instance::read_or_create(pool, "mydomain.tld".to_string()).await?; diff --git a/crates/db_views/notification/Cargo.toml b/crates/db_views/notification/Cargo.toml index 3625984f8d..6f67bbf6c7 100644 --- a/crates/db_views/notification/Cargo.toml +++ b/crates/db_views/notification/Cargo.toml @@ -45,6 +45,5 @@ serde_with = { workspace = true } chrono = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/notification/src/tests.rs b/crates/db_views/notification/src/tests.rs index 27192b231d..00c5df879f 100644 --- a/crates/db_views/notification/src/tests.rs +++ b/crates/db_views/notification/src/tests.rs @@ -16,7 +16,6 @@ use lemmy_db_schema::{ use lemmy_db_schema_file::enums::NotificationType; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; -use serial_test::serial; struct Data { alice: Person, @@ -41,9 +40,8 @@ async fn cleanup(data: Data, pool: &mut DbPool<'_>) -> LemmyResult<()> { } #[tokio::test] -#[serial] async fn test_private_message() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -73,9 +71,8 @@ async fn test_private_message() -> LemmyResult<()> { } #[tokio::test] -#[serial] async fn test_post() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/post/src/impls.rs b/crates/db_views/post/src/impls.rs index 172ab327c6..c5d20ea1a6 100644 --- a/crates/db_views/post/src/impls.rs +++ b/crates/db_views/post/src/impls.rs @@ -632,6 +632,7 @@ mod tests { }; use test_context::{test_context, AsyncTestContext}; use url::Url; + use lemmy_db_schema::utils::build_db_pool_for_tests; const POST_BY_BLOCKED_PERSON: &str = "post by blocked person"; const POST_BY_BOT: &str = "post by bot"; @@ -2122,7 +2123,6 @@ mod tests { #[test_context(Data)] #[tokio::test] - #[serial] async fn post_listing_creator_community_banned(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2229,7 +2229,7 @@ mod tests { #[test_context(Data)] #[tokio::test] async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Create a comment for a post From 9ab549a36973afb8c12424806c3b19196773541a Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 14 Oct 2025 04:32:18 +0300 Subject: [PATCH 22/40] post crate changes partial --- Cargo.lock | 1 + crates/db_views/post/Cargo.toml | 1 + crates/db_views/post/src/impls.rs | 138 +++++++++++++++--------------- 3 files changed, 69 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a62ca3f08e..5f3a575c0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3805,6 +3805,7 @@ dependencies = [ "serde_with", "test-context", "tokio", + "tokio-shared-rt", "tracing", "ts-rs", "url", diff --git a/crates/db_views/post/Cargo.toml b/crates/db_views/post/Cargo.toml index f00e3e93cb..59d416f6ba 100644 --- a/crates/db_views/post/Cargo.toml +++ b/crates/db_views/post/Cargo.toml @@ -49,6 +49,7 @@ tracing = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } url = { workspace = true } test-context = "0.4.1" diff --git a/crates/db_views/post/src/impls.rs b/crates/db_views/post/src/impls.rs index c5d20ea1a6..e4355885fa 100644 --- a/crates/db_views/post/src/impls.rs +++ b/crates/db_views/post/src/impls.rs @@ -620,7 +620,7 @@ mod tests { }, test_data::TestData, traits::{Bannable, Blockable, Crud, Followable, Likeable}, - utils::{build_db_pool, get_conn, ActualDbPool, DbPool}, + utils::{build_db_pool_for_tests, get_conn, ReusableDbPool, DbPool}, }; use lemmy_db_schema_file::enums::{CommunityFollowerState, CommunityVisibility, ListingType}; use lemmy_db_views_local_user::LocalUserView; @@ -632,7 +632,6 @@ mod tests { }; use test_context::{test_context, AsyncTestContext}; use url::Url; - use lemmy_db_schema::utils::build_db_pool_for_tests; const POST_BY_BLOCKED_PERSON: &str = "post by blocked person"; const POST_BY_BOT: &str = "post by bot"; @@ -645,7 +644,7 @@ mod tests { } struct Data { - pool: ActualDbPool, + pool: ReusableDbPool, instance: Instance, tegan: LocalUserView, john: LocalUserView, @@ -660,11 +659,8 @@ mod tests { } impl Data { - fn pool(&self) -> ActualDbPool { - self.pool.clone() - } pub fn pool2(&self) -> DbPool<'_> { - DbPool::Pool(&self.pool) + DbPool::ReusablePool(&self.pool) } fn default_post_query(&self) -> PostQuery<'_> { PostQuery { @@ -674,9 +670,9 @@ mod tests { } } - async fn setup() -> LemmyResult { - let actual_pool = build_db_pool()?; - let pool = &mut (&actual_pool).into(); + async fn test_setup() -> LemmyResult { + let test_pool = build_db_pool_for_tests().await; + let pool = &mut (&test_pool).into(); let data = TestData::create(pool).await?; let tegan_person_form = PersonInsertForm::test_form(data.instance.id, "tegan"); @@ -814,7 +810,7 @@ mod tests { }; Ok(Data { - pool: actual_pool, + pool: test_pool, instance: data.instance, tegan, john, @@ -844,7 +840,7 @@ mod tests { } impl AsyncTestContext for Data { async fn setup() -> Self { - Data::setup().await.expect("setup failed") + Data::test_setup().await.expect("setup failed") } async fn teardown(self) { Data::teardown(self).await.expect("teardown failed") @@ -852,9 +848,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_with_person(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let local_user_form = LocalUserUpdateForm { @@ -910,9 +906,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_no_person(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let read_post_listing_multiple_no_person = PostQuery { @@ -940,9 +936,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_block_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let community_block = CommunityBlockForm::new(data.community.id, data.tegan.person.id); @@ -962,9 +958,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_like(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let post_like_form = PostLikeForm::new(data.post.id, data.tegan.person.id, 1); @@ -1028,9 +1024,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn person_note(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let note_str = "Tegan loves cats."; @@ -1075,9 +1071,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_person_vote_totals(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Create a 2nd bot post, to do multiple votes @@ -1226,9 +1222,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_read_only(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Mark the bot post, then the tags post as read @@ -1251,9 +1247,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn creator_info(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let community_id = data.community.id; @@ -1373,11 +1369,11 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_person_language(data: &mut Data) -> LemmyResult<()> { const EL_POSTO: &str = "el posto"; - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let spanish_id = Language::read_id_from_code(pool, "es").await?; @@ -1439,9 +1435,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_removed(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Remove the post @@ -1472,9 +1468,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_deleted(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Delete the post @@ -1510,9 +1506,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_hidden_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); Community::update( @@ -1546,7 +1542,7 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_COMMS: &str = "post on blocked instance"; const HOWARD_POST: &str = "howard post"; @@ -1558,7 +1554,7 @@ mod tests { POST, ]; - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let blocked_instance_comms = @@ -1633,7 +1629,7 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_USERS: &str = "post from blocked instance user"; const POST_TO_UNBLOCKED_COMM: &str = "post to unblocked comm"; @@ -1645,7 +1641,7 @@ mod tests { POST, ]; - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let blocked_instance_persons = @@ -1713,9 +1709,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn pagination_includes_each_post_once(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let community_form = CommunityInsertForm::new( @@ -1819,9 +1815,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_read(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Make sure local user hides read posts @@ -1867,9 +1863,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_hidden(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Mark a post as hidden @@ -1912,9 +1908,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_nsfw(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Mark a post as nsfw @@ -1956,9 +1952,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn local_only_instance(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); Community::update( @@ -2004,9 +2000,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_local_user_banned_from_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Test that post view shows if local user is blocked from community @@ -2045,9 +2041,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_local_user_not_banned_from_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let post_view = PostView::read( @@ -2072,9 +2068,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_creator_banned(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let banned_person_form = PersonInsertForm::test_form(data.instance.id, "jill"); @@ -2122,9 +2118,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_creator_community_banned(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let banned_person_form = PersonInsertForm::test_form(data.instance.id, "jarvis"); @@ -2176,9 +2172,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn speed_check(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Make sure the post_view query is less than this time @@ -2227,7 +2223,7 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -2256,9 +2252,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_private_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Mark community as private @@ -2354,9 +2350,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_media(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // Make one post an image post @@ -2413,9 +2409,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_with_blocked_keywords(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let name_blocked = format!("post_{POST_KEYWORD_BLOCKED}"); @@ -2485,9 +2481,9 @@ mod tests { Ok(()) } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_tags_present(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let post_view = PostView::read( @@ -2512,9 +2508,9 @@ mod tests { } #[test_context(Data)] - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_listing_multi_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // create two more communities with one post each From 5ba2328840a659814ac23edde4c4f06bc31f65c2 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 3 Nov 2025 03:36:33 +0200 Subject: [PATCH 23/40] merge fixes --- Cargo.lock | 2 +- crates/db_views/community_follower_approval/Cargo.toml | 1 - crates/db_views/community_follower_approval/src/impls.rs | 3 --- crates/db_views/site/Cargo.toml | 1 - crates/db_views/site/src/impls.rs | 2 -- 5 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d60eac4ff..8063e363c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3584,6 +3584,7 @@ dependencies = [ "lemmy_utils", "serde", "serde_with", + "tokio", "ts-rs", ] @@ -3904,7 +3905,6 @@ dependencies = [ "lemmy_utils", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", diff --git a/crates/db_views/community_follower_approval/Cargo.toml b/crates/db_views/community_follower_approval/Cargo.toml index 2f80d3cad2..1d4a1bb69a 100644 --- a/crates/db_views/community_follower_approval/Cargo.toml +++ b/crates/db_views/community_follower_approval/Cargo.toml @@ -38,5 +38,4 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/community_follower_approval/src/impls.rs b/crates/db_views/community_follower_approval/src/impls.rs index 7bbb022abd..3e2a3e94d1 100644 --- a/crates/db_views/community_follower_approval/src/impls.rs +++ b/crates/db_views/community_follower_approval/src/impls.rs @@ -239,10 +239,8 @@ mod tests { utils::build_db_pool_for_tests, }; use lemmy_db_schema_file::enums::CommunityVisibility; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_has_followers_from_instance() -> LemmyResult<()> { let pool = &build_db_pool_for_tests(); let pool = &mut pool.into(); @@ -311,7 +309,6 @@ mod tests { } #[tokio::test] - #[serial] async fn test_pending_followers() -> LemmyResult<()> { let pool = &build_db_pool_for_tests(); let pool = &mut pool.into(); diff --git a/crates/db_views/site/Cargo.toml b/crates/db_views/site/Cargo.toml index 0b60ad99ab..54716b5364 100644 --- a/crates/db_views/site/Cargo.toml +++ b/crates/db_views/site/Cargo.toml @@ -59,5 +59,4 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] -serial_test = { workspace = true } tokio = { workspace = true } diff --git a/crates/db_views/site/src/impls.rs b/crates/db_views/site/src/impls.rs index 5342dd309e..a3efc78759 100644 --- a/crates/db_views/site/src/impls.rs +++ b/crates/db_views/site/src/impls.rs @@ -238,10 +238,8 @@ mod tests { utils::build_db_pool_for_tests, }; use lemmy_utils::error::LemmyResult; - use serial_test::serial; #[tokio::test] - #[serial] async fn test_instance_list() -> LemmyResult<()> { let pool = &build_db_pool_for_tests(); let pool = &mut pool.into(); From 8f9d819bd2b6f23eba77a76871fa6c73c63fde3e Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 3 Nov 2025 04:03:08 +0200 Subject: [PATCH 24/40] full access to r schema in tests --- crates/db_schema_setup/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/db_schema_setup/src/lib.rs b/crates/db_schema_setup/src/lib.rs index 191d324592..07a5c33d1e 100644 --- a/crates/db_schema_setup/src/lib.rs +++ b/crates/db_schema_setup/src/lib.rs @@ -223,6 +223,10 @@ where conn.batch_execute("SELECT pg_advisory_lock(0);")?; options.print("Running Database migrations (This may take a long time)..."); + // Allowing usage of all functions in replaceable schema to all users for tests + #[cfg(test)] + conn.batch_execute("GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA r TO PUBLIC")?; + // Drop `r` schema, so migrations don't need to be made to work both with and without things in // it existing revert_replaceable_schema(conn)?; From 1d3c3d898d442b2098dead7d48bff55fa7aeffe6 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Sat, 15 Nov 2025 07:06:58 +0200 Subject: [PATCH 25/40] made it compile --- Cargo.lock | 438 ++++++++--------- crates/db_schema/Cargo.toml | 4 - crates/db_schema/src/utils.rs | 678 -------------------------- crates/diesel_utils/Cargo.toml | 5 +- crates/diesel_utils/src/connection.rs | 112 ++++- crates/email/translations | 2 +- 6 files changed, 323 insertions(+), 916 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06024d2dd2..9d32fafdfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,7 +149,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "actix-tls" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac453898d866cdbecdbc2334fe1738c747b4eba14a677261f2b768ba05329389" +checksum = "6176099de3f58fbddac916a7f8c6db297e021d706e7a6b99947785fee14abe9f" dependencies = [ "actix-rt", "actix-service", @@ -284,7 +284,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -430,22 +430,22 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.10" +version = "3.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -490,9 +490,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a89bce6054c720275ac2432fbba080a66a2106a44a1b804553930ca6909f4e0" +checksum = "93c1f86859c1af3d514fa19e8323147ff10ea98684e6c7b307912509f50e67b2" dependencies = [ "compression-codecs", "compression-core", @@ -520,7 +520,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -550,9 +550,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.14.1" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879b6c89592deb404ba4dc0ae6b58ffd1795c78991cbb5b8bc441c48a070440d" +checksum = "5932a7d9d28b0d2ea34c6b3779d35e3dd6f6345317c34e73438c4f1f29144151" dependencies = [ "aws-lc-sys", "zeroize", @@ -560,9 +560,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.32.3" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "107a4e9d9cab9963e04e84bb8dee0e25f2a987f9a8bad5ed054abd439caa8f8c" +checksum = "1826f2e4cfc2cd19ee53c42fbf68e2f81ec21108e0b7ecf6a71cf062137360fc" dependencies = [ "bindgen", "cc", @@ -622,6 +622,18 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" +[[package]] +name = "bb8" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89aabfae550a5c44b43ab941844ffcd2e993cb6900b342debf59e9ea74acdb8" +dependencies = [ + "async-trait", + "futures-util", + "parking_lot", + "tokio", +] + [[package]] name = "bcrypt" version = "0.17.1" @@ -661,7 +673,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -769,9 +781,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" [[package]] name = "bytestring" @@ -875,16 +887,16 @@ dependencies = [ "quote", "serde", "serde_json", - "syn 2.0.108", + "syn 2.0.110", "tempfile", "toml 0.9.8", ] [[package]] name = "cc" -version = "1.2.44" +version = "1.2.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3" +checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36" dependencies = [ "find-msvc-tools", "jobserver", @@ -1006,7 +1018,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1080,9 +1092,9 @@ dependencies = [ [[package]] name = "compression-codecs" -version = "0.4.31" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef8a506ec4b81c460798f572caead636d57d3d7e940f998160f52bd254bf2d23" +checksum = "680dc087785c5230f8e8843e2e57ac7c1c90488b6a91b88caa265410568f441b" dependencies = [ "compression-core", "flate2", @@ -1091,9 +1103,9 @@ dependencies = [ [[package]] name = "compression-core" -version = "0.4.29" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e47641d3deaf41fb1538ac1f54735925e275eaf3bf4d55c81b137fba797e5cbb" +checksum = "3a9b614a5787ef0c8802a55766480563cb3a93b435898c422ed2a359cf811582" [[package]] name = "concurrent-queue" @@ -1370,9 +1382,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", "typenum", @@ -1402,7 +1414,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1460,7 +1472,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1474,7 +1486,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1496,7 +1508,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core 0.20.11", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1507,7 +1519,7 @@ checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ "darling_core 0.21.3", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1524,6 +1536,22 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "db-pool" +version = "0.6.0" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021#517efb89c1ac4c98a7bf25d1719cc8e0061042f9" +dependencies = [ + "async-trait", + "bb8", + "deadpool", + "diesel", + "diesel-async", + "futures", + "parking_lot", + "tokio", + "uuid", +] + [[package]] name = "deadpool" version = "0.12.3" @@ -1554,7 +1582,7 @@ dependencies = [ "proc-macro2", "quote", "semver", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1578,7 +1606,7 @@ checksum = "8034092389675178f570469e6c3b0465d3d30b4505c294a6550db47f3c17ad18" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1610,7 +1638,7 @@ checksum = "2cdc8d50f426189eef89dac62fabfa0abb27d5cc008f25bf4156a0203325becc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1631,7 +1659,7 @@ dependencies = [ "darling 0.20.11", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1641,7 +1669,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1654,7 +1682,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1674,7 +1702,7 @@ checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "unicode-xid", ] @@ -1706,9 +1734,9 @@ dependencies = [ [[package]] name = "diesel-async" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c69eded9cb72c7e112505caec23da00149d4dd49f4c96b3c83b2b63f0aa3da5f" +checksum = "13096fb8dae53f2d411c4b523bec85f45552ed3044a2ab4d85fb2092d9cb4f34" dependencies = [ "deadpool", "diesel", @@ -1728,7 +1756,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1739,7 +1767,7 @@ checksum = "d5adf688c584fe33726ce0e2898f608a2a92578ac94a4a92fcecf73214fe0716" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1762,7 +1790,7 @@ dependencies = [ "dsl_auto_type", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1792,7 +1820,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe2444076b48641147115697648dc743c2c00b61adade0f01ce67133c7babe8c" dependencies = [ - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1871,7 +1899,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -1927,7 +1955,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -2079,7 +2107,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -2195,7 +2223,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -2276,9 +2304,9 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "find-msvc-tools" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" +checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" [[package]] name = "flagset" @@ -2407,7 +2435,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -2442,9 +2470,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.9" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -2512,7 +2540,7 @@ checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -2656,9 +2684,9 @@ dependencies = [ [[package]] name = "html2text" -version = "0.16.0" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef65fbb577b8015aad4347acceb438da6793bdc9834944c3dfb6ad24dbef849" +checksum = "8ec3405a4163878f29357e1156eacd5c9d72803b62925f190c865d1cae8105d5" dependencies = [ "html5ever 0.35.0", "tendril", @@ -2691,7 +2719,7 @@ dependencies = [ "markup5ever 0.12.1", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -2825,9 +2853,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3aa54a13a0dfe7fbe3a59e0c76093041720fdc77b110cc0fc260fafb4dc51e" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" dependencies = [ "atomic-waker", "bytes", @@ -2865,9 +2893,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" dependencies = [ "http 1.3.1", - "hyper 1.7.0", + "hyper 1.8.1", "hyper-util", - "rustls 0.23.34", + "rustls 0.23.35", "rustls-pki-types", "tokio", "tokio-rustls 0.26.4", @@ -2877,9 +2905,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c6995591a8f1380fcb4ba966a252a4b29188d51d2b89e3a252f5305be65aea8" +checksum = "52e9a2a24dc5c6821e71a7030e1e14b7b632acac55c40e9d2e082c621261bb56" dependencies = [ "base64 0.22.1", "bytes", @@ -2888,7 +2916,7 @@ dependencies = [ "futures-util", "http 1.3.1", "http-body 1.0.1", - "hyper 1.7.0", + "hyper 1.8.1", "ipnet", "libc", "percent-encoding", @@ -2917,7 +2945,7 @@ checksum = "6708c2296b2e4d9e3451a7fda5e45b639272e6cfd8b44fe9350a66888c7c8dd2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -3181,9 +3209,9 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "iri-string" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc5ebe9c3a1a7a5127f920a418f7585e9e758e911d0466ed004f393b0e380b2" +checksum = "4f867b9d1d896b67beb18518eda36fdb77a32ea590de864f1325b294a6d14397" dependencies = [ "memchr", "serde", @@ -3367,7 +3395,6 @@ dependencies = [ "regex", "serde", "serde_json", - "serial_test", "sitemap-rs", "tokio", "totp-rs", @@ -3553,7 +3580,6 @@ dependencies = [ "reqwest-middleware", "serde", "serde_json", - "serial_test", "tokio", "tracing", "url", @@ -3587,7 +3613,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_json", - "serial_test", "tokio", "tracing", "url", @@ -3657,7 +3682,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "stringreader", "tokio", "tracing", @@ -3689,7 +3713,6 @@ dependencies = [ "reqwest 0.12.24", "serde", "serde_json", - "serial_test", "test-context", "tokio", "tokio-util", @@ -3741,7 +3764,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serial_test", "strum 0.27.2", "tokio", "ts-rs", @@ -3805,7 +3827,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3824,7 +3845,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -3843,6 +3863,7 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", + "tokio", "ts-rs", ] @@ -3859,7 +3880,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3926,7 +3946,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3956,7 +3975,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -3981,7 +3999,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4011,7 +4028,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4035,7 +4051,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4058,7 +4073,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4081,7 +4095,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4103,9 +4116,9 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "test-context", "tokio", + "tokio-shared-rt", "tracing", "ts-rs", "url", @@ -4139,7 +4152,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4161,7 +4173,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", ] @@ -4194,7 +4205,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -4222,7 +4232,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "serial_test", "tokio", "ts-rs", "url", @@ -4242,8 +4251,8 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "serial_test", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4254,6 +4263,7 @@ dependencies = [ "activitypub_federation", "anyhow", "chrono", + "db-pool", "deadpool", "diesel", "diesel-async", @@ -4268,9 +4278,8 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "pathfinding", "pretty_assertions", - "rustls 0.23.34", + "rustls 0.23.35", "serde", - "serial_test", "tokio", "tokio-postgres", "tokio-postgres-rustls", @@ -4333,7 +4342,6 @@ dependencies = [ "reqwest-middleware", "rss", "serde", - "serial_test", "tokio", "tracing", "url", @@ -4362,7 +4370,7 @@ dependencies = [ "mimalloc", "reqwest-middleware", "reqwest-tracing", - "rustls 0.23.34", + "rustls 0.23.35", "serde_json", "tokio", "tracing", @@ -4445,7 +4453,7 @@ dependencies = [ "nom 8.0.0", "percent-encoding", "quoted_printable", - "rustls 0.23.34", + "rustls 0.23.35", "socket2 0.6.1", "tokio", "tokio-rustls 0.26.4", @@ -4612,7 +4620,7 @@ dependencies = [ "manyhow-macros", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -4767,7 +4775,7 @@ checksum = "ac84fd3f360fcc43dc5f5d186f02a94192761a080e8bc58621ad4d12296a58cf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -4924,7 +4932,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -5006,9 +5014,9 @@ dependencies = [ [[package]] name = "num-bigint-dig" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c79c15c05d4bf82b6f5ef163104cc81a760d8e874d38ac50ab67c8877b647b" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" dependencies = [ "lazy_static", "libm", @@ -5318,7 +5326,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -5368,7 +5376,7 @@ checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07" dependencies = [ "base64 0.22.1", "indexmap 2.12.0", - "quick-xml 0.38.3", + "quick-xml 0.38.4", "serde", "time", ] @@ -5517,7 +5525,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -5616,7 +5624,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -5652,9 +5660,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.38.3" +version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" +checksum = "b66c2058c55a409d601666cffe35f04333cf1013010882cec174a7467cd4e21c" dependencies = [ "memchr", ] @@ -5671,7 +5679,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.23.34", + "rustls 0.23.35", "socket2 0.6.1", "thiserror 2.0.17", "tokio", @@ -5691,7 +5699,7 @@ dependencies = [ "rand 0.9.2", "ring", "rustc-hash", - "rustls 0.23.34", + "rustls 0.23.35", "rustls-pki-types", "slab", "thiserror 2.0.17", @@ -5716,9 +5724,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.41" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] @@ -5822,7 +5830,7 @@ checksum = "f2a62d85ed81ca5305dc544bd42c8804c5060b78ffa5ad3c64b0fb6a8c13d062" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -5862,7 +5870,7 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -5938,7 +5946,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls 0.21.12", - "rustls-pemfile 1.0.4", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", @@ -5970,7 +5978,7 @@ dependencies = [ "http 1.3.1", "http-body 1.0.1", "http-body-util", - "hyper 1.7.0", + "hyper 1.8.1", "hyper-rustls 0.27.7", "hyper-util", "js-sys", @@ -5978,7 +5986,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls 0.23.34", + "rustls 0.23.35", "rustls-pki-types", "serde", "serde_json", @@ -6106,9 +6114,9 @@ checksum = "2f8c01b9158de3aa5a7ac041a41c0e854d7adc3e473e7d7e2143eb5432bc5ba2" [[package]] name = "rsa" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b" +checksum = "40a0376c50d0358279d9d643e4bf7b7be212f1f4ff1da9070a7b54d22ef75c88" dependencies = [ "const-oid", "digest", @@ -6207,9 +6215,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.34" +version = "0.23.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9586e9ee2b4f8fab52a0048ca7334d7024eef48e2cb9407e3497bb7cab7fa7" +checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" dependencies = [ "aws-lc-rs", "log", @@ -6230,15 +6238,6 @@ dependencies = [ "base64 0.21.7", ] -[[package]] -name = "rustls-pemfile" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "rustls-pki-types" version = "1.13.0" @@ -6292,15 +6291,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scc" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46e6f046b7fef48e2660c57ed794263155d713de679057f2d0c169bfc6e756cc" -dependencies = [ - "sdd", -] - [[package]] name = "schemars" version = "0.9.0" @@ -6315,9 +6305,9 @@ dependencies = [ [[package]] name = "schemars" -version = "1.0.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1317c3bf3e7df961da95b0a56a172a02abead31276215a0497241a7624b487ce" +checksum = "9558e172d4e8533736ba97870c4b2cd63f84b382a3d6eb063da41b91cce17289" dependencies = [ "dyn-clone", "ref-cast", @@ -6350,12 +6340,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "sdd" -version = "3.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490dcfcbfef26be6800d11870ff2df8774fa6e86d047e3e8c8a76b25655e41ca" - [[package]] name = "sec1" version = "0.7.3" @@ -6414,7 +6398,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -6463,9 +6447,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.15.1" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa66c845eee442168b2c8134fec70ac50dc20e760769c8ba0ad1319ca1959b04" +checksum = "10574371d41b0d9b2cff89418eda27da52bcaff2cc8741db26382a77c29131f1" dependencies = [ "base64 0.22.1", "chrono", @@ -6473,7 +6457,7 @@ dependencies = [ "indexmap 1.9.3", "indexmap 2.12.0", "schemars 0.9.0", - "schemars 1.0.5", + "schemars 1.1.0", "serde_core", "serde_json", "serde_with_macros", @@ -6482,39 +6466,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.15.1" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91a903660542fced4e99881aa481bdbaec1634568ee02e0b8bd57c64cb38955" +checksum = "08a72d8216842fdd57820dc78d840bef99248e35fb2554ff923319e60f2d686b" dependencies = [ "darling 0.21.3", "proc-macro2", "quote", - "syn 2.0.108", -] - -[[package]] -name = "serial_test" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9" -dependencies = [ - "futures", - "log", - "once_cell", - "parking_lot", - "scc", - "serial_test_derive", -] - -[[package]] -name = "serial_test_derive" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -6645,7 +6604,7 @@ checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -6797,7 +6756,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -6809,7 +6768,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -6831,9 +6790,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.108" +version = "2.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" +checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" dependencies = [ "proc-macro2", "quote", @@ -6863,7 +6822,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -6977,9 +6936,9 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" [[package]] name = "test-context" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06694b7c4c2306101e4bcd025be1076f37e6f8206d1baf925f68e3a69c99e4e" +checksum = "7d94db16dc1c321805ce55f286c4023fa58a2c9c742568f95c5cfe2e95d250d7" dependencies = [ "futures", "test-context-macros", @@ -6987,13 +6946,13 @@ dependencies = [ [[package]] name = "test-context-macros" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aa907f7fbdf63b6a9776e8647c50012e43f9bb817179f26fda81b38e6e1e3f7" +checksum = "aabcca9d2cad192cfe258cd3562b7584516191a5c9b6a0002a6bb8b75ee7d21d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7022,7 +6981,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7033,7 +6992,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7125,7 +7084,7 @@ checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7153,7 +7112,7 @@ checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7190,7 +7149,7 @@ checksum = "27d684bad428a0f2481f42241f821db42c54e2dc81d8c00db8536c506b0a0144" dependencies = [ "const-oid", "ring", - "rustls 0.23.34", + "rustls 0.23.35", "tokio", "tokio-postgres", "tokio-rustls 0.26.4", @@ -7213,10 +7172,32 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" dependencies = [ - "rustls 0.23.34", + "rustls 0.23.35", "tokio", ] +[[package]] +name = "tokio-shared-rt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a6bb03ec682a0bb16ce93d19301abc5b98a0d7936477175a156a213dcc47d85" +dependencies = [ + "once_cell", + "tokio", + "tokio-shared-rt-macro", +] + +[[package]] +name = "tokio-shared-rt-macro" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe49a94e3a984b0d0ab97343dc3dcd52baae1ee13f005bfad39faea47d051dc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.110", +] + [[package]] name = "tokio-util" version = "0.7.17" @@ -7416,7 +7397,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7489,7 +7470,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04659ddb06c87d233c566112c1c9c5b9e98256d9af50ec3bc9c8327f873a7568" dependencies = [ "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7500,7 +7481,7 @@ checksum = "70977707304198400eb4835a78f6a9f928bf41bba420deb8fdb175cd965d77a7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7529,7 +7510,7 @@ checksum = "ee6ff59666c9cbaec3533964505d39154dc4e0a56151fdea30a09ed0301f62e2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "termcolor", ] @@ -7556,7 +7537,7 @@ checksum = "f9534daa9fd3ed0bd911d462a37f172228077e7abf18c18a5f67199d959205f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -7639,16 +7620,15 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "3.1.2" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ba1025f18a4a3fc3e9b48c868e9beb4f24f4b4b1a325bada26bd4119f46537" +checksum = "d39cb1dbab692d82a977c0392ffac19e188bd9186a9f32806f0aaa859d75585a" dependencies = [ "base64 0.22.1", "flate2", "log", "percent-encoding", - "rustls 0.23.34", - "rustls-pemfile 2.2.0", + "rustls 0.23.35", "rustls-pki-types", "ureq-proto", "utf-8", @@ -7849,7 +7829,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "wasm-bindgen-shared", ] @@ -7874,12 +7854,12 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.240.0" +version = "0.241.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06d642d8c5ecc083aafe9ceb32809276a304547a3a6eeecceb5d8152598bc71f" +checksum = "e01164c9dda68301e34fdae536c23ed6fe90ce6d97213ccc171eebbd3d02d6b8" dependencies = [ "leb128fmt", - "wasmparser 0.240.0", + "wasmparser 0.241.2", ] [[package]] @@ -7910,9 +7890,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.240.0" +version = "0.241.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b722dcf61e0ea47440b53ff83ccb5df8efec57a69d150e4f24882e4eba7e24a4" +checksum = "46d90019b1afd4b808c263e428de644f3003691f243387d30d673211ee0cb8e8" dependencies = [ "bitflags 2.10.0", "indexmap 2.12.0", @@ -8018,7 +7998,7 @@ dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "wasmtime-component-util", "wasmtime-wit-bindgen", "wit-parser", @@ -8131,7 +8111,7 @@ checksum = "dd2fe69d04986a12fc759d2e79494100d600adcb3bb79e63dedfc8e6bb2ab03e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -8174,24 +8154,24 @@ dependencies = [ [[package]] name = "wast" -version = "240.0.0" +version = "241.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0efe1c93db4ac562b9733e3dca19ed7fc878dba29aef22245acf84f13da4a19" +checksum = "63f66e07e2ddf531fef6344dbf94d112df7c2f23ed6ffb10962e711500b8d816" dependencies = [ "bumpalo", "leb128fmt", "memchr", "unicode-width", - "wasm-encoder 0.240.0", + "wasm-encoder 0.241.2", ] [[package]] name = "wat" -version = "1.240.0" +version = "1.241.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec9b6eab7ecd4d639d78515e9ea491c9bacf494aa5eda10823bd35992cf8c1e" +checksum = "45f923705c40830af909c5dec2352ec2821202e4a66008194585e1917458a26d" dependencies = [ - "wast 240.0.0", + "wast 241.0.2", ] [[package]] @@ -8307,7 +8287,7 @@ dependencies = [ "proc-macro2", "quote", "shellexpand", - "syn 2.0.108", + "syn 2.0.110", "witx", ] @@ -8319,7 +8299,7 @@ checksum = "ceac9f94f22ccc0485aeab08187b9f211d1993aaf0ed6eeb8aed43314f6e717c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "wiggle-generate", ] @@ -8393,7 +8373,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -8404,7 +8384,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -8807,7 +8787,7 @@ checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "synstructure", ] @@ -8828,7 +8808,7 @@ checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -8848,7 +8828,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", "synstructure", ] @@ -8869,7 +8849,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] @@ -8902,7 +8882,7 @@ checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.108", + "syn 2.0.110", ] [[package]] diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 77ece963ad..c6d4fb8d95 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -62,10 +62,6 @@ uuid.workspace = true i-love-jesus = { workspace = true, optional = true } derive-new.workspace = true moka = { workspace = true, optional = true } -db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021", features = [ - "diesel-async-postgres", - "diesel-async-deadpool", -] } [dev-dependencies] diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index a8357fb406..54fb605a0e 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -1,56 +1,10 @@ pub mod queries; use chrono::TimeDelta; -use db_pool::{ - r#async::{ - DatabasePool, - DatabasePoolBuilderTrait, - DieselAsyncPostgresBackend, - DieselDeadpool, - ReusableConnectionPool, - }, - PrivilegedPostgresConfig, -}; -use deadpool::{Runtime, Status}; -use diesel::{ - dsl, - helper_types::AsExprOf, - pg::{data_types::PgInterval, Pg}, - query_builder::{Query, QueryFragment}, - query_dsl::methods::LimitDsl, - result::{ - ConnectionError, - ConnectionResult, - Error::{self as DieselError, QueryBuilderError}, - }, - sql_types::{self, Timestamptz}, - Expression, - IntoSql, -}; -use diesel_async::{ - async_connection_wrapper::AsyncConnectionWrapper, - pg::AsyncPgConnection, - pooled_connection::{ - deadpool::{Hook, HookError, Object as PooledConnection, Pool}, - AsyncDieselConnectionManager, - ManagerConfig, - }, - scoped_futures::ScopedBoxFuture, - AsyncConnection, -}; -use futures_util::{future::BoxFuture, FutureExt}; -use i_love_jesus::{CursorKey, PaginatedQueryBuilder, SortDirection}; use lemmy_utils::{ error::{LemmyErrorType, LemmyResult}, settings::structs::Settings, }; -use std::{ - ops::{Deref, DerefMut}, - sync::Arc, - time::Duration, -}; -use tokio::sync::OnceCell; -use tracing::error; use url::Url; const FETCH_LIMIT_DEFAULT: i64 = 20; @@ -60,298 +14,6 @@ pub const SITEMAP_DAYS: TimeDelta = TimeDelta::days(31); pub const RANK_DEFAULT: f32 = 0.0001; pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*"; -pub type ActualDbPool = Pool; -pub type ReusableDbPool = - ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; - -/// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit -/// reborrowing. -/// -/// https://github.com/rust-lang/rfcs/issues/1403 -pub enum DbPool<'a> { - Pool(&'a ActualDbPool), - ReusablePool(&'a ReusableDbPool), - Conn(&'a mut AsyncPgConnection), -} - -pub enum DbConn<'a> { - Pool(PooledConnection), - Conn(&'a mut AsyncPgConnection), -} - -#[derive(Clone)] -pub enum GenericDbPool { - Actual(ActualDbPool), - Reusable(Arc), -} - -impl GenericDbPool { - pub fn status(&self) -> Status { - match self { - GenericDbPool::Actual(pool) => pool.status(), - GenericDbPool::Reusable(pool) => pool.status(), - } - } -} - -pub async fn get_conn<'a, 'b: 'a>(pool: &'a mut DbPool<'b>) -> Result, DieselError> { - Ok(match pool { - DbPool::Pool(pool) => DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?), - DbPool::Conn(conn) => DbConn::Conn(conn), - DbPool::ReusablePool(pool) => { - DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?) - } - }) -} - -impl DbConn<'_> { - pub async fn run_transaction<'a, R, F>(&mut self, callback: F) -> LemmyResult - where - F: for<'r> FnOnce(&'r mut AsyncPgConnection) -> ScopedBoxFuture<'a, 'r, LemmyResult> - + Send - + 'a, - R: Send + 'a, - { - self - .deref_mut() - .transaction::<_, LemmyError, _>(callback) - .await - } -} - -impl Deref for DbConn<'_> { - type Target = AsyncPgConnection; - - fn deref(&self) -> &Self::Target { - match self { - DbConn::Pool(conn) => conn.deref(), - DbConn::Conn(conn) => conn.deref(), - } - } -} - -impl DerefMut for DbConn<'_> { - fn deref_mut(&mut self) -> &mut Self::Target { - match self { - DbConn::Pool(conn) => conn.deref_mut(), - DbConn::Conn(conn) => conn.deref_mut(), - } - } -} - -// Allows functions that take `DbPool<'_>` to be called in a transaction by passing `&mut -// conn.into()` -impl<'a> From<&'a mut AsyncPgConnection> for DbPool<'a> { - fn from(value: &'a mut AsyncPgConnection) -> Self { - DbPool::Conn(value) - } -} - -impl<'a, 'b: 'a> From<&'a mut DbConn<'b>> for DbPool<'a> { - fn from(value: &'a mut DbConn<'b>) -> Self { - DbPool::Conn(value.deref_mut()) - } -} - -impl<'a> From<&'a ActualDbPool> for DbPool<'a> { - fn from(value: &'a ActualDbPool) -> Self { - DbPool::Pool(value) - } -} - -impl<'a> From<&'a ReusableDbPool> for DbPool<'a> { - fn from(value: &'a ReusableDbPool) -> Self { - DbPool::ReusablePool(value) - } -} - -impl<'a> From<&'a GenericDbPool> for DbPool<'a> { - fn from(value: &'a GenericDbPool) -> Self { - match value { - GenericDbPool::Actual(pool) => DbPool::Pool(pool), - GenericDbPool::Reusable(pool) => DbPool::ReusablePool(pool), - } - } -} - -/// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only -/// works when the `futures` crate is listed in `Cargo.toml`. -/// -/// `$pool` is the value given to each function. -/// -/// A `Result` is returned (not in a `Future`, so don't use `.await`). The `Ok` variant contains a -/// tuple with the values returned by the given functions. -/// -/// The functions run concurrently if `$pool` has the `DbPool::Pool` or `DbPool::ReusablePool` -/// variant. -#[macro_export] -macro_rules! try_join_with_pool { - ($pool:ident => ($($func:expr),+)) => {{ - // Check type - let _: &mut $crate::utils::DbPool<'_> = $pool; - - match $pool { - // Run concurrently with `try_join` - $crate::utils::DbPool::Pool(__pool) => ::futures_util::try_join!( - $(async { - let mut __dbpool = $crate::utils::DbPool::Pool(__pool); - ($func)(&mut __dbpool).await - }),+ - ), - // Run sequentially - $crate::utils::DbPool::Conn(__conn) => async { - Ok(($({ - let mut __dbpool = $crate::utils::DbPool::Conn(__conn); - // `?` prevents the error type from being inferred in an `async` block, so `match` is used instead - match ($func)(&mut __dbpool).await { - ::core::result::Result::Ok(__v) => __v, - ::core::result::Result::Err(__v) => return ::core::result::Result::Err(__v), - } - }),+)) - }.await, - // Run concurrently with `try_join` - $crate::utils::DbPool::ReusablePool(__pool) => ::futures_util::try_join!( - $(async { - let mut __dbpool = $crate::utils::DbPool::ReusablePool(__pool); - ($func)(&mut __dbpool).await - }),+ - ), - } - }}; -} - -/// Necessary to be able to use cursors with the lower SQL function -pub struct LowerKey(pub K); - -impl CursorKey for LowerKey -where - K: CursorKey, -{ - type SqlType = sql_types::Text; - type CursorValue = functions::lower; - type SqlValue = functions::lower; - - fn get_cursor_value(cursor: &C) -> Self::CursorValue { - functions::lower(K::get_cursor_value(cursor)) - } - - fn get_sql_value() -> Self::SqlValue { - functions::lower(K::get_sql_value()) - } -} - -/// Necessary to be able to use cursors with the subpath SQL function -pub struct Subpath(pub K); - -impl CursorKey for Subpath -where - K: CursorKey, -{ - type SqlType = diesel_ltree::sql_types::Ltree; - type CursorValue = diesel_ltree::subpath; - type SqlValue = diesel_ltree::subpath; - - fn get_cursor_value(cursor: &C) -> Self::CursorValue { - diesel_ltree::subpath(K::get_cursor_value(cursor), 0, -1) - } - - fn get_sql_value() -> Self::SqlValue { - diesel_ltree::subpath(K::get_sql_value(), 0, -1) - } -} - -pub struct CoalesceKey(pub A, pub B); - -impl CursorKey for CoalesceKey -where - A: CursorKey>, - B: CursorKey, -{ - type SqlType = B::SqlType; - type CursorValue = functions::coalesce; - type SqlValue = functions::coalesce; - - fn get_cursor_value(cursor: &C) -> Self::CursorValue { - // TODO: for slight optimization, use unwrap_or_else here (this requires the CursorKey trait to - // be changed to allow non-binded CursorValue) - functions::coalesce(A::get_cursor_value(cursor), B::get_cursor_value(cursor)) - } - - fn get_sql_value() -> Self::SqlValue { - functions::coalesce(A::get_sql_value(), B::get_sql_value()) - } -} - -/// Includes an SQL comment before `T`, which can be used to label auto_explain output -#[derive(QueryId)] -pub struct Commented { - comment: String, - inner: T, -} - -impl Commented { - pub fn new(inner: T) -> Self { - Commented { - comment: String::new(), - inner, - } - } - - /// Adds `text` to the comment if `condition` is true - fn text_if(mut self, text: &str, condition: bool) -> Self { - if condition { - if !self.comment.is_empty() { - self.comment.push_str(", "); - } - self.comment.push_str(text); - } - self - } - - /// Adds `text` to the comment - pub fn text(self, text: &str) -> Self { - self.text_if(text, true) - } -} - -impl Query for Commented { - type SqlType = T::SqlType; -} - -impl> QueryFragment for Commented { - fn walk_ast<'b>( - &'b self, - mut out: diesel::query_builder::AstPass<'_, 'b, Pg>, - ) -> Result<(), DieselError> { - for line in self.comment.lines() { - out.push_sql("\n-- "); - out.push_sql(line); - } - out.push_sql("\n"); - self.inner.walk_ast(out.reborrow()) - } -} - -impl LimitDsl for Commented { - type Output = Commented; - - fn limit(self, limit: i64) -> Self::Output { - Commented { - comment: self.comment, - inner: self.inner.limit(limit), - } - } -} - -pub fn fuzzy_search(q: &str) -> String { - let replaced = q - .replace('\\', "\\\\") - .replace('%', "\\%") - .replace('_', "\\_") - .replace(' ', "%"); - format!("%{replaced}%") -} - pub fn limit_fetch(limit: Option) -> LemmyResult { Ok(match limit { Some(limit) => limit_fetch_check(limit)?, @@ -367,308 +29,6 @@ pub fn limit_fetch_check(limit: i64) -> LemmyResult { } } -/// Takes an API optional text input, and converts it to an optional diesel DB update. -pub fn diesel_string_update(opt: Option<&str>) -> Option> { - match opt { - // An empty string is an erase - Some("") => Some(None), - Some(str) => Some(Some(str.into())), - None => None, - } -} - -/// Takes an API optional number, and converts it to an optional diesel DB update. Zero means erase. -pub fn diesel_opt_number_update(opt: Option) -> Option> { - match opt { - // Zero is an erase - Some(0) => Some(None), - Some(num) => Some(Some(num)), - None => None, - } -} - -/// Takes an API optional text input, and converts it to an optional diesel DB update (for non -/// nullable properties). -pub fn diesel_required_string_update(opt: Option<&str>) -> Option { - match opt { - // An empty string is no change - Some("") => None, - Some(str) => Some(str.into()), - None => None, - } -} - -/// Takes an optional API URL-type input, and converts it to an optional diesel DB update. -/// Also cleans the url params. -pub fn diesel_url_update(opt: Option<&str>) -> LemmyResult>> { - match opt { - // An empty string is an erase - Some("") => Ok(Some(None)), - Some(str_url) => Url::parse(str_url) - .map(|u| Some(Some(clean_url(&u).into()))) - .with_lemmy_type(LemmyErrorType::InvalidUrl), - None => Ok(None), - } -} - -/// Takes an optional API URL-type input, and converts it to an optional diesel DB update (for non -/// nullable properties). Also cleans the url params. -pub fn diesel_required_url_update(opt: Option<&str>) -> LemmyResult> { - match opt { - // An empty string is no change - Some("") => Ok(None), - Some(str_url) => Url::parse(str_url) - .map(|u| Some(clean_url(&u).into())) - .with_lemmy_type(LemmyErrorType::InvalidUrl), - None => Ok(None), - } -} - -/// Takes an optional API URL-type input, and converts it to an optional diesel DB create. -/// Also cleans the url params. -pub fn diesel_url_create(opt: Option<&str>) -> LemmyResult> { - match opt { - Some(str_url) => Url::parse(str_url) - .map(|u| Some(clean_url(&u).into())) - .with_lemmy_type(LemmyErrorType::InvalidUrl), - None => Ok(None), - } -} - -fn establish_connection(config: &str) -> BoxFuture<'_, ConnectionResult> { - let fut = async { - // We only support TLS with sslmode=require currently - let conn = if config.contains("sslmode=require") { - let rustls_config = DangerousClientConfigBuilder { - cfg: ClientConfig::builder(), - } - .with_custom_certificate_verifier(Arc::new(NoCertVerifier {})) - .with_no_client_auth(); - - let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config); - let (client, conn) = tokio_postgres::connect(config, tls) - .await - .map_err(|e| ConnectionError::BadConnection(e.to_string()))?; - tokio::spawn(async move { - if let Err(e) = conn.await { - error!("Database connection failed: {e}"); - } - }); - AsyncPgConnection::try_from(client).await? - } else { - AsyncPgConnection::establish(config).await? - }; - - Ok(conn) - }; - fut.boxed() -} - -#[derive(Debug)] -struct NoCertVerifier {} - -impl ServerCertVerifier for NoCertVerifier { - fn verify_server_cert( - &self, - _end_entity: &CertificateDer, - _intermediates: &[CertificateDer], - _server_name: &ServerName, - _ocsp: &[u8], - _now: UnixTime, - ) -> Result { - // Will verify all (even invalid) certs without any checks (sslmode=require) - Ok(ServerCertVerified::assertion()) - } - - fn verify_tls12_signature( - &self, - message: &[u8], - cert: &CertificateDer, - dss: &DigitallySignedStruct, - ) -> Result { - verify_tls12_signature( - message, - cert, - dss, - &crypto::ring::default_provider().signature_verification_algorithms, - ) - } - - fn verify_tls13_signature( - &self, - message: &[u8], - cert: &CertificateDer, - dss: &DigitallySignedStruct, - ) -> Result { - verify_tls13_signature( - message, - cert, - dss, - &crypto::ring::default_provider().signature_verification_algorithms, - ) - } - - fn supported_verify_schemes(&self) -> Vec { - crypto::ring::default_provider() - .signature_verification_algorithms - .supported_schemes() - } -} - -pub fn build_db_pool() -> LemmyResult { - let db_url = SETTINGS.get_database_url_with_options()?; - // diesel-async does not support any TLS connections out of the box, so we need to manually - // provide a setup function which handles creating the connection - let mut config = ManagerConfig::default(); - config.custom_setup = Box::new(establish_connection); - let manager = AsyncDieselConnectionManager::::new_with_config(&db_url, config); - let pool = Pool::builder(manager) - .max_size(SETTINGS.database.pool_size) - .runtime(Runtime::Tokio1) - // Limit connection age to prevent use of prepared statements that have query plans based on - // very old statistics - .pre_recycle(Hook::sync_fn(|_conn, metrics| { - // Preventing the first recycle can cause an infinite loop when trying to get a new connection - // from the pool - let conn_was_used = metrics.recycled.is_some(); - if metrics.age() > Duration::from_secs(3 * 24 * 60 * 60) && conn_was_used { - Err(HookError::Message("Connection is too old".into())) - } else { - Ok(()) - } - })) - .build()?; - - lemmy_db_schema_setup::run(lemmy_db_schema_setup::Options::default().run(), &db_url)?; - - Ok(pool) -} - -#[allow(clippy::expect_used)] -pub async fn build_db_pool_for_tests( -) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend> { - static POOL: OnceCell>> = - OnceCell::const_new(); - let db_pool = POOL - .get_or_init(|| async { - let conn_string = SETTINGS.get_database_url(); - - let db_url = Url::parse(conn_string.as_str()).expect("db url"); - - let config = PrivilegedPostgresConfig::new() - .host(db_url.host().expect("db host").to_string()) - .port(db_url.port().expect("db port")) - .username(db_url.username().to_string()) - .password(Some(db_url.password().expect("db password").to_string())); - - let backend = DieselAsyncPostgresBackend::new( - config, - |manager| Pool::builder(manager).max_size(SETTINGS.database.pool_size), - |manager| Pool::builder(manager).max_size(2), - None, - move |conn| { - Box::pin(async { - let mut async_wrapper: AsyncConnectionWrapper = - AsyncConnectionWrapper::from(conn); - - tokio::task::spawn_blocking(move || { - lemmy_db_schema_setup::run_with_connection( - lemmy_db_schema_setup::Options::default().run(), - &mut async_wrapper, - ) - .expect("run migrations") - }) - .await - .expect("task panicked"); - - None - }) - }, - ) - .await - .expect("diesel postgres backend"); - - backend - .create_database_pool() - .await - .expect("create db pool") - }) - .await; - - db_pool.pull_immutable().await -} - -pub mod functions { - use diesel::sql_types::{Int4, Text, Timestamptz}; - - define_sql_function! { - #[sql_name = "r.hot_rank"] - fn hot_rank(score: Int4, time: Timestamptz) -> Float; - } - - define_sql_function! { - #[sql_name = "r.scaled_rank"] - fn scaled_rank(score: Int4, time: Timestamptz, interactions_month: Int4) -> Float; - } - - define_sql_function!(fn lower(x: Text) -> Text); - - define_sql_function!(fn random() -> Text); - - define_sql_function!(fn random_smallint() -> SmallInt); - - // really this function is variadic, this just adds the two-argument version - define_sql_function!(fn coalesce(x: diesel::sql_types::Nullable, y: T) -> T); - - define_sql_function! { - #[aggregate] - fn json_agg(obj: T) -> Json - } - - define_sql_function!(#[sql_name = "coalesce"] fn coalesce_2_nullable(x: diesel::sql_types::Nullable, y: diesel::sql_types::Nullable) -> diesel::sql_types::Nullable); - - define_sql_function!(#[sql_name = "coalesce"] fn coalesce_3_nullable(x: diesel::sql_types::Nullable, y: diesel::sql_types::Nullable, z: diesel::sql_types::Nullable) -> diesel::sql_types::Nullable); -} - -pub const DELETED_REPLACEMENT_TEXT: &str = "*Permanently Deleted*"; - -pub fn now() -> AsExprOf { - // https://github.com/diesel-rs/diesel/issues/1514 - diesel::dsl::now.into_sql::() -} - -pub fn seconds_to_pg_interval(seconds: i32) -> PgInterval { - PgInterval::from_microseconds(i64::from(seconds) * 1_000_000) -} - -/// Output of `IntoSql::into_sql` for a type that implements `AsRecord` -pub type AsRecordOutput = dsl::AsExprOf::SqlType>>; - -pub type ResultFuture<'a, T> = BoxFuture<'a, Result>; - -pub fn paginate( - query: Q, - sort_direction: SortDirection, - page_after: Option, - page_before_or_equal: Option, - page_back: Option, -) -> PaginatedQueryBuilder { - let mut query = PaginatedQueryBuilder::new(query, sort_direction); - - if page_back.unwrap_or_default() { - query = query - .before(page_after) - .after_or_equal(page_before_or_equal) - .limit_and_offset_from_end(); - } else { - query = query - .after(page_after) - .before_or_equal(page_before_or_equal); - } - - query -} - pub(crate) fn format_actor_url( name: &str, domain: &str, @@ -684,41 +44,3 @@ pub(crate) fn format_actor_url( }; Ok(Url::parse(&url)?) } - -#[cfg(test)] -mod tests { - use super::*; - use pretty_assertions::assert_eq; - - #[test] - fn test_fuzzy_search() { - let test = "This %is% _a_ fuzzy search"; - assert_eq!( - fuzzy_search(test), - "%This%\\%is\\%%\\_a\\_%fuzzy%search%".to_string() - ); - } - - #[test] - fn test_diesel_option_overwrite() { - assert_eq!(diesel_string_update(None), None); - assert_eq!(diesel_string_update(Some("")), Some(None)); - assert_eq!( - diesel_string_update(Some("test")), - Some(Some("test".to_string())) - ); - } - - #[test] - fn test_diesel_option_overwrite_to_url() -> LemmyResult<()> { - assert!(matches!(diesel_url_update(None), Ok(None))); - assert!(matches!(diesel_url_update(Some("")), Ok(Some(None)))); - assert!(diesel_url_update(Some("invalid_url")).is_err()); - let example_url = "https://example.com"; - assert!(matches!( - diesel_url_update(Some(example_url)), - Ok(Some(Some(url))) if url == Url::parse(example_url)?.into() - )); - Ok(()) - } -} diff --git a/crates/diesel_utils/Cargo.toml b/crates/diesel_utils/Cargo.toml index 1a5971c55e..f0b66bb9c2 100644 --- a/crates/diesel_utils/Cargo.toml +++ b/crates/diesel_utils/Cargo.toml @@ -52,6 +52,10 @@ diesel-async = { workspace = true, features = [ "deadpool", "postgres", ], optional = true } +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021", features = [ + "diesel-async-postgres", + "diesel-async-deadpool", +] } diesel_ltree = { workspace = true, optional = true } tracing = { workspace = true, optional = true } deadpool = { version = "0.12.3", features = ["rt_tokio_1"], optional = true } @@ -65,7 +69,6 @@ i-love-jesus = { workspace = true, optional = true } lemmy_utils = { workspace = true, features = ["full"], optional = true } [dev-dependencies] -serial_test = { workspace = true } diff = "0.1.13" itertools = { workspace = true } pathfinding = "4.14.0" diff --git a/crates/diesel_utils/src/connection.rs b/crates/diesel_utils/src/connection.rs index 9025baf2fa..0029b9c84f 100644 --- a/crates/diesel_utils/src/connection.rs +++ b/crates/diesel_utils/src/connection.rs @@ -1,4 +1,14 @@ -use deadpool::Runtime; +use deadpool::{Runtime, Status}; +use db_pool::{ + r#async::{ + DatabasePool, + DatabasePoolBuilderTrait, + DieselAsyncPostgresBackend, + DieselDeadpool, + ReusableConnectionPool, + }, + PrivilegedPostgresConfig, +}; use diesel::result::{ ConnectionError, ConnectionResult, @@ -37,9 +47,15 @@ use std::{ sync::Arc, time::Duration, }; +use diesel_async::async_connection_wrapper::AsyncConnectionWrapper; +use tokio::sync::OnceCell; use tracing::error; +use url::Url; +use crate::schema_setup; pub type ActualDbPool = Pool; +pub type ReusableDbPool = +ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; /// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit /// reborrowing. @@ -47,6 +63,7 @@ pub type ActualDbPool = Pool; /// https://github.com/rust-lang/rfcs/issues/1403 pub enum DbPool<'a> { Pool(&'a ActualDbPool), + ReusablePool(&'a ReusableDbPool), Conn(&'a mut AsyncPgConnection), } @@ -55,10 +72,28 @@ pub enum DbConn<'a> { Conn(&'a mut AsyncPgConnection), } +#[derive(Clone)] +pub enum GenericDbPool { + Actual(ActualDbPool), + Reusable(Arc), +} + +impl GenericDbPool { + pub fn status(&self) -> Status { + match self { + GenericDbPool::Actual(pool) => pool.status(), + GenericDbPool::Reusable(pool) => pool.status(), + } + } +} + pub async fn get_conn<'a, 'b: 'a>(pool: &'a mut DbPool<'b>) -> Result, DieselError> { Ok(match pool { DbPool::Pool(pool) => DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?), DbPool::Conn(conn) => DbConn::Conn(conn), + DbPool::ReusablePool(pool) => { + DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?) + } }) } @@ -117,6 +152,21 @@ impl<'a> From<&'a ActualDbPool> for DbPool<'a> { } } +impl<'a> From<&'a ReusableDbPool> for DbPool<'a> { + fn from(value: &'a ReusableDbPool) -> Self { + DbPool::ReusablePool(value) + } +} + +impl<'a> From<&'a GenericDbPool> for DbPool<'a> { + fn from(value: &'a GenericDbPool) -> Self { + match value { + GenericDbPool::Actual(pool) => DbPool::Pool(pool), + GenericDbPool::Reusable(pool) => DbPool::ReusablePool(pool), + } + } +} + /// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only /// works when the `futures` crate is listed in `Cargo.toml`. /// @@ -151,6 +201,13 @@ macro_rules! try_join_with_pool { } }),+)) }.await, + // Run concurrently with `try_join` + $crate::connection::DbPool::ReusablePool(__pool) => ::futures_util::try_join!( + $(async { + let mut __dbpool = $crate::connection::DbPool::ReusablePool(__pool); + ($func)(&mut __dbpool).await + }),+ + ), } }}; } @@ -185,8 +242,57 @@ pub fn build_db_pool() -> LemmyResult { } #[allow(clippy::expect_used)] -pub fn build_db_pool_for_tests() -> ActualDbPool { - build_db_pool().expect("db pool missing") +pub async fn build_db_pool_for_tests( +) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend> { + static POOL: OnceCell>> = + OnceCell::const_new(); + let db_pool = POOL + .get_or_init(|| async { + let conn_string = SETTINGS.get_database_url(); + + let db_url = Url::parse(conn_string.as_str()).expect("db url"); + + let config = PrivilegedPostgresConfig::new() + .host(db_url.host().expect("db host").to_string()) + .port(db_url.port().expect("db port")) + .username(db_url.username().to_string()) + .password(Some(db_url.password().expect("db password").to_string())); + + let backend = DieselAsyncPostgresBackend::new( + config, + |manager| Pool::builder(manager).max_size(SETTINGS.database.pool_size), + |manager| Pool::builder(manager).max_size(2), + None, + move |conn| { + Box::pin(async { + let mut async_wrapper: AsyncConnectionWrapper = + AsyncConnectionWrapper::from(conn); + + tokio::task::spawn_blocking(move || { + schema_setup::run_with_connection( + schema_setup::Options::default().run(), + &mut async_wrapper, + ) + .expect("run migrations") + }) + .await + .expect("task panicked"); + + None + }) + }, + ) + .await + .expect("diesel postgres backend"); + + backend + .create_database_pool() + .await + .expect("create db pool") + }) + .await; + + db_pool.pull_immutable().await } fn establish_connection(config: &str) -> BoxFuture<'_, ConnectionResult> { diff --git a/crates/email/translations b/crates/email/translations index ecad71da90..95c1c4f6e4 160000 --- a/crates/email/translations +++ b/crates/email/translations @@ -1 +1 @@ -Subproject commit ecad71da90148aaad2ddea50e404b03025eff6e8 +Subproject commit 95c1c4f6e47876264a5f092e798592dee537bf04 From 35ac09072733aec08c2796f7489ee1e3afa8ecfd Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 17 Nov 2025 00:40:38 +0200 Subject: [PATCH 26/40] using db-pool version with superuser test user --- Cargo.lock | 2 +- crates/diesel_utils/Cargo.toml | 2 +- crates/diesel_utils/src/schema_setup/mod.rs | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d32fafdfc..6b2d1d34ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1539,7 +1539,7 @@ dependencies = [ [[package]] name = "db-pool" version = "0.6.0" -source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021#517efb89c1ac4c98a7bf25d1719cc8e0061042f9" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-test-superuser#abdee330bfffd21c4d9eae6a0aab4520f433290f" dependencies = [ "async-trait", "bb8", diff --git a/crates/diesel_utils/Cargo.toml b/crates/diesel_utils/Cargo.toml index f0b66bb9c2..51d796d65f 100644 --- a/crates/diesel_utils/Cargo.toml +++ b/crates/diesel_utils/Cargo.toml @@ -52,7 +52,7 @@ diesel-async = { workspace = true, features = [ "deadpool", "postgres", ], optional = true } -db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021", features = [ +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test-superuser", features = [ "diesel-async-postgres", "diesel-async-deadpool", ] } diff --git a/crates/diesel_utils/src/schema_setup/mod.rs b/crates/diesel_utils/src/schema_setup/mod.rs index bc480de4cd..49aabd240d 100644 --- a/crates/diesel_utils/src/schema_setup/mod.rs +++ b/crates/diesel_utils/src/schema_setup/mod.rs @@ -223,10 +223,6 @@ where conn.batch_execute("SELECT pg_advisory_lock(0);")?; options.print("Running Database migrations (This may take a long time)..."); - // Allowing usage of all functions in replaceable schema to all users for tests - #[cfg(test)] - conn.batch_execute("GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA r TO PUBLIC")?; - // Drop `r` schema, so migrations don't need to be made to work both with and without things in // it existing revert_replaceable_schema(conn)?; From 5d52b367d246d447926ab9276f331398031e2d7c Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 9 Dec 2025 02:26:31 +0200 Subject: [PATCH 27/40] PrivilegedPostgresConfig adapted to conn string containing options --- Cargo.lock | 21 +++++++++++---------- crates/diesel_utils/src/connection.rs | 5 +++-- crates/utils/src/settings/mod.rs | 13 ++++++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfe8ec99f7..5cca4f7cfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1538,7 +1538,7 @@ dependencies = [ [[package]] name = "db-pool" version = "0.6.0" -source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-test-superuser#abdee330bfffd21c4d9eae6a0aab4520f433290f" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-test-superuser#68d84b8477059821ef82ad0bda5762106d1623bf" dependencies = [ "async-trait", "bb8", @@ -1548,6 +1548,7 @@ dependencies = [ "futures", "parking_lot", "tokio", + "urlencoding", "uuid", ] @@ -2126,7 +2127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2892,7 +2893,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.6.1", + "socket2 0.5.10", "tokio", "tower-service", "tracing", @@ -4951,7 +4952,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5655,7 +5656,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls 0.23.35", - "socket2 0.6.1", + "socket2 0.5.10", "thiserror 2.0.17", "tokio", "tracing", @@ -5692,9 +5693,9 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.6.1", + "socket2 0.5.10", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.52.0", ] [[package]] @@ -6163,7 +6164,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6890,7 +6891,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.2", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -8324,7 +8325,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] diff --git a/crates/diesel_utils/src/connection.rs b/crates/diesel_utils/src/connection.rs index 0029b9c84f..29d4c78568 100644 --- a/crates/diesel_utils/src/connection.rs +++ b/crates/diesel_utils/src/connection.rs @@ -248,7 +248,7 @@ pub async fn build_db_pool_for_tests( OnceCell::const_new(); let db_pool = POOL .get_or_init(|| async { - let conn_string = SETTINGS.get_database_url(); + let conn_string = SETTINGS.get_database_url_with_options().unwrap(); let db_url = Url::parse(conn_string.as_str()).expect("db url"); @@ -256,7 +256,8 @@ pub async fn build_db_pool_for_tests( .host(db_url.host().expect("db host").to_string()) .port(db_url.port().expect("db port")) .username(db_url.username().to_string()) - .password(Some(db_url.password().expect("db password").to_string())); + .password(Some(db_url.password().expect("db password").to_string())) + .options(SETTINGS.get_lemmy_connection_options()); let backend = DieselAsyncPostgresBackend::new( config, diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index 82c838e983..43597b5022 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -87,15 +87,18 @@ impl Settings { .ok_or_else(|| anyhow!("images_disabled").into()) } + pub fn get_lemmy_connection_options(&self) -> Vec<(String, String)> { + Vec::from([("lemmy.protocol_and_hostname".to_string(), self.get_protocol_and_hostname().to_string())]) + } + /// Sets a few additional config options necessary for starting lemmy pub fn get_database_url_with_options(&self) -> LemmyResult { let mut url = Url::parse(&self.get_database_url())?; - // Set `lemmy.protocol_and_hostname` so triggers can use it - let lemmy_protocol_and_hostname_option = - "lemmy.protocol_and_hostname=".to_owned() + &self.get_protocol_and_hostname(); - let mut options = CONNECTION_OPTIONS.to_vec(); - options.push(&lemmy_protocol_and_hostname_option); + let mut options = CONNECTION_OPTIONS.iter().map(|s| s.to_string()).collect::>(); + for (k, v) in self.get_lemmy_connection_options() { + options.push(format!("{}={}", k, v)); + } // Create the connection uri portion let options_segments = options From 3d469ef8e6e1d4ba371ba0e7bafe140d2effc7e2 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 15 Dec 2025 21:30:06 +0200 Subject: [PATCH 28/40] tests are compiling --- .../community_follower_approval/src/impls.rs | 4 +-- crates/db_views/modlog/src/impls.rs | 10 ++---- crates/db_views/notification/src/tests.rs | 3 +- crates/db_views/post/src/test.rs | 33 ------------------- crates/db_views/report_combined/src/impls.rs | 3 +- crates/db_views/site/src/impls.rs | 2 +- 6 files changed, 8 insertions(+), 47 deletions(-) diff --git a/crates/db_views/community_follower_approval/src/impls.rs b/crates/db_views/community_follower_approval/src/impls.rs index 196608579b..4cbe0cbaf0 100644 --- a/crates/db_views/community_follower_approval/src/impls.rs +++ b/crates/db_views/community_follower_approval/src/impls.rs @@ -251,7 +251,7 @@ mod tests { #[tokio::test] async fn test_has_followers_from_instance() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // insert local community @@ -319,7 +319,7 @@ mod tests { #[tokio::test] async fn test_pending_followers() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // insert local community diff --git a/crates/db_views/modlog/src/impls.rs b/crates/db_views/modlog/src/impls.rs index 780443d1fd..924c613438 100644 --- a/crates/db_views/modlog/src/impls.rs +++ b/crates/db_views/modlog/src/impls.rs @@ -208,7 +208,6 @@ mod tests { }; use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - use serial_test::serial; struct Data { instance: Instance, @@ -288,9 +287,8 @@ mod tests { } #[tokio::test] - #[serial] async fn admin_types() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -438,9 +436,8 @@ mod tests { } #[tokio::test] - #[serial] async fn mod_types() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; @@ -769,9 +766,8 @@ mod tests { } #[tokio::test] - #[serial] async fn hide_modlog_names() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/notification/src/tests.rs b/crates/db_views/notification/src/tests.rs index ba39f39d9d..bc12f07ebd 100644 --- a/crates/db_views/notification/src/tests.rs +++ b/crates/db_views/notification/src/tests.rs @@ -145,9 +145,8 @@ async fn test_post() -> LemmyResult<()> { } #[tokio::test] -#[serial] async fn test_modlog() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/post/src/test.rs b/crates/db_views/post/src/test.rs index d644d8ed6e..a7b422a9dd 100644 --- a/crates/db_views/post/src/test.rs +++ b/crates/db_views/post/src/test.rs @@ -54,7 +54,6 @@ use lemmy_diesel_utils::{ }; use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use pretty_assertions::assert_eq; -use serial_test::serial; use std::{ collections::HashSet, time::{Duration, Instant}, @@ -280,7 +279,6 @@ impl AsyncTestContext for Data { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_with_person(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -340,7 +338,6 @@ async fn post_listing_with_person(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_no_person(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -373,7 +370,6 @@ async fn post_listing_no_person(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_block_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -396,7 +392,6 @@ async fn post_listing_block_community(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_like(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -464,7 +459,6 @@ async fn post_listing_like(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn person_note(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -514,7 +508,6 @@ async fn person_note(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_person_vote_totals(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -664,7 +657,6 @@ async fn post_listing_person_vote_totals(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_read_only(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -688,7 +680,6 @@ async fn post_listing_read_only(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn creator_info(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -811,7 +802,6 @@ async fn creator_info(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_person_language(data: &mut Data) -> LemmyResult<()> { const EL_POSTO: &str = "el posto"; @@ -878,7 +868,6 @@ async fn post_listing_person_language(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_removed(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -912,7 +901,6 @@ async fn post_listings_removed(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_deleted(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -951,7 +939,6 @@ async fn post_listings_deleted(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_hidden_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -988,7 +975,6 @@ async fn post_listings_hidden_community(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_COMMS: &str = "post on blocked instance"; const HOWARD_POST: &str = "howard post"; @@ -1077,7 +1063,6 @@ async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_USERS: &str = "post from blocked instance user"; const POST_TO_UNBLOCKED_COMM: &str = "post to unblocked comm"; @@ -1158,7 +1143,6 @@ async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> #[test_context(Data)] #[tokio::test] -#[serial] async fn pagination_includes_each_post_once(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1258,7 +1242,6 @@ async fn pagination_includes_each_post_once(data: &mut Data) -> LemmyResult<()> #[test_context(Data)] #[tokio::test] -#[serial] /// Test that last and first partial pages only have one cursor. async fn pagination_hidden_cursors(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); @@ -1375,7 +1358,6 @@ async fn pagination_hidden_cursors(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] /// Test paging past the last and first page. async fn pagination_recovery_cursors(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); @@ -1506,7 +1488,6 @@ async fn pagination_recovery_cursors(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_hide_read(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1554,7 +1535,6 @@ async fn post_listings_hide_read(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_hide_hidden(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1600,7 +1580,6 @@ async fn post_listings_hide_hidden(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_hide_nsfw(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1645,7 +1624,6 @@ async fn post_listings_hide_nsfw(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn local_only_instance(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1694,7 +1672,6 @@ async fn local_only_instance(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_local_user_banned_from_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1738,7 +1715,6 @@ async fn post_listing_local_user_banned_from_community(data: &mut Data) -> Lemmy #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_local_user_not_banned_from_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1766,7 +1742,6 @@ fn micros(dt: DateTime) -> i64 { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_creator_banned(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1817,7 +1792,6 @@ async fn post_listing_creator_banned(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_creator_community_banned(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1872,7 +1846,6 @@ async fn post_listing_creator_community_banned(data: &mut Data) -> LemmyResult<( #[test_context(Data)] #[tokio::test] -#[serial] async fn speed_check(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1924,7 +1897,6 @@ async fn speed_check(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -1954,7 +1926,6 @@ async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_private_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2053,7 +2024,6 @@ async fn post_listing_private_community(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listings_hide_media(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2113,7 +2083,6 @@ async fn post_listings_hide_media(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_with_blocked_keywords(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2186,7 +2155,6 @@ async fn post_with_blocked_keywords(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] #[tokio::test] -#[serial] async fn post_tags_present(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); @@ -2214,7 +2182,6 @@ async fn post_tags_present(data: &mut Data) -> LemmyResult<()> { #[test_context(Data)] #[tokio::test] -#[serial] async fn post_listing_multi_community(data: &mut Data) -> LemmyResult<()> { let pool = &data.pool(); let pool = &mut pool.into(); diff --git a/crates/db_views/report_combined/src/impls.rs b/crates/db_views/report_combined/src/impls.rs index b139add3bb..f3cb37ed72 100644 --- a/crates/db_views/report_combined/src/impls.rs +++ b/crates/db_views/report_combined/src/impls.rs @@ -1287,12 +1287,11 @@ mod tests { } #[tokio::test] - #[serial] async fn ensure_creator_data_is_correct() -> LemmyResult<()> { // The creator_banned and other creator_data should be the content creator, not the report // creator. - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/site/src/impls.rs b/crates/db_views/site/src/impls.rs index d2a1925be4..b4547f1b4a 100644 --- a/crates/db_views/site/src/impls.rs +++ b/crates/db_views/site/src/impls.rs @@ -240,7 +240,7 @@ mod tests { #[tokio::test] async fn test_instance_list() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); // insert test data From 7984f6d80698da906156d573ec5a339860be944f Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 15 Dec 2025 23:13:33 +0200 Subject: [PATCH 29/40] shared runtime in tests --- Cargo.lock | 20 ++++++++++++++++ crates/api/api/Cargo.toml | 1 + .../api/api/src/federation/resolve_object.rs | 2 +- .../src/federation/user_settings_backup.rs | 6 ++--- crates/api/api/src/site/mod_log.rs | 2 +- .../site/registration_applications/tests.rs | 2 +- crates/api/api_utils/Cargo.toml | 1 + crates/api/api_utils/src/claims.rs | 2 +- crates/api/api_utils/src/notify.rs | 10 ++++---- crates/api/api_utils/src/request.rs | 2 +- crates/api/api_utils/src/utils.rs | 2 +- crates/apub/apub/Cargo.toml | 1 + .../src/collections/community_moderators.rs | 2 +- crates/apub/apub/src/http/community.rs | 8 +++---- crates/apub/objects/Cargo.toml | 1 + crates/apub/objects/src/objects/comment.rs | 6 ++--- crates/apub/objects/src/objects/community.rs | 2 +- crates/apub/objects/src/objects/instance.rs | 2 +- crates/apub/objects/src/objects/person.rs | 4 ++-- crates/apub/objects/src/objects/post.rs | 4 ++-- .../objects/src/objects/private_message.rs | 4 ++-- .../apub/objects/src/utils/markdown_links.rs | 2 +- crates/db_schema/Cargo.toml | 1 + crates/db_schema/src/impls/activity.rs | 4 ++-- crates/db_schema/src/impls/actor_language.rs | 12 +++++----- crates/db_schema/src/impls/captcha_answer.rs | 4 ++-- crates/db_schema/src/impls/comment.rs | 6 ++--- crates/db_schema/src/impls/community.rs | 4 ++-- .../src/impls/federation_allowlist.rs | 2 +- crates/db_schema/src/impls/language.rs | 2 +- crates/db_schema/src/impls/local_site.rs | 4 ++-- crates/db_schema/src/impls/local_user.rs | 4 ++-- crates/db_schema/src/impls/mod_log/mod.rs | 2 +- crates/db_schema/src/impls/multi_community.rs | 4 ++-- .../src/impls/password_reset_request.rs | 2 +- crates/db_schema/src/impls/person.rs | 6 ++--- crates/db_schema/src/impls/post.rs | 6 ++--- crates/db_schema/src/impls/post_report.rs | 4 ++-- crates/db_schema/src/impls/private_message.rs | 2 +- crates/db_views/comment/Cargo.toml | 1 + crates/db_views/comment/src/impls.rs | 24 +++++++++---------- crates/db_views/community/Cargo.toml | 1 + crates/db_views/community/src/impls.rs | 10 ++++---- .../community_follower_approval/Cargo.toml | 1 + .../community_follower_approval/src/impls.rs | 4 ++-- crates/db_views/local_user/Cargo.toml | 1 + crates/db_views/local_user/src/impls.rs | 2 +- crates/db_views/modlog/Cargo.toml | 1 + crates/db_views/modlog/src/impls.rs | 6 ++--- crates/db_views/notification/Cargo.toml | 1 + crates/db_views/notification/src/tests.rs | 6 ++--- crates/db_views/person/Cargo.toml | 1 + crates/db_views/person/src/impls.rs | 6 ++--- .../person_content_combined/Cargo.toml | 1 + .../person_content_combined/src/impls.rs | 2 +- .../db_views/person_liked_combined/Cargo.toml | 1 + .../person_liked_combined/src/impls.rs | 2 +- .../db_views/person_saved_combined/Cargo.toml | 1 + .../person_saved_combined/src/impls.rs | 2 +- .../registration_applications/Cargo.toml | 1 + .../registration_applications/src/impls.rs | 2 +- crates/db_views/report_combined/Cargo.toml | 1 + crates/db_views/report_combined/src/impls.rs | 16 ++++++------- crates/db_views/search_combined/Cargo.toml | 1 + crates/db_views/search_combined/src/impls.rs | 16 ++++++------- crates/db_views/site/Cargo.toml | 1 + crates/db_views/site/src/impls.rs | 2 +- crates/routes/Cargo.toml | 1 + crates/routes/src/middleware/session.rs | 2 +- crates/routes/src/utils/scheduled_tasks.rs | 6 ++--- 70 files changed, 159 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46a7738e92..25c8f2b03b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3361,6 +3361,7 @@ dependencies = [ "serde_json", "sitemap-rs", "tokio", + "tokio-shared-rt", "totp-rs", "tracing", "url", @@ -3546,6 +3547,7 @@ dependencies = [ "reqwest-middleware", "serde", "tokio", + "tokio-shared-rt", "tracing", "url", "urlencoding", @@ -3579,6 +3581,7 @@ dependencies = [ "serde", "serde_json", "tokio", + "tokio-shared-rt", "tracing", "url", ] @@ -3649,6 +3652,7 @@ dependencies = [ "serde_with", "stringreader", "tokio", + "tokio-shared-rt", "tracing", "url", ] @@ -3731,6 +3735,7 @@ dependencies = [ "serde_with", "strum 0.27.2", "tokio", + "tokio-shared-rt", "ts-rs", "url", "uuid", @@ -3793,6 +3798,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -3811,6 +3817,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", "url", ] @@ -3846,6 +3853,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -3912,6 +3920,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -3941,6 +3950,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -3965,6 +3975,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -3994,6 +4005,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4015,6 +4027,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4035,6 +4048,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4055,6 +4069,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4125,6 +4140,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4146,6 +4162,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", ] @@ -4178,6 +4195,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", "url", ] @@ -4205,6 +4223,7 @@ dependencies = [ "serde", "serde_with", "tokio", + "tokio-shared-rt", "ts-rs", "url", ] @@ -4317,6 +4336,7 @@ dependencies = [ "rss", "serde", "tokio", + "tokio-shared-rt", "tracing", "url", ] diff --git a/crates/api/api/Cargo.toml b/crates/api/api/Cargo.toml index 3e833ee536..866eed5c41 100644 --- a/crates/api/api/Cargo.toml +++ b/crates/api/api/Cargo.toml @@ -78,6 +78,7 @@ lemmy_diesel_utils = { workspace = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } elementtree = "1.2.3" pretty_assertions = { workspace = true } lemmy_api_crud = { workspace = true } diff --git a/crates/api/api/src/federation/resolve_object.rs b/crates/api/api/src/federation/resolve_object.rs index 41075fccc7..f1d73f7ebe 100644 --- a/crates/api/api/src/federation/resolve_object.rs +++ b/crates/api/api/src/federation/resolve_object.rs @@ -130,7 +130,7 @@ mod tests { }; use lemmy_diesel_utils::traits::Crud; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_object_visibility() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api/src/federation/user_settings_backup.rs b/crates/api/api/src/federation/user_settings_backup.rs index 25c577596e..c2e015580d 100644 --- a/crates/api/api/src/federation/user_settings_backup.rs +++ b/crates/api/api/src/federation/user_settings_backup.rs @@ -316,7 +316,7 @@ pub(crate) mod tests { use std::time::Duration; use tokio::time::sleep; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_settings_export_import() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -386,7 +386,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn disallow_large_backup() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -422,7 +422,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn import_partial_backup() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api/src/site/mod_log.rs b/crates/api/api/src/site/mod_log.rs index c28936af72..16e12e655e 100644 --- a/crates/api/api/src/site/mod_log.rs +++ b/crates/api/api/src/site/mod_log.rs @@ -67,7 +67,7 @@ mod tests { use lemmy_diesel_utils::traits::Crud; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_mod_remove_or_restore_data() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api/src/site/registration_applications/tests.rs b/crates/api/api/src/site/registration_applications/tests.rs index dde43f5d85..1eaa0f2150 100644 --- a/crates/api/api/src/site/registration_applications/tests.rs +++ b/crates/api/api/src/site/registration_applications/tests.rs @@ -119,7 +119,7 @@ async fn get_application_statuses( )) } -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] #[expect(clippy::indexing_slicing)] async fn test_application_approval() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/api/api_utils/Cargo.toml b/crates/api/api_utils/Cargo.toml index d5a20fcf37..f1726ff581 100644 --- a/crates/api/api_utils/Cargo.toml +++ b/crates/api/api_utils/Cargo.toml @@ -81,3 +81,4 @@ lemmy_diesel_utils = { workspace = true } pretty_assertions = { workspace = true } lemmy_db_views_notification = { workspace = true, features = ["full"] } diesel_ltree = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/api/api_utils/src/claims.rs b/crates/api/api_utils/src/claims.rs index bddd889cb4..aea340e715 100644 --- a/crates/api/api_utils/src/claims.rs +++ b/crates/api/api_utils/src/claims.rs @@ -93,7 +93,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_should_not_validate_user_token_after_password_change() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api_utils/src/notify.rs b/crates/api/api_utils/src/notify.rs index 679a98e0f3..f3f17230e3 100644 --- a/crates/api/api_utils/src/notify.rs +++ b/crates/api/api_utils/src/notify.rs @@ -493,7 +493,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn replies() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -587,7 +587,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn mentions() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -727,7 +727,7 @@ mod tests { } } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn read_private_messages() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -775,7 +775,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn ensure_private_message_person_block() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); @@ -816,7 +816,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn ensure_private_message_instance_block() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); diff --git a/crates/api/api_utils/src/request.rs b/crates/api/api_utils/src/request.rs index b535ad4929..f6a67fac39 100644 --- a/crates/api/api_utils/src/request.rs +++ b/crates/api/api_utils/src/request.rs @@ -602,7 +602,7 @@ mod tests { use url::Url; // These helped with testing - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_link_metadata() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let sample_url = Url::parse("https://gitlab.com/IzzyOnDroid/repo/-/wikis/FAQ")?; diff --git a/crates/api/api_utils/src/utils.rs b/crates/api/api_utils/src/utils.rs index 5b9c24107b..3e857b8813 100644 --- a/crates/api/api_utils/src/utils.rs +++ b/crates/api/api_utils/src/utils.rs @@ -1011,7 +1011,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_proxy_image_link() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/apub/apub/Cargo.toml b/crates/apub/apub/Cargo.toml index 84c79d180e..6cb8a3c976 100644 --- a/crates/apub/apub/Cargo.toml +++ b/crates/apub/apub/Cargo.toml @@ -50,6 +50,7 @@ chrono = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio-shared-rt = { workspace = true } [package.metadata.cargo-shear] ignored = ["futures", "futures-util"] diff --git a/crates/apub/apub/src/collections/community_moderators.rs b/crates/apub/apub/src/collections/community_moderators.rs index f7737feadf..58b1ee552e 100644 --- a/crates/apub/apub/src/collections/community_moderators.rs +++ b/crates/apub/apub/src/collections/community_moderators.rs @@ -118,7 +118,7 @@ mod tests { use lemmy_diesel_utils::traits::Crud; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_lemmy_community_moderators() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; diff --git a/crates/apub/apub/src/http/community.rs b/crates/apub/apub/src/http/community.rs index 558ade1554..cbc458b90a 100644 --- a/crates/apub/apub/src/http/community.rs +++ b/crates/apub/apub/src/http/community.rs @@ -277,7 +277,7 @@ pub(crate) mod tests { Ok(serde_json::from_str(body)?) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_get_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, community, path) = init(false, CommunityVisibility::Public, &context).await?; @@ -315,7 +315,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_get_deleted_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, _, path) = init(true, CommunityVisibility::Public, &context).await?; @@ -344,7 +344,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_get_local_only_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, _, path) = init(false, CommunityVisibility::LocalOnlyPrivate, &context).await?; @@ -369,7 +369,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_outbox_deleted_user() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, community, path) = init(false, CommunityVisibility::Public, &context).await?; diff --git a/crates/apub/objects/Cargo.toml b/crates/apub/objects/Cargo.toml index c3ab61cfa8..187fb5cdfe 100644 --- a/crates/apub/objects/Cargo.toml +++ b/crates/apub/objects/Cargo.toml @@ -54,6 +54,7 @@ lemmy_diesel_utils = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio-shared-rt = { workspace = true } [package.metadata.cargo-shear] ignored = ["futures", "futures-util"] diff --git a/crates/apub/objects/src/objects/comment.rs b/crates/apub/objects/src/objects/comment.rs index a891b2b12c..c966212c83 100644 --- a/crates/apub/objects/src/objects/comment.rs +++ b/crates/apub/objects/src/objects/comment.rs @@ -266,7 +266,7 @@ pub(crate) mod tests { Ok((person, community, post, site)) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] pub(crate) async fn test_parse_lemmy_comment() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; @@ -290,7 +290,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_pleroma_comment() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; @@ -316,7 +316,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_html_to_markdown_sanitize() { let parsed = parse_html("hello"); assert_eq!(parsed, "**hello**"); diff --git a/crates/apub/objects/src/objects/community.rs b/crates/apub/objects/src/objects/community.rs index d53ac2e652..a49f1d600d 100644 --- a/crates/apub/objects/src/objects/community.rs +++ b/crates/apub/objects/src/objects/community.rs @@ -294,7 +294,7 @@ pub(crate) mod tests { use lemmy_db_schema::source::instance::Instance; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_lemmy_community() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; parse_lemmy_instance(&context).await?; diff --git a/crates/apub/objects/src/objects/instance.rs b/crates/apub/objects/src/objects/instance.rs index a06cc460c3..0902170458 100644 --- a/crates/apub/objects/src/objects/instance.rs +++ b/crates/apub/objects/src/objects/instance.rs @@ -221,7 +221,7 @@ pub(crate) mod tests { use lemmy_db_schema::source::instance::Instance; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_lemmy_instance() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let site = parse_lemmy_instance(&context).await?; diff --git a/crates/apub/objects/src/objects/person.rs b/crates/apub/objects/src/objects/person.rs index 07594a0eae..c11aaf7a6c 100644 --- a/crates/apub/objects/src/objects/person.rs +++ b/crates/apub/objects/src/objects/person.rs @@ -219,7 +219,7 @@ pub(crate) mod tests { use lemmy_db_schema::source::instance::Instance; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_lemmy_person() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (person, _) = parse_lemmy_person(&context).await?; @@ -232,7 +232,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_pleroma_person() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/apub/objects/src/objects/post.rs b/crates/apub/objects/src/objects/post.rs index 8c5c6a2207..5156ff5788 100644 --- a/crates/apub/objects/src/objects/post.rs +++ b/crates/apub/objects/src/objects/post.rs @@ -382,7 +382,7 @@ mod tests { use lemmy_db_schema::source::instance::Instance; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_lemmy_post() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; parse_lemmy_person(&context).await?; @@ -405,7 +405,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_convert_mastodon_post_title() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; parse_lemmy_community(&context).await?; diff --git a/crates/apub/objects/src/objects/private_message.rs b/crates/apub/objects/src/objects/private_message.rs index e3ec15aa7f..83c395e6b6 100644 --- a/crates/apub/objects/src/objects/private_message.rs +++ b/crates/apub/objects/src/objects/private_message.rs @@ -201,7 +201,7 @@ mod tests { Ok((person1, person2, site)) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_lemmy_pm() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; @@ -224,7 +224,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_parse_pleroma_pm() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let test_data = TestData::create(&mut context.pool()).await?; diff --git a/crates/apub/objects/src/utils/markdown_links.rs b/crates/apub/objects/src/utils/markdown_links.rs index ab34d671ba..9300d9f3b7 100644 --- a/crates/apub/objects/src/utils/markdown_links.rs +++ b/crates/apub/objects/src/utils/markdown_links.rs @@ -80,7 +80,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_markdown_rewrite_remote_links() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let data = TestData::create(&mut context.pool()).await?; diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index c6d4fb8d95..7b3ae229bf 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -66,3 +66,4 @@ moka = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio-shared-rt = { workspace = true } \ No newline at end of file diff --git a/crates/db_schema/src/impls/activity.rs b/crates/db_schema/src/impls/activity.rs index 96c7b13288..131b719d6a 100644 --- a/crates/db_schema/src/impls/activity.rs +++ b/crates/db_schema/src/impls/activity.rs @@ -72,7 +72,7 @@ mod tests { use serde_json::json; use url::Url; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn receive_activity_duplicate() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -86,7 +86,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn sent_activity_write_read() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/actor_language.rs b/crates/db_schema/src/impls/actor_language.rs index e2c8066aed..0c180b8bae 100644 --- a/crates/db_schema/src/impls/actor_language.rs +++ b/crates/db_schema/src/impls/actor_language.rs @@ -395,7 +395,7 @@ mod tests { ]) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_convert_update_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -412,7 +412,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_convert_read_languages() -> LemmyResult<()> { use lemmy_db_schema_file::schema::language::dsl::{id, language}; let pool = &build_db_pool_for_tests().await; @@ -432,7 +432,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_site_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -454,7 +454,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_user_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -485,7 +485,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_community_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -539,7 +539,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_validate_post_language() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/captcha_answer.rs b/crates/db_schema/src/impls/captcha_answer.rs index 9bd61f0998..fc6d71f45c 100644 --- a/crates/db_schema/src/impls/captcha_answer.rs +++ b/crates/db_schema/src/impls/captcha_answer.rs @@ -51,7 +51,7 @@ mod tests { use lemmy_diesel_utils::connection::build_db_pool_for_tests; use lemmy_utils::error::LemmyResult; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_captcha_happy_path() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -77,7 +77,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_captcha_repeat_answer_fails() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index f4d2e01671..66823f073e 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -439,7 +439,7 @@ mod tests { use pretty_assertions::assert_eq; use url::Url; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -552,7 +552,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_aggregates() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -647,7 +647,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_update_children() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 23e045c78e..5b2e2f3fd1 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -705,7 +705,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -855,7 +855,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_aggregates() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/federation_allowlist.rs b/crates/db_schema/src/impls/federation_allowlist.rs index 35db651e2f..e361b29da7 100644 --- a/crates/db_schema/src/impls/federation_allowlist.rs +++ b/crates/db_schema/src/impls/federation_allowlist.rs @@ -31,7 +31,7 @@ mod tests { use lemmy_diesel_utils::connection::build_db_pool_for_tests; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_allowlist_insert_and_clear() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/language.rs b/crates/db_schema/src/impls/language.rs index bed62a9ecc..72bda3ea63 100644 --- a/crates/db_schema/src/impls/language.rs +++ b/crates/db_schema/src/impls/language.rs @@ -62,7 +62,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index 239194b927..51767ea21f 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -83,7 +83,7 @@ mod tests { Ok((data, inserted_person, inserted_community)) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_aggregates() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -152,7 +152,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_soft_delete() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/local_user.rs b/crates/db_schema/src/impls/local_user.rs index 1b68612e9d..f81537b773 100644 --- a/crates/db_schema/src/impls/local_user.rs +++ b/crates/db_schema/src/impls/local_user.rs @@ -408,7 +408,7 @@ mod tests { use lemmy_diesel_utils::{connection::build_db_pool_for_tests, traits::Crud}; use lemmy_utils::error::LemmyResult; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_admin_higher_check() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -446,7 +446,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_email_taken() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/mod_log/mod.rs b/crates/db_schema/src/impls/mod_log/mod.rs index 8174623445..643ff6e8f7 100644 --- a/crates/db_schema/src/impls/mod_log/mod.rs +++ b/crates/db_schema/src/impls/mod_log/mod.rs @@ -19,7 +19,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/multi_community.rs b/crates/db_schema/src/impls/multi_community.rs index 09fe425f03..ab14a03737 100644 --- a/crates/db_schema/src/impls/multi_community.rs +++ b/crates/db_schema/src/impls/multi_community.rs @@ -395,7 +395,7 @@ mod tests { }) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_counts() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -452,7 +452,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_multi_community_apub() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 693030ed22..c5fcd82df3 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -56,7 +56,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_password_reset() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index a441503a9f..50efbbfb73 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -453,7 +453,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -508,7 +508,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn follow() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -535,7 +535,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_aggregates() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index 88beceb27a..b321fa1192 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -599,7 +599,7 @@ mod tests { use pretty_assertions::assert_eq; use url::Url; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -737,7 +737,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_aggregates() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -840,7 +840,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_aggregates_soft_delete() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index 69a6a0c159..0e5b6bd976 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -128,7 +128,7 @@ mod tests { Ok((person, report)) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_resolve_post_report() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -147,7 +147,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_resolve_all_post_reports() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index fd262051b2..4883bedb34 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -114,7 +114,7 @@ mod tests { use pretty_assertions::assert_eq; use url::Url; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/comment/Cargo.toml b/crates/db_views/comment/Cargo.toml index b92a952012..8214da2841 100644 --- a/crates/db_views/comment/Cargo.toml +++ b/crates/db_views/comment/Cargo.toml @@ -45,4 +45,5 @@ chrono = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/comment/src/impls.rs b/crates/db_views/comment/src/impls.rs index 93e01a0b6a..30b41a12d3 100644 --- a/crates/db_views/comment/src/impls.rs +++ b/crates/db_views/comment/src/impls.rs @@ -489,7 +489,7 @@ mod tests { }) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -544,7 +544,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_comment_tree() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -622,7 +622,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -680,7 +680,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_distinguished_first() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -704,7 +704,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_creator_is_moderator() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -732,7 +732,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_creator_is_admin() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -776,7 +776,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn local_only_instance() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -823,7 +823,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment_listing_local_user_banned_from_community() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -865,7 +865,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment_listing_local_user_not_banned_from_community() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -884,7 +884,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment_listings_hide_nsfw() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -912,7 +912,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment_listing_private_community() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1004,7 +1004,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment_removed() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/community/Cargo.toml b/crates/db_views/community/Cargo.toml index 24b6caad33..f46585b42e 100644 --- a/crates/db_views/community/Cargo.toml +++ b/crates/db_views/community/Cargo.toml @@ -47,4 +47,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } url = { workspace = true } diff --git a/crates/db_views/community/src/impls.rs b/crates/db_views/community/src/impls.rs index fb1a89ac37..cdcc2e1ced 100644 --- a/crates/db_views/community/src/impls.rs +++ b/crates/db_views/community/src/impls.rs @@ -463,7 +463,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn follow_state() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -534,7 +534,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn local_only_community() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -578,7 +578,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn community_sort_name() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -607,7 +607,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn can_mod() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -653,7 +653,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_multi_community_list() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/community_follower_approval/Cargo.toml b/crates/db_views/community_follower_approval/Cargo.toml index e2515ea670..a31527e434 100644 --- a/crates/db_views/community_follower_approval/Cargo.toml +++ b/crates/db_views/community_follower_approval/Cargo.toml @@ -41,3 +41,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/community_follower_approval/src/impls.rs b/crates/db_views/community_follower_approval/src/impls.rs index 4cbe0cbaf0..1ee9a1642a 100644 --- a/crates/db_views/community_follower_approval/src/impls.rs +++ b/crates/db_views/community_follower_approval/src/impls.rs @@ -249,7 +249,7 @@ mod tests { use lemmy_db_schema_file::enums::CommunityVisibility; use lemmy_diesel_utils::{connection::build_db_pool_for_tests, traits::Crud}; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_has_followers_from_instance() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -317,7 +317,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_pending_followers() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/local_user/Cargo.toml b/crates/db_views/local_user/Cargo.toml index 677746d613..5522046095 100644 --- a/crates/db_views/local_user/Cargo.toml +++ b/crates/db_views/local_user/Cargo.toml @@ -44,4 +44,5 @@ chrono = { workspace = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/local_user/src/impls.rs b/crates/db_views/local_user/src/impls.rs index 84758a4b7e..ec69040196 100644 --- a/crates/db_views/local_user/src/impls.rs +++ b/crates/db_views/local_user/src/impls.rs @@ -278,7 +278,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn list_banned() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/modlog/Cargo.toml b/crates/db_views/modlog/Cargo.toml index a8ec974a4c..be6aa4e4dc 100644 --- a/crates/db_views/modlog/Cargo.toml +++ b/crates/db_views/modlog/Cargo.toml @@ -42,3 +42,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/modlog/src/impls.rs b/crates/db_views/modlog/src/impls.rs index 924c613438..b058583351 100644 --- a/crates/db_views/modlog/src/impls.rs +++ b/crates/db_views/modlog/src/impls.rs @@ -286,7 +286,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn admin_types() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -435,7 +435,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn mod_types() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -765,7 +765,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn hide_modlog_names() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/notification/Cargo.toml b/crates/db_views/notification/Cargo.toml index b8d9f9f78b..0233577469 100644 --- a/crates/db_views/notification/Cargo.toml +++ b/crates/db_views/notification/Cargo.toml @@ -51,4 +51,5 @@ chrono = { workspace = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/notification/src/tests.rs b/crates/db_views/notification/src/tests.rs index bc12f07ebd..ef30182a5e 100644 --- a/crates/db_views/notification/src/tests.rs +++ b/crates/db_views/notification/src/tests.rs @@ -42,7 +42,7 @@ async fn cleanup(data: Data, pool: &mut DbPool<'_>) -> LemmyResult<()> { Ok(()) } -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn test_private_message() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -73,7 +73,7 @@ async fn test_private_message() -> LemmyResult<()> { cleanup(data, pool).await } -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn test_post() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -144,7 +144,7 @@ async fn test_post() -> LemmyResult<()> { cleanup(data, pool).await } -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn test_modlog() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/person/Cargo.toml b/crates/db_views/person/Cargo.toml index 05c8c58199..56d8e6d0a8 100644 --- a/crates/db_views/person/Cargo.toml +++ b/crates/db_views/person/Cargo.toml @@ -51,4 +51,5 @@ chrono = { workspace = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/person/src/impls.rs b/crates/db_views/person/src/impls.rs index 77f0abb1dc..40bf6c578e 100644 --- a/crates/db_views/person/src/impls.rs +++ b/crates/db_views/person/src/impls.rs @@ -181,7 +181,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn exclude_deleted() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -207,7 +207,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn list_admins() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -245,7 +245,7 @@ mod tests { cleanup(data, pool).await } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn note() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/person_content_combined/Cargo.toml b/crates/db_views/person_content_combined/Cargo.toml index 40c9b718bc..cbfc665946 100644 --- a/crates/db_views/person_content_combined/Cargo.toml +++ b/crates/db_views/person_content_combined/Cargo.toml @@ -49,3 +49,4 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_content_combined/src/impls.rs b/crates/db_views/person_content_combined/src/impls.rs index 8d5d1f509a..0cb7746c32 100644 --- a/crates/db_views/person_content_combined/src/impls.rs +++ b/crates/db_views/person_content_combined/src/impls.rs @@ -310,7 +310,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_combined() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/person_liked_combined/Cargo.toml b/crates/db_views/person_liked_combined/Cargo.toml index 256fcf5694..a9eee189a3 100644 --- a/crates/db_views/person_liked_combined/Cargo.toml +++ b/crates/db_views/person_liked_combined/Cargo.toml @@ -49,3 +49,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_liked_combined/src/impls.rs b/crates/db_views/person_liked_combined/src/impls.rs index 7bb1b582b6..54f0e10033 100644 --- a/crates/db_views/person_liked_combined/src/impls.rs +++ b/crates/db_views/person_liked_combined/src/impls.rs @@ -318,7 +318,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_combined() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/person_saved_combined/Cargo.toml b/crates/db_views/person_saved_combined/Cargo.toml index 241b0b1127..de036c1f4f 100644 --- a/crates/db_views/person_saved_combined/Cargo.toml +++ b/crates/db_views/person_saved_combined/Cargo.toml @@ -49,3 +49,4 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_saved_combined/src/impls.rs b/crates/db_views/person_saved_combined/src/impls.rs index 9e972e5dc9..981f7e5a3a 100644 --- a/crates/db_views/person_saved_combined/src/impls.rs +++ b/crates/db_views/person_saved_combined/src/impls.rs @@ -308,7 +308,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_combined() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/registration_applications/Cargo.toml b/crates/db_views/registration_applications/Cargo.toml index 7f4c92b34c..4560a23a9e 100644 --- a/crates/db_views/registration_applications/Cargo.toml +++ b/crates/db_views/registration_applications/Cargo.toml @@ -40,4 +40,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/registration_applications/src/impls.rs b/crates/db_views/registration_applications/src/impls.rs index a9c30b1297..238cde6bbb 100644 --- a/crates/db_views/registration_applications/src/impls.rs +++ b/crates/db_views/registration_applications/src/impls.rs @@ -174,7 +174,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_crud() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/report_combined/Cargo.toml b/crates/db_views/report_combined/Cargo.toml index 24341d7128..d3e58d965c 100644 --- a/crates/db_views/report_combined/Cargo.toml +++ b/crates/db_views/report_combined/Cargo.toml @@ -47,3 +47,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/report_combined/src/impls.rs b/crates/db_views/report_combined/src/impls.rs index f3cb37ed72..e1eac964be 100644 --- a/crates/db_views/report_combined/src/impls.rs +++ b/crates/db_views/report_combined/src/impls.rs @@ -586,7 +586,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn combined() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -756,7 +756,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn private_message_reports() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -820,7 +820,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post_reports() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -953,7 +953,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment_reports() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1076,7 +1076,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn community_reports() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1147,7 +1147,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn violates_instance_rules() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1236,7 +1236,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn my_reports_only() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1286,7 +1286,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn ensure_creator_data_is_correct() -> LemmyResult<()> { // The creator_banned and other creator_data should be the content creator, not the report // creator. diff --git a/crates/db_views/search_combined/Cargo.toml b/crates/db_views/search_combined/Cargo.toml index 63e040557d..5fbb1f2d76 100644 --- a/crates/db_views/search_combined/Cargo.toml +++ b/crates/db_views/search_combined/Cargo.toml @@ -60,3 +60,4 @@ url = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/search_combined/src/impls.rs b/crates/db_views/search_combined/src/impls.rs index 9ce3eb96d0..a059c76ffa 100644 --- a/crates/db_views/search_combined/src/impls.rs +++ b/crates/db_views/search_combined/src/impls.rs @@ -658,7 +658,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn combined() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -834,7 +834,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn community() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -907,7 +907,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn person() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -988,7 +988,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn post() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1118,7 +1118,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn nsfw_post() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1146,7 +1146,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn nsfw_comment() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1175,7 +1175,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn comment() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); @@ -1281,7 +1281,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn multi_community() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/site/Cargo.toml b/crates/db_views/site/Cargo.toml index 41e4550922..bbf99e4162 100644 --- a/crates/db_views/site/Cargo.toml +++ b/crates/db_views/site/Cargo.toml @@ -64,3 +64,4 @@ chrono = { workspace = true } [dev-dependencies] tokio = { workspace = true } +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/site/src/impls.rs b/crates/db_views/site/src/impls.rs index b4547f1b4a..63d638a99c 100644 --- a/crates/db_views/site/src/impls.rs +++ b/crates/db_views/site/src/impls.rs @@ -238,7 +238,7 @@ mod tests { use lemmy_diesel_utils::{connection::build_db_pool_for_tests, traits::Crud}; use lemmy_utils::error::LemmyResult; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_instance_list() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/routes/Cargo.toml b/crates/routes/Cargo.toml index fc0323a822..261a9e1347 100644 --- a/crates/routes/Cargo.toml +++ b/crates/routes/Cargo.toml @@ -63,3 +63,4 @@ lemmy_diesel_utils = { workspace = true } [dev-dependencies] pretty_assertions.workspace = true +tokio-shared-rt = { workspace = true } diff --git a/crates/routes/src/middleware/session.rs b/crates/routes/src/middleware/session.rs index 3e00f6e7f3..9e60ab5eed 100644 --- a/crates/routes/src/middleware/session.rs +++ b/crates/routes/src/middleware/session.rs @@ -111,7 +111,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_session_auth() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; diff --git a/crates/routes/src/utils/scheduled_tasks.rs b/crates/routes/src/utils/scheduled_tasks.rs index 8700684564..59c92e887b 100644 --- a/crates/routes/src/utils/scheduled_tasks.rs +++ b/crates/routes/src/utils/scheduled_tasks.rs @@ -729,7 +729,7 @@ mod tests { use pretty_assertions::assert_eq; use reqwest_middleware::ClientBuilder; - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_nodeinfo_lemmy_ml() -> LemmyResult<()> { let client = ClientBuilder::new(client_builder(&Settings::default()).build()?).build(); let form = build_update_instance_form("lemmy.ml", &client) @@ -739,7 +739,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_nodeinfo_mastodon_social() -> LemmyResult<()> { let client = ClientBuilder::new(client_builder(&Settings::default()).build()?).build(); let form = build_update_instance_form("mastodon.social", &client) @@ -749,7 +749,7 @@ mod tests { Ok(()) } - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_scheduled_tasks() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let pool = &mut context.pool(); From f912ecf18ee63d9bd43061be8d301091970d8762 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 15 Dec 2025 23:18:04 +0200 Subject: [PATCH 30/40] prettier fix --- docker/docker-compose-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose-test.yml b/docker/docker-compose-test.yml index b7dfa66fef..2981e35057 100644 --- a/docker/docker-compose-test.yml +++ b/docker/docker-compose-test.yml @@ -7,4 +7,4 @@ services: environment: - POSTGRES_USER=lemmy - POSTGRES_PASSWORD=password - - POSTGRES_DB=lemmy \ No newline at end of file + - POSTGRES_DB=lemmy From 20e9b46e5c5857e38d707bd3d277860a1326b4e4 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 15 Dec 2025 23:24:06 +0200 Subject: [PATCH 31/40] linter fixes --- Cargo.lock | 17 ------------- crates/api/api_utils/src/context.rs | 2 +- crates/apub/send/src/inboxes.rs | 2 +- crates/apub/send/src/stats.rs | 2 +- crates/apub/send/src/worker.rs | 2 +- crates/db_schema/Cargo.toml | 2 +- crates/db_views/comment/Cargo.toml | 1 - crates/db_views/community/Cargo.toml | 1 - crates/db_views/community_follower/Cargo.toml | 1 - .../community_follower_approval/Cargo.toml | 1 - crates/db_views/local_user/Cargo.toml | 1 - crates/db_views/modlog/Cargo.toml | 1 - crates/db_views/notification/Cargo.toml | 1 - crates/db_views/person/Cargo.toml | 1 - .../person_content_combined/Cargo.toml | 1 - .../db_views/person_liked_combined/Cargo.toml | 1 - .../db_views/person_saved_combined/Cargo.toml | 1 - crates/db_views/post/Cargo.toml | 1 - .../registration_applications/Cargo.toml | 1 - crates/db_views/report_combined/Cargo.toml | 1 - crates/db_views/search_combined/Cargo.toml | 1 - crates/db_views/site/Cargo.toml | 1 - crates/db_views/vote/Cargo.toml | 1 - crates/diesel_utils/src/connection.rs | 24 +++++++++---------- crates/server/src/lib.rs | 2 +- crates/utils/src/settings/mod.rs | 10 ++++++-- 26 files changed, 26 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25c8f2b03b..1f7c387781 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3797,7 +3797,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3816,7 +3815,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", "url", @@ -3835,7 +3833,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "tokio", "ts-rs", ] @@ -3852,7 +3849,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3919,7 +3915,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3949,7 +3944,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3974,7 +3968,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4004,7 +3997,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4026,7 +4018,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4047,7 +4038,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4068,7 +4058,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4092,7 +4081,6 @@ dependencies = [ "serde_with", "test-context", "tokio", - "tokio-shared-rt", "tracing", "ts-rs", "url", @@ -4139,7 +4127,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4161,7 +4148,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4194,7 +4180,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", "url", @@ -4222,7 +4207,6 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", "url", @@ -4241,7 +4225,6 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", - "tokio", "tokio-shared-rt", "ts-rs", ] diff --git a/crates/api/api_utils/src/context.rs b/crates/api/api_utils/src/context.rs index 36c598bb12..e5ced602d0 100644 --- a/crates/api/api_utils/src/context.rs +++ b/crates/api/api_utils/src/context.rs @@ -1,7 +1,7 @@ use crate::request::client_builder; use activitypub_federation::config::{Data, FederationConfig}; use lemmy_db_schema::source::secret::Secret; -use lemmy_diesel_utils::connection::{GenericDbPool, DbPool, build_db_pool_for_tests}; +use lemmy_diesel_utils::connection::{DbPool, GenericDbPool, build_db_pool_for_tests}; use lemmy_utils::{ rate_limit::RateLimit, settings::{SETTINGS, structs::Settings}, diff --git a/crates/apub/send/src/inboxes.rs b/crates/apub/send/src/inboxes.rs index bb2ee28e2e..6a798e0668 100644 --- a/crates/apub/send/src/inboxes.rs +++ b/crates/apub/send/src/inboxes.rs @@ -7,7 +7,7 @@ use lemmy_db_schema::{ use lemmy_db_schema_file::InstanceId; use lemmy_db_views_community_follower::CommunityFollowerView; use lemmy_diesel_utils::{ - connection::{GenericDbPool, DbPool}, + connection::{DbPool, GenericDbPool}, dburl::DbUrl, }; use lemmy_utils::error::LemmyResult; diff --git a/crates/apub/send/src/stats.rs b/crates/apub/send/src/stats.rs index 1f73b4c183..39f807ac20 100644 --- a/crates/apub/send/src/stats.rs +++ b/crates/apub/send/src/stats.rs @@ -2,7 +2,7 @@ use crate::util::{FederationQueueStateWithDomain, get_latest_activity_id}; use chrono::Local; use lemmy_db_schema::newtypes::ActivityId; use lemmy_db_schema_file::InstanceId; -use lemmy_diesel_utils::connection::{GenericDbPool, DbPool}; +use lemmy_diesel_utils::connection::{DbPool, GenericDbPool}; use lemmy_utils::{error::LemmyResult, federate_retry_sleep_duration}; use std::{collections::HashMap, time::Duration}; use tokio::{sync::mpsc::UnboundedReceiver, time::interval}; diff --git a/crates/apub/send/src/worker.rs b/crates/apub/send/src/worker.rs index 5f15baa250..492540d852 100644 --- a/crates/apub/send/src/worker.rs +++ b/crates/apub/send/src/worker.rs @@ -19,7 +19,7 @@ use lemmy_db_schema::{ instance::{Instance, InstanceForm}, }, }; -use lemmy_diesel_utils::connection::{GenericDbPool, DbPool}; +use lemmy_diesel_utils::connection::{DbPool, GenericDbPool}; use lemmy_utils::{ error::LemmyResult, federate_retry_sleep_duration, diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 7b3ae229bf..3d4d6732b7 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -66,4 +66,4 @@ moka = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio-shared-rt = { workspace = true } \ No newline at end of file +tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/comment/Cargo.toml b/crates/db_views/comment/Cargo.toml index 8214da2841..be6da832a7 100644 --- a/crates/db_views/comment/Cargo.toml +++ b/crates/db_views/comment/Cargo.toml @@ -44,6 +44,5 @@ chrono = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/community/Cargo.toml b/crates/db_views/community/Cargo.toml index f46585b42e..fb366aeaf6 100644 --- a/crates/db_views/community/Cargo.toml +++ b/crates/db_views/community/Cargo.toml @@ -46,6 +46,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } url = { workspace = true } diff --git a/crates/db_views/community_follower/Cargo.toml b/crates/db_views/community_follower/Cargo.toml index c12847c1df..d6eac5d8e3 100644 --- a/crates/db_views/community_follower/Cargo.toml +++ b/crates/db_views/community_follower/Cargo.toml @@ -40,4 +40,3 @@ chrono = { workspace = true } lemmy_diesel_utils = { workspace = true, optional = true } [dev-dependencies] -tokio = { workspace = true } diff --git a/crates/db_views/community_follower_approval/Cargo.toml b/crates/db_views/community_follower_approval/Cargo.toml index a31527e434..e43c88ce23 100644 --- a/crates/db_views/community_follower_approval/Cargo.toml +++ b/crates/db_views/community_follower_approval/Cargo.toml @@ -40,5 +40,4 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/local_user/Cargo.toml b/crates/db_views/local_user/Cargo.toml index 5522046095..5cac3e39ea 100644 --- a/crates/db_views/local_user/Cargo.toml +++ b/crates/db_views/local_user/Cargo.toml @@ -43,6 +43,5 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/modlog/Cargo.toml b/crates/db_views/modlog/Cargo.toml index be6aa4e4dc..6ea9ee7a08 100644 --- a/crates/db_views/modlog/Cargo.toml +++ b/crates/db_views/modlog/Cargo.toml @@ -41,5 +41,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/notification/Cargo.toml b/crates/db_views/notification/Cargo.toml index 0233577469..99e3fb22dd 100644 --- a/crates/db_views/notification/Cargo.toml +++ b/crates/db_views/notification/Cargo.toml @@ -50,6 +50,5 @@ serde_with = { workspace = true } chrono = { workspace = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/person/Cargo.toml b/crates/db_views/person/Cargo.toml index 56d8e6d0a8..b914f77e4f 100644 --- a/crates/db_views/person/Cargo.toml +++ b/crates/db_views/person/Cargo.toml @@ -50,6 +50,5 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/person_content_combined/Cargo.toml b/crates/db_views/person_content_combined/Cargo.toml index cbfc665946..b2fdbf01d9 100644 --- a/crates/db_views/person_content_combined/Cargo.toml +++ b/crates/db_views/person_content_combined/Cargo.toml @@ -48,5 +48,4 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_liked_combined/Cargo.toml b/crates/db_views/person_liked_combined/Cargo.toml index a9eee189a3..b4b81d3f5a 100644 --- a/crates/db_views/person_liked_combined/Cargo.toml +++ b/crates/db_views/person_liked_combined/Cargo.toml @@ -48,5 +48,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_saved_combined/Cargo.toml b/crates/db_views/person_saved_combined/Cargo.toml index de036c1f4f..dcf81c1569 100644 --- a/crates/db_views/person_saved_combined/Cargo.toml +++ b/crates/db_views/person_saved_combined/Cargo.toml @@ -48,5 +48,4 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/post/Cargo.toml b/crates/db_views/post/Cargo.toml index 1bc7ff242c..625c1e140d 100644 --- a/crates/db_views/post/Cargo.toml +++ b/crates/db_views/post/Cargo.toml @@ -44,7 +44,6 @@ lemmy_diesel_utils = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } tokio = { workspace = true } -tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } url = { workspace = true } test-context = "0.5.4" diff --git a/crates/db_views/registration_applications/Cargo.toml b/crates/db_views/registration_applications/Cargo.toml index 4560a23a9e..718be225ae 100644 --- a/crates/db_views/registration_applications/Cargo.toml +++ b/crates/db_views/registration_applications/Cargo.toml @@ -39,6 +39,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/report_combined/Cargo.toml b/crates/db_views/report_combined/Cargo.toml index d3e58d965c..aa18792fbe 100644 --- a/crates/db_views/report_combined/Cargo.toml +++ b/crates/db_views/report_combined/Cargo.toml @@ -46,5 +46,4 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/search_combined/Cargo.toml b/crates/db_views/search_combined/Cargo.toml index 5fbb1f2d76..04aabfb413 100644 --- a/crates/db_views/search_combined/Cargo.toml +++ b/crates/db_views/search_combined/Cargo.toml @@ -59,5 +59,4 @@ url = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/site/Cargo.toml b/crates/db_views/site/Cargo.toml index bbf99e4162..b1c5493e32 100644 --- a/crates/db_views/site/Cargo.toml +++ b/crates/db_views/site/Cargo.toml @@ -63,5 +63,4 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/vote/Cargo.toml b/crates/db_views/vote/Cargo.toml index 3ae47ac8c0..e04b7382c0 100644 --- a/crates/db_views/vote/Cargo.toml +++ b/crates/db_views/vote/Cargo.toml @@ -38,6 +38,5 @@ serde_with = { workspace = true } ts-rs = { workspace = true, optional = true } [dev-dependencies] -tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/diesel_utils/src/connection.rs b/crates/diesel_utils/src/connection.rs index 29d4c78568..a39efcb2e1 100644 --- a/crates/diesel_utils/src/connection.rs +++ b/crates/diesel_utils/src/connection.rs @@ -1,5 +1,6 @@ -use deadpool::{Runtime, Status}; +use crate::schema_setup; use db_pool::{ + PrivilegedPostgresConfig, r#async::{ DatabasePool, DatabasePoolBuilderTrait, @@ -7,8 +8,8 @@ use db_pool::{ DieselDeadpool, ReusableConnectionPool, }, - PrivilegedPostgresConfig, }; +use deadpool::{Runtime, Status}; use diesel::result::{ ConnectionError, ConnectionResult, @@ -16,6 +17,7 @@ use diesel::result::{ }; use diesel_async::{ AsyncConnection, + async_connection_wrapper::AsyncConnectionWrapper, pg::AsyncPgConnection, pooled_connection::{ AsyncDieselConnectionManager, @@ -47,15 +49,13 @@ use std::{ sync::Arc, time::Duration, }; -use diesel_async::async_connection_wrapper::AsyncConnectionWrapper; use tokio::sync::OnceCell; use tracing::error; use url::Url; -use crate::schema_setup; pub type ActualDbPool = Pool; pub type ReusableDbPool = -ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; + ReusableConnectionPool<'static, DieselAsyncPostgresBackend>; /// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit /// reborrowing. @@ -242,8 +242,8 @@ pub fn build_db_pool() -> LemmyResult { } #[allow(clippy::expect_used)] -pub async fn build_db_pool_for_tests( -) -> ReusableConnectionPool<'static, DieselAsyncPostgresBackend> { +pub async fn build_db_pool_for_tests() +-> ReusableConnectionPool<'static, DieselAsyncPostgresBackend> { static POOL: OnceCell>> = OnceCell::const_new(); let db_pool = POOL @@ -274,17 +274,17 @@ pub async fn build_db_pool_for_tests( schema_setup::Options::default().run(), &mut async_wrapper, ) - .expect("run migrations") + .expect("run migrations") }) - .await - .expect("task panicked"); + .await + .expect("task panicked"); None }) }, ) - .await - .expect("diesel postgres backend"); + .await + .expect("diesel postgres backend"); backend .create_database_pool() diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index 10a29a160f..9656958a4d 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -25,7 +25,7 @@ use lemmy_apub_objects::objects::{community::FETCH_COMMUNITY_COLLECTIONS, instan use lemmy_apub_send::{Opts, SendManager}; use lemmy_db_schema::source::secret::Secret; use lemmy_db_views_site::SiteView; -use lemmy_diesel_utils::connection::{build_db_pool, GenericDbPool}; +use lemmy_diesel_utils::connection::{GenericDbPool, build_db_pool}; use lemmy_routes::{ feeds, middleware::{ diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index 43597b5022..576a7fbc02 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -88,14 +88,20 @@ impl Settings { } pub fn get_lemmy_connection_options(&self) -> Vec<(String, String)> { - Vec::from([("lemmy.protocol_and_hostname".to_string(), self.get_protocol_and_hostname().to_string())]) + Vec::from([( + "lemmy.protocol_and_hostname".to_string(), + self.get_protocol_and_hostname().to_string(), + )]) } /// Sets a few additional config options necessary for starting lemmy pub fn get_database_url_with_options(&self) -> LemmyResult { let mut url = Url::parse(&self.get_database_url())?; - let mut options = CONNECTION_OPTIONS.iter().map(|s| s.to_string()).collect::>(); + let mut options = CONNECTION_OPTIONS + .iter() + .map(|s| s.to_string()) + .collect::>(); for (k, v) in self.get_lemmy_connection_options() { options.push(format!("{}={}", k, v)); } From c4ad852b514ba2a90229a98465941a7dcfda92bd Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 15 Dec 2025 23:27:51 +0200 Subject: [PATCH 32/40] removing empty file --- crates/db_views/modlog_combined/src/impls.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 crates/db_views/modlog_combined/src/impls.rs diff --git a/crates/db_views/modlog_combined/src/impls.rs b/crates/db_views/modlog_combined/src/impls.rs deleted file mode 100644 index e69de29bb2..0000000000 From c7f91519f78face18a7030af14493a2d95af8a5b Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 16 Dec 2025 00:02:14 +0200 Subject: [PATCH 33/40] fixing tests --- Cargo.lock | 15 +++++++++++++++ crates/db_views/comment/Cargo.toml | 1 + crates/db_views/community/Cargo.toml | 1 + .../community_follower_approval/Cargo.toml | 1 + crates/db_views/local_user/Cargo.toml | 1 + crates/db_views/modlog/Cargo.toml | 1 + crates/db_views/notification/Cargo.toml | 1 + crates/db_views/person/Cargo.toml | 1 + .../db_views/person_content_combined/Cargo.toml | 1 + crates/db_views/person_liked_combined/Cargo.toml | 1 + crates/db_views/person_saved_combined/Cargo.toml | 1 + .../db_views/registration_applications/Cargo.toml | 1 + crates/db_views/report_combined/Cargo.toml | 1 + crates/db_views/search_combined/Cargo.toml | 1 + crates/db_views/site/Cargo.toml | 1 + crates/db_views/vote/Cargo.toml | 1 + 16 files changed, 30 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1f7c387781..4c2f88b6fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3797,6 +3797,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3815,6 +3816,7 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", "url", @@ -3849,6 +3851,7 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3915,6 +3918,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3944,6 +3948,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3968,6 +3973,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -3997,6 +4003,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4018,6 +4025,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4038,6 +4046,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4058,6 +4067,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4127,6 +4137,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4148,6 +4159,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] @@ -4180,6 +4192,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", "url", @@ -4207,6 +4220,7 @@ dependencies = [ "lemmy_utils 1.0.0-alpha.12", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", "url", @@ -4225,6 +4239,7 @@ dependencies = [ "pretty_assertions", "serde", "serde_with", + "tokio", "tokio-shared-rt", "ts-rs", ] diff --git a/crates/db_views/comment/Cargo.toml b/crates/db_views/comment/Cargo.toml index be6da832a7..8214da2841 100644 --- a/crates/db_views/comment/Cargo.toml +++ b/crates/db_views/comment/Cargo.toml @@ -44,5 +44,6 @@ chrono = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/community/Cargo.toml b/crates/db_views/community/Cargo.toml index fb366aeaf6..f46585b42e 100644 --- a/crates/db_views/community/Cargo.toml +++ b/crates/db_views/community/Cargo.toml @@ -46,5 +46,6 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } url = { workspace = true } diff --git a/crates/db_views/community_follower_approval/Cargo.toml b/crates/db_views/community_follower_approval/Cargo.toml index e43c88ce23..a31527e434 100644 --- a/crates/db_views/community_follower_approval/Cargo.toml +++ b/crates/db_views/community_follower_approval/Cargo.toml @@ -40,4 +40,5 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/local_user/Cargo.toml b/crates/db_views/local_user/Cargo.toml index 5cac3e39ea..5522046095 100644 --- a/crates/db_views/local_user/Cargo.toml +++ b/crates/db_views/local_user/Cargo.toml @@ -43,5 +43,6 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/modlog/Cargo.toml b/crates/db_views/modlog/Cargo.toml index 6ea9ee7a08..be6aa4e4dc 100644 --- a/crates/db_views/modlog/Cargo.toml +++ b/crates/db_views/modlog/Cargo.toml @@ -41,4 +41,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/notification/Cargo.toml b/crates/db_views/notification/Cargo.toml index 99e3fb22dd..0233577469 100644 --- a/crates/db_views/notification/Cargo.toml +++ b/crates/db_views/notification/Cargo.toml @@ -50,5 +50,6 @@ serde_with = { workspace = true } chrono = { workspace = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/person/Cargo.toml b/crates/db_views/person/Cargo.toml index b914f77e4f..56d8e6d0a8 100644 --- a/crates/db_views/person/Cargo.toml +++ b/crates/db_views/person/Cargo.toml @@ -50,5 +50,6 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/person_content_combined/Cargo.toml b/crates/db_views/person_content_combined/Cargo.toml index b2fdbf01d9..cbfc665946 100644 --- a/crates/db_views/person_content_combined/Cargo.toml +++ b/crates/db_views/person_content_combined/Cargo.toml @@ -48,4 +48,5 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_liked_combined/Cargo.toml b/crates/db_views/person_liked_combined/Cargo.toml index b4b81d3f5a..a9eee189a3 100644 --- a/crates/db_views/person_liked_combined/Cargo.toml +++ b/crates/db_views/person_liked_combined/Cargo.toml @@ -48,4 +48,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/person_saved_combined/Cargo.toml b/crates/db_views/person_saved_combined/Cargo.toml index dcf81c1569..de036c1f4f 100644 --- a/crates/db_views/person_saved_combined/Cargo.toml +++ b/crates/db_views/person_saved_combined/Cargo.toml @@ -48,4 +48,5 @@ serde_with = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/registration_applications/Cargo.toml b/crates/db_views/registration_applications/Cargo.toml index 718be225ae..4560a23a9e 100644 --- a/crates/db_views/registration_applications/Cargo.toml +++ b/crates/db_views/registration_applications/Cargo.toml @@ -39,5 +39,6 @@ ts-rs = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } diff --git a/crates/db_views/report_combined/Cargo.toml b/crates/db_views/report_combined/Cargo.toml index aa18792fbe..d3e58d965c 100644 --- a/crates/db_views/report_combined/Cargo.toml +++ b/crates/db_views/report_combined/Cargo.toml @@ -46,4 +46,5 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/search_combined/Cargo.toml b/crates/db_views/search_combined/Cargo.toml index 04aabfb413..5fbb1f2d76 100644 --- a/crates/db_views/search_combined/Cargo.toml +++ b/crates/db_views/search_combined/Cargo.toml @@ -59,4 +59,5 @@ url = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/site/Cargo.toml b/crates/db_views/site/Cargo.toml index b1c5493e32..bbf99e4162 100644 --- a/crates/db_views/site/Cargo.toml +++ b/crates/db_views/site/Cargo.toml @@ -63,4 +63,5 @@ i-love-jesus = { workspace = true, optional = true } chrono = { workspace = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } diff --git a/crates/db_views/vote/Cargo.toml b/crates/db_views/vote/Cargo.toml index e04b7382c0..3ae47ac8c0 100644 --- a/crates/db_views/vote/Cargo.toml +++ b/crates/db_views/vote/Cargo.toml @@ -38,5 +38,6 @@ serde_with = { workspace = true } ts-rs = { workspace = true, optional = true } [dev-dependencies] +tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } From 90c6152ac857ad8a8079dda07a6a97a4afc2323d Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 16 Dec 2025 00:11:20 +0200 Subject: [PATCH 34/40] ignoring tokio to satisfy shear --- crates/db_views/comment/Cargo.toml | 3 +++ crates/db_views/community/Cargo.toml | 3 +++ crates/db_views/community_follower_approval/Cargo.toml | 3 +++ crates/db_views/local_user/Cargo.toml | 3 +++ crates/db_views/modlog/Cargo.toml | 3 +++ crates/db_views/notification/Cargo.toml | 3 +++ crates/db_views/person/Cargo.toml | 3 +++ crates/db_views/person_content_combined/Cargo.toml | 3 +++ crates/db_views/person_liked_combined/Cargo.toml | 3 +++ crates/db_views/person_saved_combined/Cargo.toml | 3 +++ crates/db_views/registration_applications/Cargo.toml | 3 +++ crates/db_views/report_combined/Cargo.toml | 3 +++ crates/db_views/search_combined/Cargo.toml | 3 +++ crates/db_views/site/Cargo.toml | 3 +++ crates/db_views/vote/Cargo.toml | 3 +++ 15 files changed, 45 insertions(+) diff --git a/crates/db_views/comment/Cargo.toml b/crates/db_views/comment/Cargo.toml index 8214da2841..a0bea7f001 100644 --- a/crates/db_views/comment/Cargo.toml +++ b/crates/db_views/comment/Cargo.toml @@ -47,3 +47,6 @@ lemmy_db_views_local_user = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/community/Cargo.toml b/crates/db_views/community/Cargo.toml index f46585b42e..4b98acf86d 100644 --- a/crates/db_views/community/Cargo.toml +++ b/crates/db_views/community/Cargo.toml @@ -49,3 +49,6 @@ i-love-jesus = { workspace = true, optional = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } url = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/community_follower_approval/Cargo.toml b/crates/db_views/community_follower_approval/Cargo.toml index a31527e434..34ef60add4 100644 --- a/crates/db_views/community_follower_approval/Cargo.toml +++ b/crates/db_views/community_follower_approval/Cargo.toml @@ -42,3 +42,6 @@ i-love-jesus = { workspace = true, optional = true } [dev-dependencies] tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/local_user/Cargo.toml b/crates/db_views/local_user/Cargo.toml index 5522046095..7f689e582e 100644 --- a/crates/db_views/local_user/Cargo.toml +++ b/crates/db_views/local_user/Cargo.toml @@ -46,3 +46,6 @@ chrono = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/modlog/Cargo.toml b/crates/db_views/modlog/Cargo.toml index be6aa4e4dc..f5180600cc 100644 --- a/crates/db_views/modlog/Cargo.toml +++ b/crates/db_views/modlog/Cargo.toml @@ -43,3 +43,6 @@ i-love-jesus = { workspace = true, optional = true } pretty_assertions = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/notification/Cargo.toml b/crates/db_views/notification/Cargo.toml index 0233577469..dbac866eb1 100644 --- a/crates/db_views/notification/Cargo.toml +++ b/crates/db_views/notification/Cargo.toml @@ -53,3 +53,6 @@ chrono = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] \ No newline at end of file diff --git a/crates/db_views/person/Cargo.toml b/crates/db_views/person/Cargo.toml index 56d8e6d0a8..8ee9bcb0cc 100644 --- a/crates/db_views/person/Cargo.toml +++ b/crates/db_views/person/Cargo.toml @@ -53,3 +53,6 @@ chrono = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/person_content_combined/Cargo.toml b/crates/db_views/person_content_combined/Cargo.toml index cbfc665946..f963591d2f 100644 --- a/crates/db_views/person_content_combined/Cargo.toml +++ b/crates/db_views/person_content_combined/Cargo.toml @@ -50,3 +50,6 @@ serde_with = { workspace = true } pretty_assertions = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/person_liked_combined/Cargo.toml b/crates/db_views/person_liked_combined/Cargo.toml index a9eee189a3..fcffde769b 100644 --- a/crates/db_views/person_liked_combined/Cargo.toml +++ b/crates/db_views/person_liked_combined/Cargo.toml @@ -50,3 +50,6 @@ i-love-jesus = { workspace = true, optional = true } pretty_assertions = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/person_saved_combined/Cargo.toml b/crates/db_views/person_saved_combined/Cargo.toml index de036c1f4f..6c9d99062c 100644 --- a/crates/db_views/person_saved_combined/Cargo.toml +++ b/crates/db_views/person_saved_combined/Cargo.toml @@ -50,3 +50,6 @@ serde_with = { workspace = true } pretty_assertions = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/registration_applications/Cargo.toml b/crates/db_views/registration_applications/Cargo.toml index 4560a23a9e..f93da627ff 100644 --- a/crates/db_views/registration_applications/Cargo.toml +++ b/crates/db_views/registration_applications/Cargo.toml @@ -42,3 +42,6 @@ i-love-jesus = { workspace = true, optional = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/report_combined/Cargo.toml b/crates/db_views/report_combined/Cargo.toml index d3e58d965c..e9e589e13f 100644 --- a/crates/db_views/report_combined/Cargo.toml +++ b/crates/db_views/report_combined/Cargo.toml @@ -48,3 +48,6 @@ i-love-jesus = { workspace = true, optional = true } pretty_assertions = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/search_combined/Cargo.toml b/crates/db_views/search_combined/Cargo.toml index 5fbb1f2d76..b549969089 100644 --- a/crates/db_views/search_combined/Cargo.toml +++ b/crates/db_views/search_combined/Cargo.toml @@ -61,3 +61,6 @@ url = { workspace = true } pretty_assertions = { workspace = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/site/Cargo.toml b/crates/db_views/site/Cargo.toml index bbf99e4162..11bd99593e 100644 --- a/crates/db_views/site/Cargo.toml +++ b/crates/db_views/site/Cargo.toml @@ -65,3 +65,6 @@ chrono = { workspace = true } [dev-dependencies] tokio = { workspace = true } tokio-shared-rt = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] diff --git a/crates/db_views/vote/Cargo.toml b/crates/db_views/vote/Cargo.toml index 3ae47ac8c0..d52ba809a6 100644 --- a/crates/db_views/vote/Cargo.toml +++ b/crates/db_views/vote/Cargo.toml @@ -41,3 +41,6 @@ ts-rs = { workspace = true, optional = true } tokio = { workspace = true } tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } + +[package.metadata.cargo-shear] +ignored = ["tokio"] \ No newline at end of file From a847d441378c8c5e3ca83cda5b44dcfea5b1184a Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Tue, 16 Dec 2025 00:13:38 +0200 Subject: [PATCH 35/40] taplo fix --- crates/db_views/notification/Cargo.toml | 2 +- crates/db_views/vote/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/db_views/notification/Cargo.toml b/crates/db_views/notification/Cargo.toml index dbac866eb1..83dad4e42d 100644 --- a/crates/db_views/notification/Cargo.toml +++ b/crates/db_views/notification/Cargo.toml @@ -55,4 +55,4 @@ tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } [package.metadata.cargo-shear] -ignored = ["tokio"] \ No newline at end of file +ignored = ["tokio"] diff --git a/crates/db_views/vote/Cargo.toml b/crates/db_views/vote/Cargo.toml index d52ba809a6..3a24c225a7 100644 --- a/crates/db_views/vote/Cargo.toml +++ b/crates/db_views/vote/Cargo.toml @@ -43,4 +43,4 @@ tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } [package.metadata.cargo-shear] -ignored = ["tokio"] \ No newline at end of file +ignored = ["tokio"] From 75d5671c16f9d83ef3fbf3c5341a401a26c4223d Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Thu, 1 Jan 2026 20:53:54 +0200 Subject: [PATCH 36/40] fixing tests and tomls --- crates/db_schema/src/impls/person.rs | 5 ++--- crates/diesel_utils/Cargo.toml | 1 + crates/server/Cargo.toml | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index f813a6dce3..b4b415dab2 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -631,10 +631,9 @@ mod tests { Ok(()) } - #[tokio::test] - #[serial] + #[tokio_shared_rt::test(shared = true)] async fn person_vote_counts() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = TestData::create(pool).await?; diff --git a/crates/diesel_utils/Cargo.toml b/crates/diesel_utils/Cargo.toml index 0c443beb65..acee1155c5 100644 --- a/crates/diesel_utils/Cargo.toml +++ b/crates/diesel_utils/Cargo.toml @@ -53,6 +53,7 @@ diesel-derive-newtype = { workspace = true } diesel-async = { workspace = true, features = [ "deadpool", "postgres", + "async-connection-wrapper", ], optional = true } db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test-superuser", features = [ "diesel-async-postgres", diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index 03718d200e..6d74267430 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -19,6 +19,7 @@ workspace = true [features] default = [] +full = [] [dependencies] lemmy_api = { workspace = true } From ec18a6baf46f53d55d5b856e855256adbb9c340d Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Fri, 2 Jan 2026 03:24:40 +0200 Subject: [PATCH 37/40] fixing lemmy_db_views_post tests --- Cargo.lock | 1 + crates/db_views/post/Cargo.toml | 1 + crates/db_views/post/src/test.rs | 244 ++++++++++++++++++------------- 3 files changed, 141 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c2f88b6fc..65d7c8f979 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4091,6 +4091,7 @@ dependencies = [ "serde_with", "test-context", "tokio", + "tokio-shared-rt", "tracing", "ts-rs", "url", diff --git a/crates/db_views/post/Cargo.toml b/crates/db_views/post/Cargo.toml index 625c1e140d..1bc7ff242c 100644 --- a/crates/db_views/post/Cargo.toml +++ b/crates/db_views/post/Cargo.toml @@ -44,6 +44,7 @@ lemmy_diesel_utils = { workspace = true } [dev-dependencies] lemmy_db_views_local_user = { workspace = true } tokio = { workspace = true } +tokio-shared-rt = { workspace = true } pretty_assertions = { workspace = true } url = { workspace = true } test-context = "0.5.4" diff --git a/crates/db_views/post/src/test.rs b/crates/db_views/post/src/test.rs index 0e1e1b1b43..ca6c60d44d 100644 --- a/crates/db_views/post/src/test.rs +++ b/crates/db_views/post/src/test.rs @@ -48,7 +48,7 @@ use lemmy_db_schema_file::enums::{ }; use lemmy_db_views_local_user::LocalUserView; use lemmy_diesel_utils::{ - connection::{ActualDbPool, DbPool, build_db_pool, get_conn}, + connection::{DbPool, ReusableDbPool, build_db_pool_for_tests, get_conn}, pagination::PaginationCursor, traits::Crud, }; @@ -56,6 +56,7 @@ use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult}; use pretty_assertions::assert_eq; use std::{ collections::HashSet, + sync::Arc, time::{Duration, Instant}, }; use test_context::{AsyncTestContext, test_context}; @@ -72,7 +73,7 @@ fn names(post_views: &[PostView]) -> Vec<&str> { } struct Data { - pool: ActualDbPool, + pool: Arc, instance: Instance, tegan: LocalUserView, john: LocalUserView, @@ -87,11 +88,11 @@ struct Data { } impl Data { - fn pool(&self) -> ActualDbPool { - self.pool.clone() + fn pool(&self) -> Arc { + Arc::clone(&self.pool) } pub fn pool2(&self) -> DbPool<'_> { - DbPool::Pool(&self.pool) + DbPool::ReusablePool(&self.pool) } fn default_post_query(&self) -> PostQuery<'_> { PostQuery { @@ -102,7 +103,7 @@ impl Data { } async fn setup() -> LemmyResult { - let actual_pool = build_db_pool()?; + let actual_pool = build_db_pool_for_tests().await; let pool = &mut (&actual_pool).into(); let data = TestData::create(pool).await?; @@ -240,7 +241,7 @@ impl Data { }; Ok(Data { - pool: actual_pool, + pool: actual_pool.into(), instance: data.instance, tegan, john, @@ -278,10 +279,11 @@ impl AsyncTestContext for Data { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_with_person(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let local_user_form = LocalUserUpdateForm { show_bot_accounts: Some(false), @@ -337,10 +339,11 @@ async fn post_listing_with_person(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_no_person(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let read_post_listing_multiple_no_person = PostQuery { community_id: Some(data.community.id), @@ -369,10 +372,11 @@ async fn post_listing_no_person(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_block_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let community_block = CommunityBlockForm::new(data.community.id, data.tegan.person.id); CommunityActions::block(pool, &community_block).await?; @@ -391,10 +395,11 @@ async fn post_listing_block_community(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_like(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let post_like_form = PostLikeForm::new(data.post.id, data.tegan.person.id, Some(true)); @@ -456,10 +461,11 @@ async fn post_listing_like(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn person_note(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let note_str = "Tegan loves cats."; @@ -505,10 +511,11 @@ async fn person_note(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_person_vote_totals(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Create a 2nd bot post, to do multiple votes let bot_post_2 = PostInsertForm::new( @@ -679,10 +686,11 @@ async fn post_listing_person_vote_totals(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_read_only(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Mark the bot post, then the tags post as read PostActions::mark_as_read(pool, data.tegan.person.id, &[data.bot_post.id]).await?; @@ -702,10 +710,11 @@ async fn post_listing_read_only(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn creator_info(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let community_id = data.community.id; let tegan_listings = PostQuery { @@ -824,12 +833,13 @@ async fn creator_info(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_person_language(data: &mut Data) -> LemmyResult<()> { const EL_POSTO: &str = "el posto"; - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let spanish_id = Language::read_id_from_code(pool, "es").await?; @@ -890,10 +900,11 @@ async fn post_listing_person_language(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_removed(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Remove the post Post::update( @@ -923,10 +934,11 @@ async fn post_listings_removed(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_deleted(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Delete the post Post::update( @@ -961,10 +973,11 @@ async fn post_listings_deleted(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_hidden_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); Community::update( pool, @@ -997,7 +1010,7 @@ async fn post_listings_hidden_community(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_COMMS: &str = "post on blocked instance"; const HOWARD_POST: &str = "howard post"; @@ -1009,8 +1022,9 @@ async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult POST, ]; - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let blocked_instance_comms = Instance::read_or_create(pool, "another_domain.tld").await?; @@ -1085,7 +1099,7 @@ async fn post_listing_instance_block_communities(data: &mut Data) -> LemmyResult } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> { const POST_FROM_BLOCKED_INSTANCE_USERS: &str = "post from blocked instance user"; const POST_TO_UNBLOCKED_COMM: &str = "post to unblocked comm"; @@ -1097,8 +1111,9 @@ async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> POST, ]; - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let blocked_instance_persons = Instance::read_or_create(pool, "another_domain.tld").await?; @@ -1165,10 +1180,11 @@ async fn post_listing_instance_block_persons(data: &mut Data) -> LemmyResult<()> } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn pagination_includes_each_post_once(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let community_form = CommunityInsertForm::new( data.instance.id, @@ -1264,11 +1280,12 @@ async fn pagination_includes_each_post_once(data: &mut Data) -> LemmyResult<()> } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] /// Test that last and first partial pages only have one cursor. async fn pagination_hidden_cursors(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let community_form = CommunityInsertForm::new( data.instance.id, @@ -1327,8 +1344,9 @@ async fn pagination_hidden_cursors(data: &mut Data) -> LemmyResult<()> { assert!(first_page2.prev_page.is_some()); assert_eq!(first_page2.next_page, first_page.next_page); - let pool = &data.pool; - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Mark first post as deleted let first_post_view = first_page.items.first().expect("first post"); @@ -1380,11 +1398,12 @@ async fn pagination_hidden_cursors(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] /// Test paging past the last and first page. async fn pagination_recovery_cursors(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let community_form = CommunityInsertForm::new( data.instance.id, @@ -1510,10 +1529,11 @@ async fn pagination_recovery_cursors(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_read(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Make sure local user hides read posts let local_user_form = LocalUserUpdateForm { @@ -1557,10 +1577,11 @@ async fn post_listings_hide_read(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_hidden(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Mark a post as hidden let hide_form = PostHideForm::new(data.bot_post.id, data.tegan.person.id); @@ -1602,10 +1623,11 @@ async fn post_listings_hide_hidden(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_nsfw(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Mark a post as nsfw let update_form = PostUpdateForm { @@ -1646,10 +1668,11 @@ async fn post_listings_hide_nsfw(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn local_only_instance(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); Community::update( pool, @@ -1694,10 +1717,11 @@ async fn local_only_instance(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_local_user_banned_from_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Test that post view shows if local user is blocked from community let banned_from_comm_person = PersonInsertForm::test_form(data.instance.id, "jill"); @@ -1737,10 +1761,11 @@ async fn post_listing_local_user_banned_from_community(data: &mut Data) -> Lemmy } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_local_user_not_banned_from_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let post_view = PostView::read( pool, @@ -1764,10 +1789,11 @@ fn micros(dt: DateTime) -> i64 { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_creator_banned(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let banned_person_form = PersonInsertForm::test_form(data.instance.id, "jill"); @@ -1814,10 +1840,11 @@ async fn post_listing_creator_banned(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_creator_community_banned(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let banned_person_form = PersonInsertForm::test_form(data.instance.id, "jarvis"); @@ -1868,10 +1895,11 @@ async fn post_listing_creator_community_banned(data: &mut Data) -> LemmyResult<( } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn speed_check(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Make sure the post_view query is less than this time let duration_max = Duration::from_millis(120); @@ -1919,10 +1947,11 @@ async fn speed_check(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Create a comment for a post let comment_form = @@ -1948,10 +1977,11 @@ async fn post_listings_no_comments_only(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_private_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Mark community as private Community::update( @@ -2046,10 +2076,11 @@ async fn post_listing_private_community(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listings_hide_media(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // Make one post an image post Post::update( @@ -2105,10 +2136,11 @@ async fn post_listings_hide_media(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_with_blocked_keywords(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let name_blocked = format!("post_{POST_KEYWORD_BLOCKED}"); let name_blocked2 = format!("post2_{POST_KEYWORD_BLOCKED}2"); @@ -2177,10 +2209,11 @@ async fn post_with_blocked_keywords(data: &mut Data) -> LemmyResult<()> { Ok(()) } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_tags_present(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); let post_view = PostView::read( pool, @@ -2204,10 +2237,11 @@ async fn post_tags_present(data: &mut Data) -> LemmyResult<()> { } #[test_context(Data)] -#[tokio::test] +#[tokio_shared_rt::test(shared = true)] async fn post_listing_multi_community(data: &mut Data) -> LemmyResult<()> { - let pool = &data.pool(); - let pool = &mut pool.into(); + let pool_arc = data.pool(); + let pool_ref = &***pool_arc; + let pool = &mut pool_ref.into(); // create two more communities with one post each let form = CommunityInsertForm::new( From ae6ac4bca1ce3197f4ba25f123fd5a4b0c13f323 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 12 Jan 2026 17:45:57 +0200 Subject: [PATCH 38/40] fix test --- crates/apub/objects/src/utils/markdown_links.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/apub/objects/src/utils/markdown_links.rs b/crates/apub/objects/src/utils/markdown_links.rs index 9300d9f3b7..2bd28d4e16 100644 --- a/crates/apub/objects/src/utils/markdown_links.rs +++ b/crates/apub/objects/src/utils/markdown_links.rs @@ -138,7 +138,6 @@ mod tests { ), ]; - let context = LemmyContext::init_test_context().await; for (msg, input, expected) in &tests { let result = markdown_rewrite_remote_links(input.clone(), &context).await; From c26ab70f00f3baccf038bf89fe56ad9f917bf5f5 Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Mon, 12 Jan 2026 21:58:40 +0200 Subject: [PATCH 39/40] some more fixes --- Cargo.lock | 1 + crates/apub/apub/src/http/community.rs | 2 +- crates/apub/objects/src/objects/person.rs | 2 +- crates/apub/send/Cargo.toml | 1 + crates/apub/send/src/lib.rs | 10 +++++----- crates/db_schema/src/impls/language.rs | 2 +- crates/db_schema/src/impls/local_site.rs | 2 +- crates/db_views/person_content_combined/src/impls.rs | 5 ++--- crates/db_views/search_combined/src/impls.rs | 5 ++--- crates/diesel_utils/src/connection.rs | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65d7c8f979..c2ff4a07ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3684,6 +3684,7 @@ dependencies = [ "serde_json", "test-context", "tokio", + "tokio-shared-rt", "tokio-util", "tracing", "tracing-test", diff --git a/crates/apub/apub/src/http/community.rs b/crates/apub/apub/src/http/community.rs index cbc458b90a..734993a476 100644 --- a/crates/apub/apub/src/http/community.rs +++ b/crates/apub/apub/src/http/community.rs @@ -369,7 +369,7 @@ pub(crate) mod tests { Ok(()) } - #[tokio_shared_rt::test(shared = true)] + #[tokio_shared_rt::test(shared = true, flavor = "multi_thread")] async fn test_outbox_deleted_user() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (data, community, path) = init(false, CommunityVisibility::Public, &context).await?; diff --git a/crates/apub/objects/src/objects/person.rs b/crates/apub/objects/src/objects/person.rs index c11aaf7a6c..66c202c1aa 100644 --- a/crates/apub/objects/src/objects/person.rs +++ b/crates/apub/objects/src/objects/person.rs @@ -219,7 +219,7 @@ pub(crate) mod tests { use lemmy_db_schema::source::instance::Instance; use pretty_assertions::assert_eq; - #[tokio_shared_rt::test(shared = true)] + #[tokio_shared_rt::test(shared = true, flavor = "multi_thread")] async fn test_parse_lemmy_person() -> LemmyResult<()> { let context = LemmyContext::init_test_context().await; let (person, _) = parse_lemmy_person(&context).await?; diff --git a/crates/apub/send/Cargo.toml b/crates/apub/send/Cargo.toml index 7371e63d5d..d7380f5577 100644 --- a/crates/apub/send/Cargo.toml +++ b/crates/apub/send/Cargo.toml @@ -54,3 +54,4 @@ tracing-test = "0.2.5" uuid.workspace = true test-context = "0.5.4" mockall = "0.14.0" +tokio-shared-rt = { workspace = true } diff --git a/crates/apub/send/src/lib.rs b/crates/apub/send/src/lib.rs index a0ba7e4e2d..b78066b86d 100644 --- a/crates/apub/send/src/lib.rs +++ b/crates/apub/send/src/lib.rs @@ -272,7 +272,7 @@ mod test { } /// Basic test with default params and only active/allowed instances - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_send_manager() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; @@ -287,7 +287,7 @@ mod test { } /// Running with multiple processes should start correct workers - #[tokio::test] + #[tokio_shared_rt::test(shared = true, flavor = "multi_thread")] async fn test_send_manager_processes() -> LemmyResult<()> { let active = Arc::new(Mutex::new(vec![])); let execute = |count, index, active: Arc>>| async move { @@ -311,7 +311,7 @@ mod test { } /// Use blocklist, should not send to blocked instances - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_send_manager_blocked() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; @@ -332,7 +332,7 @@ mod test { } /// Use allowlist, should only send to allowed instance - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_send_manager_allowed() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; @@ -352,7 +352,7 @@ mod test { } /// Mark instance as dead, there should be no worker created for it - #[tokio::test] + #[tokio_shared_rt::test(shared = true)] async fn test_send_manager_dead() -> LemmyResult<()> { let mut data = TestData::init(1, 1).await?; diff --git a/crates/db_schema/src/impls/language.rs b/crates/db_schema/src/impls/language.rs index 72bda3ea63..f899609f27 100644 --- a/crates/db_schema/src/impls/language.rs +++ b/crates/db_schema/src/impls/language.rs @@ -62,7 +62,7 @@ mod tests { use lemmy_utils::error::LemmyResult; use pretty_assertions::assert_eq; - #[tokio_shared_rt::test(shared = true)] + #[tokio_shared_rt::test(shared = true, flavor = "multi_thread")] async fn test_languages() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_schema/src/impls/local_site.rs b/crates/db_schema/src/impls/local_site.rs index 51767ea21f..14c9e0d458 100644 --- a/crates/db_schema/src/impls/local_site.rs +++ b/crates/db_schema/src/impls/local_site.rs @@ -83,7 +83,7 @@ mod tests { Ok((data, inserted_person, inserted_community)) } - #[tokio_shared_rt::test(shared = true)] + #[tokio_shared_rt::test(shared = true, flavor = "multi_thread")] async fn test_aggregates() -> LemmyResult<()> { let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); diff --git a/crates/db_views/person_content_combined/src/impls.rs b/crates/db_views/person_content_combined/src/impls.rs index 3623f3d957..c134065a5b 100644 --- a/crates/db_views/person_content_combined/src/impls.rs +++ b/crates/db_views/person_content_combined/src/impls.rs @@ -437,10 +437,9 @@ mod tests { Ok(()) } - #[tokio::test] - #[serial] + #[tokio_shared_rt::test(shared = true)] async fn private_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/db_views/search_combined/src/impls.rs b/crates/db_views/search_combined/src/impls.rs index a6b907a1de..3872b642ee 100644 --- a/crates/db_views/search_combined/src/impls.rs +++ b/crates/db_views/search_combined/src/impls.rs @@ -1266,10 +1266,9 @@ mod tests { Ok(()) } - #[tokio::test] - #[serial] + #[tokio_shared_rt::test(shared = true)] async fn private_community() -> LemmyResult<()> { - let pool = &build_db_pool_for_tests(); + let pool = &build_db_pool_for_tests().await; let pool = &mut pool.into(); let data = init_data(pool).await?; diff --git a/crates/diesel_utils/src/connection.rs b/crates/diesel_utils/src/connection.rs index a39efcb2e1..538298cad0 100644 --- a/crates/diesel_utils/src/connection.rs +++ b/crates/diesel_utils/src/connection.rs @@ -261,8 +261,8 @@ pub async fn build_db_pool_for_tests() let backend = DieselAsyncPostgresBackend::new( config, - |manager| Pool::builder(manager).max_size(SETTINGS.database.pool_size), |manager| Pool::builder(manager).max_size(2), + |manager| Pool::builder(manager).max_size(SETTINGS.database.pool_size), None, move |conn| { Box::pin(async { From 4abcc9d5a4a0df9809293a8d4fdd69ff3bc6712c Mon Sep 17 00:00:00 2001 From: momentary-lapse Date: Sat, 24 Jan 2026 20:57:46 +0200 Subject: [PATCH 40/40] using improved db-pool config accepting a connection string --- Cargo.lock | 3 ++- crates/diesel_utils/Cargo.toml | 2 +- crates/diesel_utils/src/connection.rs | 11 +---------- docker/docker-compose-test.yml | 10 ---------- scripts/start_test_db.sh | 7 ------- scripts/test.sh | 5 +++-- 6 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 docker/docker-compose-test.yml delete mode 100644 scripts/start_test_db.sh diff --git a/Cargo.lock b/Cargo.lock index 4eacbc73cd..40e9238161 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1538,7 +1538,7 @@ dependencies = [ [[package]] name = "db-pool" version = "0.6.0" -source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-test-superuser#68d84b8477059821ef82ad0bda5762106d1623bf" +source = "git+https://github.com/momentary-lapse/db-pool.git?branch=edition2021-superuser-config#ee6c96d9ca1248d41e19fcedd2db6990c9b7bebd" dependencies = [ "async-trait", "bb8", @@ -1548,6 +1548,7 @@ dependencies = [ "futures", "parking_lot", "tokio", + "url", "urlencoding", "uuid", ] diff --git a/crates/diesel_utils/Cargo.toml b/crates/diesel_utils/Cargo.toml index acee1155c5..cac8916857 100644 --- a/crates/diesel_utils/Cargo.toml +++ b/crates/diesel_utils/Cargo.toml @@ -55,7 +55,7 @@ diesel-async = { workspace = true, features = [ "postgres", "async-connection-wrapper", ], optional = true } -db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-test-superuser", features = [ +db-pool = { git = "https://github.com/momentary-lapse/db-pool.git", branch = "edition2021-superuser-config", features = [ "diesel-async-postgres", "diesel-async-deadpool", ] } diff --git a/crates/diesel_utils/src/connection.rs b/crates/diesel_utils/src/connection.rs index 538298cad0..b5149ba41a 100644 --- a/crates/diesel_utils/src/connection.rs +++ b/crates/diesel_utils/src/connection.rs @@ -51,7 +51,6 @@ use std::{ }; use tokio::sync::OnceCell; use tracing::error; -use url::Url; pub type ActualDbPool = Pool; pub type ReusableDbPool = @@ -248,16 +247,8 @@ pub async fn build_db_pool_for_tests() OnceCell::const_new(); let db_pool = POOL .get_or_init(|| async { - let conn_string = SETTINGS.get_database_url_with_options().unwrap(); - - let db_url = Url::parse(conn_string.as_str()).expect("db url"); - let config = PrivilegedPostgresConfig::new() - .host(db_url.host().expect("db host").to_string()) - .port(db_url.port().expect("db port")) - .username(db_url.username().to_string()) - .password(Some(db_url.password().expect("db password").to_string())) - .options(SETTINGS.get_lemmy_connection_options()); + .database_url(SETTINGS.get_database_url_with_options().unwrap()); let backend = DieselAsyncPostgresBackend::new( config, diff --git a/docker/docker-compose-test.yml b/docker/docker-compose-test.yml deleted file mode 100644 index 2981e35057..0000000000 --- a/docker/docker-compose-test.yml +++ /dev/null @@ -1,10 +0,0 @@ -services: - postgres: - image: pgautoupgrade/pgautoupgrade:16-alpine - ports: - # use a different port so it doesn't conflict with potential postgres db running on the host - - "5433:5432" - environment: - - POSTGRES_USER=lemmy - - POSTGRES_PASSWORD=password - - POSTGRES_DB=lemmy diff --git a/scripts/start_test_db.sh b/scripts/start_test_db.sh deleted file mode 100644 index 5c79c2b663..0000000000 --- a/scripts/start_test_db.sh +++ /dev/null @@ -1,7 +0,0 @@ -export PGUSER=lemmy -export LEMMY_DATABASE_HOST=localhost -export LEMMY_DATABASE_PORT=5433 -export LEMMY_DATABASE_URL="postgresql://lemmy:password@$LEMMY_DATABASE_HOST:$LEMMY_DATABASE_PORT/lemmy" -export PGDATABASE=lemmy - -docker-compose -f docker/docker-compose-test.yml up -d postgres diff --git a/scripts/test.sh b/scripts/test.sh index d7835034e4..85d4ea1655 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -8,7 +8,7 @@ cd "$CWD/../" PACKAGE="$1" TEST="$2" -source scripts/start_test_db.sh +source scripts/start_dev_db.sh # tests are executed in working directory crates/api (or similar), # so to load the config we need to traverse to the repo root @@ -24,4 +24,5 @@ fi # Add this to do printlns: -- --nocapture -docker-compose -f docker/docker-compose-test.yml down +pg_ctl stop --silent +rm -rf $PGDATA