diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-17 18:22:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-17 18:22:54 +0900 |
| commit | 6aa4808a0936e85384100f13e07aa7bea559bc3c (patch) | |
| tree | fe2c3008fce0825a8d74c37588ce8bece91e3df3 /crates/shirabe/tests/downloader | |
| parent | e44085eb742cb14dff22de054ef19fe725a4e2c2 (diff) | |
| download | php-shirabe-6aa4808a0936e85384100f13e07aa7bea559bc3c.tar.gz php-shirabe-6aa4808a0936e85384100f13e07aa7bea559bc3c.tar.zst php-shirabe-6aa4808a0936e85384100f13e07aa7bea559bc3c.zip | |
refactor(tests-async): unify duplicated tokio runtime bridges
11 downloader/installer integration-test files each redefined an
identical current_thread `run()` helper to block on async code. Extract
one shared multi_thread Runtime into tests/common/async_runtime.rs so
concurrent #[test] threads can all block_on it, matching the direction
item 7 (top-level Runtime) will take in production code.
Diffstat (limited to 'crates/shirabe/tests/downloader')
9 files changed, 10 insertions, 56 deletions
diff --git a/crates/shirabe/tests/downloader/download_manager_test.rs b/crates/shirabe/tests/downloader/download_manager_test.rs index f596beed..6f6ed352 100644 --- a/crates/shirabe/tests/downloader/download_manager_test.rs +++ b/crates/shirabe/tests/downloader/download_manager_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/DownloadManagerTest.php +use crate::async_runtime::run; use crate::io_stub::IOStub; use indexmap::IndexMap; use shirabe::downloader::DownloaderInterface; @@ -58,13 +59,6 @@ mockall::mock! { } } -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - /// ref: DownloadManagerTest::createPackageMock /// /// PHPUnit returns a `PackageInterface` mock; a real CompletePackage with the diff --git a/crates/shirabe/tests/downloader/file_downloader_test.rs b/crates/shirabe/tests/downloader/file_downloader_test.rs index e2b19958..a9af69ed 100644 --- a/crates/shirabe/tests/downloader/file_downloader_test.rs +++ b/crates/shirabe/tests/downloader/file_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/FileDownloaderTest.php +use crate::async_runtime::run; use crate::http_downloader_mock::get_http_downloader_mock; use crate::io_mock::{Expectation, get_io_mock}; use indexmap::IndexMap; @@ -28,13 +29,6 @@ fn get_package(name: &str, version: &str) -> PackageInterfaceHandle { CompletePackageHandle::new(name.to_string(), norm_version, version.to_string()).into() } -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - /// ref: TestCase::getConfig fn get_config( config_options: IndexMap<String, PhpMixed>, diff --git a/crates/shirabe/tests/downloader/fossil_downloader_test.rs b/crates/shirabe/tests/downloader/fossil_downloader_test.rs index eed3d7fb..e473b2dd 100644 --- a/crates/shirabe/tests/downloader/fossil_downloader_test.rs +++ b/crates/shirabe/tests/downloader/fossil_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/FossilDownloaderTest.php +use crate::async_runtime::run; use crate::config_stub::ConfigStubBuilder; use crate::io_stub::IOStub; use crate::process_executor_mock::get_process_executor_mock; @@ -14,13 +15,6 @@ use shirabe_php_shim::PhpMixed; use shirabe_semver::VersionParser; use tempfile::TempDir; -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - fn set_up() -> TempDir { TempDir::new().unwrap() } diff --git a/crates/shirabe/tests/downloader/git_downloader_test.rs b/crates/shirabe/tests/downloader/git_downloader_test.rs index a73958b4..d4f40b77 100644 --- a/crates/shirabe/tests/downloader/git_downloader_test.rs +++ b/crates/shirabe/tests/downloader/git_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/GitDownloaderTest.php +use crate::async_runtime::run; use crate::config_stub::ConfigStubBuilder; use crate::io_mock::{Expectation, get_io_mock}; use crate::io_stub::IOStub; @@ -20,13 +21,6 @@ use shirabe_php_shim::PhpMixed; use shirabe_semver::VersionParser; use tempfile::TempDir; -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - fn set_up() -> TempDir { // skipIfNotExecutable('git') is irrelevant because every git invocation is mocked. diff --git a/crates/shirabe/tests/downloader/hg_downloader_test.rs b/crates/shirabe/tests/downloader/hg_downloader_test.rs index d68812d8..ac3d50b6 100644 --- a/crates/shirabe/tests/downloader/hg_downloader_test.rs +++ b/crates/shirabe/tests/downloader/hg_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/HgDownloaderTest.php +use crate::async_runtime::run; use crate::io_stub::IOStub; use crate::process_executor_mock::{cmd, get_process_executor_mock}; use shirabe::config::Config; @@ -12,13 +13,6 @@ use shirabe::util::filesystem::{Filesystem, FilesystemMock}; use shirabe_semver::VersionParser; use tempfile::TempDir; -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - fn set_up() -> TempDir { TempDir::new().unwrap() } diff --git a/crates/shirabe/tests/downloader/main.rs b/crates/shirabe/tests/downloader/main.rs index 82440108..88f16266 100644 --- a/crates/shirabe/tests/downloader/main.rs +++ b/crates/shirabe/tests/downloader/main.rs @@ -1,3 +1,5 @@ +#[path = "../common/async_runtime.rs"] +mod async_runtime; #[path = "../common/config_stub.rs"] mod config_stub; #[path = "../common/http_downloader_mock.rs"] diff --git a/crates/shirabe/tests/downloader/perforce_downloader_test.rs b/crates/shirabe/tests/downloader/perforce_downloader_test.rs index 13a818a6..bdf24a2e 100644 --- a/crates/shirabe/tests/downloader/perforce_downloader_test.rs +++ b/crates/shirabe/tests/downloader/perforce_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +use crate::async_runtime::run; use crate::io_mock::{Expectation, get_io_mock}; use crate::io_stub::IOStub; use crate::process_executor_mock::get_process_executor_mock; @@ -42,13 +43,6 @@ mockall::mock! { } } -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - /// ref: PerforceDownloaderTest::getConfig (seeds `home` with the temp dir) fn get_config(test_path: &std::path::Path) -> Config { let mut config = Config::new(true, None); diff --git a/crates/shirabe/tests/downloader/xz_downloader_test.rs b/crates/shirabe/tests/downloader/xz_downloader_test.rs index 6d504313..0002f0e6 100644 --- a/crates/shirabe/tests/downloader/xz_downloader_test.rs +++ b/crates/shirabe/tests/downloader/xz_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/XzDownloaderTest.php +use crate::async_runtime::run; use indexmap::IndexMap; use shirabe::config::Config; use shirabe::downloader::DownloaderInterface; @@ -22,13 +23,6 @@ fn get_package(name: &str, version: &str) -> PackageInterfaceHandle { CompletePackageHandle::new(name.to_string(), norm_version, version.to_string()).into() } -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - /// ref: setUp markTestSkipped on Windows / 32bit, expressed as a compile-time /// cfg gate on the test function below. fn set_up() -> TempDir { diff --git a/crates/shirabe/tests/downloader/zip_downloader_test.rs b/crates/shirabe/tests/downloader/zip_downloader_test.rs index b8fddf68..878c8054 100644 --- a/crates/shirabe/tests/downloader/zip_downloader_test.rs +++ b/crates/shirabe/tests/downloader/zip_downloader_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Downloader/ZipDownloaderTest.php +use crate::async_runtime::run; use crate::io_stub::IOStub; use indexmap::IndexMap; use serial_test::serial; @@ -17,13 +18,6 @@ use shirabe_php_shim::{PhpMixed, ZipArchive, ZipArchiveMock}; use shirabe_semver::VersionParser; use tempfile::TempDir; -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - struct SetUp { test_dir: TempDir, io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, |
