Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1443731
draft: using db-pool form a 2021 branch
momentary-lapse Jul 4, 2025
55d010d
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Jul 11, 2025
91613fb
fix
momentary-lapse Jul 11, 2025
618f635
some renaming
momentary-lapse Jul 11, 2025
ef155c5
reusable pool integrated except everywhere, some tests adapted
momentary-lapse Jul 14, 2025
f949aea
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Jul 14, 2025
6b13d21
generic pool in context and stat modules, now it compiles
momentary-lapse Jul 15, 2025
8528a7f
Merge branch 'main' into parallel-db-tests
momentary-lapse Jul 15, 2025
e90c8be
fix taplo
momentary-lapse Jul 16, 2025
5d6fe0c
clippy fix
momentary-lapse Jul 16, 2025
906c36a
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Jul 19, 2025
418e91b
clippy fix
momentary-lapse Jul 19, 2025
fe3305b
fmt fix
momentary-lapse Jul 20, 2025
a95ad45
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Jul 23, 2025
4377da8
shear fix
momentary-lapse Jul 23, 2025
e18c7f7
clippy + shear fixes
momentary-lapse Jul 23, 2025
5264ab1
fmt fix
momentary-lapse Jul 23, 2025
9db404d
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Jul 27, 2025
6e795ea
fix merge issues
momentary-lapse Jul 27, 2025
603efb3
config forrunning new tests locally
momentary-lapse Jul 27, 2025
0d59fcf
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Aug 7, 2025
1fbe5f4
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Aug 11, 2025
64bc9e6
removing the rest of serial tests
momentary-lapse Aug 12, 2025
6534cbc
fmt
momentary-lapse Aug 12, 2025
12037df
excluding serial_test dep
momentary-lapse Aug 12, 2025
b8c2836
fix
momentary-lapse Aug 13, 2025
aadfcca
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Aug 15, 2025
99f4f03
Merge branch 'main' of github.com:LemmyNet/lemmy into parallel-db-tests
momentary-lapse Aug 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ lemmy_db_views_vote = { version = "=1.0.0-alpha.5", path = "./crates/db_views/vo
activitypub_federation = { version = "0.7.0-beta.5", default-features = false, features = [
"actix-web",
] }
diesel = { version = "2.2.10", features = [
diesel = { version = "2.2.11", features = [
"chrono",
"postgres",
"serde_json",
Expand Down
22 changes: 16 additions & 6 deletions crates/api/api_utils/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the moment which currently blocks me, and i think it's better to consult with you again. LemmyContext structure must be cloneable, therefore all the fields, therefore the pool. But unfortunately, reusable pool from db-pool crate is not, and i don't have access to its fields to implement the trait here.
But before asking db-pool developer, i'd like to be sure we really need this pool cloning stuff, especially for the tests. Cloning the pool seems a bit strange to me, but i may miss something. I'm looking at the code now, but maybe you folks already have some insights on this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap it in Arc for now.

client: Arc<ClientWithMiddleware>,
/// 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.
Expand All @@ -24,7 +31,7 @@ pub struct LemmyContext {

impl LemmyContext {
pub fn create(
pool: ActualDbPool,
pool: ContextPool,
client: ClientWithMiddleware,
pictrs_client: ClientWithMiddleware,
secret: Secret,
Expand All @@ -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 {
Expand All @@ -66,7 +76,7 @@ impl LemmyContext {
#[allow(clippy::expect_used)]
pub async fn init_test_federation_config() -> FederationConfig<LemmyContext> {
// 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");

Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/db_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 }
Expand All @@ -75,6 +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-test", features = ["diesel-async-postgres", "diesel-async-deadpool"] }


[dev-dependencies]
Expand Down
6 changes: 2 additions & 4 deletions crates/db_schema/src/impls/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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!({
Expand Down
18 changes: 6 additions & 12 deletions crates/db_schema/src/impls/actor_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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?;
Expand All @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
6 changes: 2 additions & 4 deletions crates/db_schema/src/impls/captcha_answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions crates/db_schema/src/impls/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
6 changes: 2 additions & 4 deletions crates/db_schema/src/impls/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
3 changes: 1 addition & 2 deletions crates/db_schema/src/impls/federation_allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
3 changes: 1 addition & 2 deletions crates/db_schema/src/impls/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
6 changes: 2 additions & 4 deletions crates/db_schema/src/impls/local_site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
6 changes: 2 additions & 4 deletions crates/db_schema/src/impls/local_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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 = "[email protected]";
Expand Down
3 changes: 1 addition & 2 deletions crates/db_schema/src/impls/mod_log/moderator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
3 changes: 1 addition & 2 deletions crates/db_schema/src/impls/multi_community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
3 changes: 1 addition & 2 deletions crates/db_schema/src/impls/password_reset_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading