Skip to content

Commit

Permalink
Fix startup errors, add unit test for scheduled task errors (fixes L…
Browse files Browse the repository at this point in the history
…emmyNet#5209)  (LemmyNet#5269)

* Fix startup errors, add ci check (fixes LemmyNet#5209)

* normal unit test

* cleanup

* shear

* remove serial

* migration
  • Loading branch information
Nutomic authored Dec 21, 2024
1 parent 6015ef0 commit 7585aac
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 363 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ tracing = { workspace = true }
tracing-actix-web = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
reqwest-tracing = { workspace = true }
clokwerk = { workspace = true }
Expand Down
36 changes: 18 additions & 18 deletions crates/db_schema/replaceable_schema/utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,26 @@ BEGIN
AND pe.bot_account = FALSE
UNION
SELECT
pl.person_id,
pa.person_id,
p.community_id
FROM
post_like pl
INNER JOIN post p ON pl.post_id = p.id
INNER JOIN person pe ON pl.person_id = pe.id
post_actions pa
INNER JOIN post p ON pa.post_id = p.id
INNER JOIN person pe ON pa.person_id = pe.id
WHERE
pl.published > ('now'::timestamp - i::interval)
pa.liked > ('now'::timestamp - i::interval)
AND pe.bot_account = FALSE
UNION
SELECT
cl.person_id,
ca.person_id,
p.community_id
FROM
comment_like cl
INNER JOIN comment c ON cl.comment_id = c.id
comment_actions ca
INNER JOIN comment c ON ca.comment_id = c.id
INNER JOIN post p ON c.post_id = p.id
INNER JOIN person pe ON cl.person_id = pe.id
INNER JOIN person pe ON ca.person_id = pe.id
WHERE
cl.published > ('now'::timestamp - i::interval)
ca.liked > ('now'::timestamp - i::interval)
AND pe.bot_account = FALSE) a
GROUP BY
community_id;
Expand Down Expand Up @@ -244,22 +244,22 @@ BEGIN
AND pe.bot_account = FALSE
UNION
SELECT
pl.person_id
pa.person_id
FROM
post_like pl
INNER JOIN person pe ON pl.person_id = pe.id
post_actions pa
INNER JOIN person pe ON pa.person_id = pe.id
WHERE
pl.published > ('now'::timestamp - i::interval)
pa.liked > ('now'::timestamp - i::interval)
AND pe.local = TRUE
AND pe.bot_account = FALSE
UNION
SELECT
cl.person_id
ca.person_id
FROM
comment_like cl
INNER JOIN person pe ON cl.person_id = pe.id
comment_actions ca
INNER JOIN person pe ON ca.person_id = pe.id
WHERE
cl.published > ('now'::timestamp - i::interval)
ca.liked > ('now'::timestamp - i::interval)
AND pe.local = TRUE
AND pe.bot_account = FALSE) a;
RETURN count_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT
1;

3 changes: 3 additions & 0 deletions migrations/2024-12-20-090225_update-replaceable-schema/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT
1;

15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,18 @@ fn cors_config(settings: &Settings) -> Cors {
_ => cors_default,
}
}

#[cfg(test)]
pub mod tests {
use activitypub_federation::config::Data;
use lemmy_api_common::context::LemmyContext;
use std::env::set_current_dir;

pub async fn test_context() -> Data<LemmyContext> {
// hack, necessary so that config file can be loaded from hardcoded, relative path.
// Ignore errors as this gets called once for every test (so changing dir again would fail).
set_current_dir("crates/utils").ok();

LemmyContext::init_test_context().await
}
}
Loading

0 comments on commit 7585aac

Please sign in to comment.