From ab1450c655f7fdfc214e1556d16fc754ca684613 Mon Sep 17 00:00:00 2001 From: jk Date: Wed, 31 Jan 2024 15:13:52 +0100 Subject: test: replace block_on with tokio::tests This is intended to improve the reliabilty of the tests. there have been particular issues with random tests never ending when run in the nix configuration see discussion here https://github.com/DanConwayDev/ngit-cli/issues/ 6#issuecomment-1918971239 and: https://github.com/DanConwayDev/ngit-cli/pull/7 --- tests/prs_list.rs | 85 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'tests/prs_list.rs') diff --git a/tests/prs_list.rs b/tests/prs_list.rs index 7f753c0..75704f6 100644 --- a/tests/prs_list.rs +++ b/tests/prs_list.rs @@ -226,17 +226,18 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn prompts_to_choose_from_pr_titles() -> Result<()> { - futures::executor::block_on(run_async_prompts_to_choose_from_pr_titles()) + async fn prompts_to_choose_from_pr_titles() -> Result<()> { + let _ = run_async_prompts_to_choose_from_pr_titles().await; + Ok(()) } } - #[test] + #[tokio::test] #[serial] - fn pr_branch_created_with_correct_name() -> Result<()> { - let (_, test_repo) = futures::executor::block_on(prep_and_run())?; + async fn pr_branch_created_with_correct_name() -> Result<()> { + let (_, test_repo) = prep_and_run().await?; assert_eq!( vec![FEATURE_BRANCH_NAME_1, "main"], test_repo.get_local_branch_names()? @@ -244,10 +245,10 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn pr_branch_checked_out() -> Result<()> { - let (_, test_repo) = futures::executor::block_on(prep_and_run())?; + async fn pr_branch_checked_out() -> Result<()> { + let (_, test_repo) = prep_and_run().await?; assert_eq!( FEATURE_BRANCH_NAME_1, test_repo.get_checked_out_branch_name()?, @@ -255,11 +256,10 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn pr_branch_tip_is_most_recent_patch() -> Result<()> { - let (originating_repo, test_repo) = - futures::executor::block_on(prep_and_run())?; + async fn pr_branch_tip_is_most_recent_patch() -> Result<()> { + let (originating_repo, test_repo) = prep_and_run().await?; assert_eq!( originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, @@ -391,17 +391,18 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn prompts_to_choose_from_pr_titles() -> Result<()> { - futures::executor::block_on(run_async_prompts_to_choose_from_pr_titles()) + async fn prompts_to_choose_from_pr_titles() -> Result<()> { + let _ = run_async_prompts_to_choose_from_pr_titles().await; + Ok(()) } } - #[test] + #[tokio::test] #[serial] - fn pr_branch_created_with_correct_name() -> Result<()> { - let (_, test_repo) = futures::executor::block_on(prep_and_run())?; + async fn pr_branch_created_with_correct_name() -> Result<()> { + let (_, test_repo) = prep_and_run().await?; assert_eq!( vec![FEATURE_BRANCH_NAME_3, "main"], test_repo.get_local_branch_names()? @@ -409,10 +410,10 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn pr_branch_checked_out() -> Result<()> { - let (_, test_repo) = futures::executor::block_on(prep_and_run())?; + async fn pr_branch_checked_out() -> Result<()> { + let (_, test_repo) = prep_and_run().await?; assert_eq!( FEATURE_BRANCH_NAME_3, test_repo.get_checked_out_branch_name()?, @@ -420,11 +421,10 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn pr_branch_tip_is_most_recent_patch() -> Result<()> { - let (originating_repo, test_repo) = - futures::executor::block_on(prep_and_run())?; + async fn pr_branch_tip_is_most_recent_patch() -> Result<()> { + let (originating_repo, test_repo) = prep_and_run().await?; assert_eq!( originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, @@ -579,17 +579,18 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn prompts_to_choose_from_pr_titles() -> Result<()> { - futures::executor::block_on(run_async_prompts_to_choose_from_pr_titles()) + async fn prompts_to_choose_from_pr_titles() -> Result<()> { + let _ = run_async_prompts_to_choose_from_pr_titles().await; + Ok(()) } } - #[test] + #[tokio::test] #[serial] - fn pr_branch_checked_out() -> Result<()> { - let (_, test_repo) = futures::executor::block_on(prep_and_run())?; + async fn pr_branch_checked_out() -> Result<()> { + let (_, test_repo) = prep_and_run().await?; assert_eq!( FEATURE_BRANCH_NAME_1, test_repo.get_checked_out_branch_name()?, @@ -738,17 +739,18 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn prompts_to_choose_from_pr_titles() -> Result<()> { - futures::executor::block_on(run_async_prompts_to_choose_from_pr_titles()) + async fn prompts_to_choose_from_pr_titles() -> Result<()> { + let _ = run_async_prompts_to_choose_from_pr_titles().await; + Ok(()) } } - #[test] + #[tokio::test] #[serial] - fn pr_branch_checked_out() -> Result<()> { - let (_, test_repo) = futures::executor::block_on(prep_and_run())?; + async fn pr_branch_checked_out() -> Result<()> { + let (_, test_repo) = prep_and_run().await?; assert_eq!( FEATURE_BRANCH_NAME_1, test_repo.get_checked_out_branch_name()?, @@ -756,11 +758,10 @@ mod when_main_branch_is_uptodate { Ok(()) } - #[test] + #[tokio::test] #[serial] - fn pr_branch_tip_is_most_recent_patch() -> Result<()> { - let (originating_repo, test_repo) = - futures::executor::block_on(prep_and_run())?; + async fn pr_branch_tip_is_most_recent_patch() -> Result<()> { + let (originating_repo, test_repo) = prep_and_run().await?; assert_eq!( originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, -- cgit v1.2.3