Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: refactor service tests as standalone #249

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion src/models/post/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod tests {
const REPLY_ID: &str = "2ZECXVXHZBE00";
const POST_ID: &str = "2ZECRNM66G900";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_post_details_get_from_graph() {
// Open connections against ddbb
let config = Config::from_env();
Expand Down
2 changes: 1 addition & 1 deletion src/models/user/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod tests {
"not_existing_user_id_either", // Does not exist
];

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_get_by_ids_from_redis() {
let config = Config::from_env();
setup(&config).await;
Expand Down
1 change: 1 addition & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod service;
pub mod utils;
pub mod watcher;
8 changes: 4 additions & 4 deletions tests/service/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde_json::json;

const HOST_URL: &str = "http://localhost:8080";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_static_serving() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;
let test_file_path = "static";
Expand Down Expand Up @@ -48,7 +48,7 @@ async fn test_static_serving() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_file_details() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;
let test_file_id = "2ZK2H8P2T5NG0";
Expand All @@ -74,7 +74,7 @@ async fn test_file_details() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_files_by_ids() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;
let test_file_id = "2ZK2H8P2T5NG0";
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn test_files_by_ids() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_get_post() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;

Expand Down
6 changes: 3 additions & 3 deletions tests/service/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;

const HOST_URL: &str = "http://localhost:8080";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_swagger_ui() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;

Expand All @@ -14,7 +14,7 @@ async fn test_swagger_ui() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_openapi_schema() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;

Expand All @@ -30,7 +30,7 @@ async fn test_openapi_schema() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_info_endpoint() -> Result<()> {
let client = httpc_test::new_client(HOST_URL)?;

Expand Down
2 changes: 1 addition & 1 deletion tests/service/stream/post/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{ROOT_PATH, USER_ID};
use crate::service::utils::make_request;
use anyhow::Result;

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_user_posts() -> Result<()> {
let path = format!(
"{ROOT_PATH}?author_id={}&source=author&sorting=timeline",
Expand Down
2 changes: 1 addition & 1 deletion tests/service/stream/post/author_replies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ROOT_PATH;
use crate::service::utils::make_request;
use anyhow::Result;

#[tokio::test]
#[tokio_shared_rt::test(shared)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are the benefits for service tests of using the shared tokio runtime?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not using it can cause conflict when using the connectors.

async fn test_stream_user_replies() -> Result<()> {
let author_id = "pxnu33x7jtpx9ar1ytsi4yxbp6a5o36gwhffs8zoxmbuptici1jy";
let path = format!(
Expand Down
8 changes: 4 additions & 4 deletions tests/service/stream/post/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::Result;
// User with most bookmarks
const BOOKMARKER_ID: &str = "o1gg96ewuojmopcjbz8895478wdtxtzzuxnfjjz8o8e77csa1ngo";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_bookmarked_posts() -> Result<()> {
let observer_id = BOOKMARKER_ID;
let path = format!("{ROOT_PATH}?observer_id={}&source=bookmarks", observer_id);
Expand Down Expand Up @@ -40,7 +40,7 @@ pub const POST_TK: &str = "2ZAX1DBDD5YG0";
pub const START_TIMELINE: &str = "1724134149050";
pub const END_TIMELINE: &str = "1724134141150";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_user_bookmarks_by_timeline_with_start() -> Result<()> {
let path =
format!("{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&start={START_TIMELINE}");
Expand All @@ -54,7 +54,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_start() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_user_bookmarks_by_timeline_with_start_and_end() -> Result<()> {
let path = format!(
"{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&start={START_TIMELINE}&end={END_TIMELINE}"
Expand All @@ -69,7 +69,7 @@ async fn test_stream_user_bookmarks_by_timeline_with_start_and_end() -> Result<(
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_user_bookmarks_by_timeline_with_skip_end() -> Result<()> {
let path = format!(
"{ROOT_PATH}?observer_id={BOOKMARKER_ID}&source=bookmarks&limit=5&end={END_TIMELINE}"
Expand Down
6 changes: 3 additions & 3 deletions tests/service/stream/post/kind/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const END_TIMELINE: &str = "1980477299303";
pub const PUBKY_TAG: &str = "pubky";
pub const FK_TAG: &str = "4k";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind() -> Result<()> {
let path = format!("{ROOT_PATH}?author_id={BOGOTA}&source=author");

Expand All @@ -38,7 +38,7 @@ async fn test_stream_post_kind() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_with_start_and_end() -> Result<()> {
let path = format!(
"{ROOT_PATH}?author_id={BOGOTA}&source=author&start={START_TIMELINE}&end={END_TIMELINE}"
Expand All @@ -51,7 +51,7 @@ async fn test_stream_post_kind_with_start_and_end() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_with_tag() -> Result<()> {
let path = format!("{ROOT_PATH}?author_id={BOGOTA}&source=author&tags={PUBKY_TAG}");

Expand Down
24 changes: 12 additions & 12 deletions tests/service/stream/post/kind/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const POST_F8: &str = "GJMW1TGL5BKG1";
pub const START_TIMELINE: &str = "1980477299345";
pub const END_TIMELINE: &str = "1980477299309";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_file_post_kind() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}");

Expand All @@ -32,7 +32,7 @@ async fn test_stream_file_post_kind() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_file_post_kind_with_start() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}");

Expand All @@ -43,7 +43,7 @@ async fn test_stream_file_post_kind_with_start() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_file_post_kind_with_end() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}");

Expand All @@ -54,7 +54,7 @@ async fn test_stream_file_post_kind_with_end() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_file_post_kind_with_start_and_end() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}");

Expand All @@ -65,7 +65,7 @@ async fn test_stream_file_post_kind_with_start_and_end() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_file_post_kind_with_author() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author");

Expand All @@ -76,7 +76,7 @@ async fn test_stream_file_post_kind_with_author() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_file_post_kind_with_author_skip_and_limit() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1");

Expand All @@ -89,7 +89,7 @@ async fn test_stream_file_post_kind_with_author_skip_and_limit() -> Result<()> {

// ##### REACH: FOLLOWERS ####

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_followers() -> Result<()> {
let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}");

Expand All @@ -102,7 +102,7 @@ async fn test_stream_post_kind_followers() -> Result<()> {

const REACH_START_TIMELINE: &str = "1980477299360";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_followers_with_start() -> Result<()> {
let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}");

Expand All @@ -115,7 +115,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> {

// ##### REACH: FOLLOWING ####

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_following() -> Result<()> {
let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}");

Expand All @@ -126,7 +126,7 @@ async fn test_stream_post_kind_following() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_following_with_start() -> Result<()> {
let path = format!(
"{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1980477299325"
Expand All @@ -141,7 +141,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> {

// ##### REACH: FRIENDS ####

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_friends() -> Result<()> {
let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}");

Expand All @@ -152,7 +152,7 @@ async fn test_stream_post_kind_friends() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_friends_with_start() -> Result<()> {
let path = format!(
"{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"
Expand Down
24 changes: 12 additions & 12 deletions tests/service/stream/post/kind/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const POST_I8: &str = "5YCW1TGL5BKG1";
pub const START_TIMELINE: &str = "1820477299345";
pub const END_TIMELINE: &str = "1820477299308";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_image_post_kind() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}");

Expand All @@ -32,7 +32,7 @@ async fn test_stream_image_post_kind() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_image_post_kind_with_start() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}");

Expand All @@ -43,7 +43,7 @@ async fn test_stream_image_post_kind_with_start() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_image_post_kind_with_end() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&end={START_TIMELINE}");

Expand All @@ -54,7 +54,7 @@ async fn test_stream_image_post_kind_with_end() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_image_post_kind_with_start_and_end() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&start={START_TIMELINE}&end={END_TIMELINE}");

Expand All @@ -65,7 +65,7 @@ async fn test_stream_image_post_kind_with_start_and_end() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_image_post_kind_with_author() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author");

Expand All @@ -76,7 +76,7 @@ async fn test_stream_image_post_kind_with_author() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_image_post_kind_with_author_skip_and_limit() -> Result<()> {
let path = format!("{ROOT_PATH}?kind={KIND}&author_id={BOGOTA}&source=author&skip=1&limit=1");

Expand All @@ -89,7 +89,7 @@ async fn test_stream_image_post_kind_with_author_skip_and_limit() -> Result<()>

// ##### REACH: FOLLOWING ####

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_followers() -> Result<()> {
let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}");

Expand All @@ -102,7 +102,7 @@ async fn test_stream_post_kind_followers() -> Result<()> {

const REACH_START_TIMELINE: &str = "1820477299355";

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_followers_with_start() -> Result<()> {
let path = format!("{ROOT_PATH}?source=followers&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}");

Expand All @@ -115,7 +115,7 @@ async fn test_stream_post_kind_followers_with_start() -> Result<()> {

// ##### REACH: FOLLOWING ####

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_following() -> Result<()> {
let path = format!("{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}");

Expand All @@ -126,7 +126,7 @@ async fn test_stream_post_kind_following() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_following_with_start() -> Result<()> {
let path = format!(
"{ROOT_PATH}?source=following&observer_id={AMSTERDAM}&kind={KIND}&start=1820477299325"
Expand All @@ -141,7 +141,7 @@ async fn test_stream_post_kind_following_with_start() -> Result<()> {

// ##### REACH: FRIENDS ####

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_friends() -> Result<()> {
let path = format!("{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}");

Expand All @@ -152,7 +152,7 @@ async fn test_stream_post_kind_friends() -> Result<()> {
Ok(())
}

#[tokio::test]
#[tokio_shared_rt::test(shared)]
async fn test_stream_post_kind_friends_with_start() -> Result<()> {
let path = format!(
"{ROOT_PATH}?source=friends&observer_id={DETROIT}&kind={KIND}&start={REACH_START_TIMELINE}"
Expand Down
Loading
Loading