From 1172d92e9cd14d04202c64186a699367d1286610 Mon Sep 17 00:00:00 2001 From: Joshua Potts <8704475+iamjpotts@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:06:53 -0500 Subject: [PATCH] Refactor async test cases to use actix_rt macro --- ipfs-api/tests/test_basic_auth.rs | 8 ++------ ipfs-api/tests/test_get_version.rs | 8 ++------ ipfs-api/tests/test_support/lib.rs | 1 - ipfs-api/tests/test_support/rt.rs | 17 ----------------- 4 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 ipfs-api/tests/test_support/rt.rs diff --git a/ipfs-api/tests/test_basic_auth.rs b/ipfs-api/tests/test_basic_auth.rs index feaeca7..3f01f07 100644 --- a/ipfs-api/tests/test_basic_auth.rs +++ b/ipfs-api/tests/test_basic_auth.rs @@ -11,16 +11,12 @@ mod test_support; use test_support::client::{build_client, wait_for_server}; use test_support::container::{IpfsContainer, NginxContainer}; use test_support::images; -use test_support::rt::run_async; use ipfs_api_versions::test_current_image; #[test_current_image] -fn test_basic_auth(image_name: &str, image_tag: &str) { - run_async(run_test(image_name, image_tag)); -} - -async fn run_test(image_name: &str, image_tag: &str) { +#[actix_rt::test] +async fn test_basic_auth(image_name: &str, image_tag: &str) { let expected_version = images::extract_version(image_tag); let container = IpfsContainer::new("test_basic_auth_ipfs", image_name, image_tag) diff --git a/ipfs-api/tests/test_get_version.rs b/ipfs-api/tests/test_get_version.rs index 832d27f..0ab2aef 100644 --- a/ipfs-api/tests/test_get_version.rs +++ b/ipfs-api/tests/test_get_version.rs @@ -11,16 +11,12 @@ mod test_support; use test_support::client::{build_client, wait_for_server}; use test_support::container::IpfsContainer; use test_support::images; -use test_support::rt::run_async; use ipfs_api_versions::test_supported_images; #[test_supported_images] -fn test_get_version(image_name: &str, image_tag: &str) { - run_async(run_test(image_name, image_tag)); -} - -async fn run_test(image_name: &str, image_tag: &str) { +#[actix_rt::test] +async fn test_get_version(image_name: &str, image_tag: &str) { let expected_version = images::extract_version(image_tag); let container_name = format!("test_get_version_{}", expected_version.replace('.', "-")); diff --git a/ipfs-api/tests/test_support/lib.rs b/ipfs-api/tests/test_support/lib.rs index 09806d6..bf36950 100644 --- a/ipfs-api/tests/test_support/lib.rs +++ b/ipfs-api/tests/test_support/lib.rs @@ -14,4 +14,3 @@ pub mod client; pub mod container; pub mod errors; pub mod images; -pub mod rt; diff --git a/ipfs-api/tests/test_support/rt.rs b/ipfs-api/tests/test_support/rt.rs deleted file mode 100644 index 62bbbf1..0000000 --- a/ipfs-api/tests/test_support/rt.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022 rust-ipfs-api Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -use std::future::Future; - -/// Hyper tests can use [tokio::test] but Actix can't due to LocalSet requirement. -pub fn run_async(f: F) { - let rt = tokio::runtime::Runtime::new().unwrap(); - - // Actix requires LocalSet. Hyper doesn't care. - let local = tokio::task::LocalSet::new(); - local.block_on(&rt, f); -}