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/installer | |
| 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/installer')
4 files changed, 5 insertions, 21 deletions
diff --git a/crates/shirabe/tests/installer/installation_manager_test.rs b/crates/shirabe/tests/installer/installation_manager_test.rs index f60d1250..e24f440c 100644 --- a/crates/shirabe/tests/installer/installation_manager_test.rs +++ b/crates/shirabe/tests/installer/installation_manager_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Installer/InstallationManagerTest.php +use crate::async_runtime::run; use crate::test_case::get_package; use shirabe::dependency_resolver::operation::{ InstallOperation, UninstallOperation, UpdateOperation, @@ -15,13 +16,6 @@ use shirabe::util::r#loop::Loop; use shirabe_php_shim::PhpMixed; use shirabe_semver::VersionParser; -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - /// ref: setUp(): the PHP loop/io mocks are never exercised by these tests (the loop has its /// constructor disabled), so a real Loop over a real HttpDownloader and a NullIO stand in. struct SetUp { diff --git a/crates/shirabe/tests/installer/library_installer_test.rs b/crates/shirabe/tests/installer/library_installer_test.rs index 72272a07..f2a94cbf 100644 --- a/crates/shirabe/tests/installer/library_installer_test.rs +++ b/crates/shirabe/tests/installer/library_installer_test.rs @@ -1,5 +1,6 @@ //! ref: composer/tests/Composer/Test/Installer/LibraryInstallerTest.php +use crate::async_runtime::run; use crate::test_case::get_package; use indexmap::IndexMap; use shirabe::composer::{ @@ -87,13 +88,6 @@ mockall::mock! { } } -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - /// Mirror of setUp(): builds the Composer/Config over temp root/vendor/bin dirs plus a NullIO and a /// DownloadManager mock. `composer_full` keeps the inner Rc alive for the duration of the test since /// LibraryInstaller only holds a weak handle, and lets tests swap in a configured DownloadManager diff --git a/crates/shirabe/tests/installer/main.rs b/crates/shirabe/tests/installer/main.rs index 4b422780..b3641108 100644 --- a/crates/shirabe/tests/installer/main.rs +++ b/crates/shirabe/tests/installer/main.rs @@ -1,3 +1,5 @@ +#[path = "../common/async_runtime.rs"] +mod async_runtime; #[path = "../common/io_mock.rs"] mod io_mock; #[path = "../common/test_case.rs"] diff --git a/crates/shirabe/tests/installer/metapackage_installer_test.rs b/crates/shirabe/tests/installer/metapackage_installer_test.rs index bc740e74..3380befb 100644 --- a/crates/shirabe/tests/installer/metapackage_installer_test.rs +++ b/crates/shirabe/tests/installer/metapackage_installer_test.rs @@ -3,19 +3,13 @@ //! PHP verifies the mocked repository's add/remove/hasPackage calls; here the same //! behaviour is checked against a real InstalledArrayRepository by observing its state. +use crate::async_runtime::run; use crate::test_case::get_package; use shirabe::installer::{InstallerInterface, MetapackageInstaller}; use shirabe::io::IOInterface; use shirabe::io::null_io::NullIO; use shirabe::repository::{InstalledArrayRepository, RepositoryInterface}; -fn run<F: std::future::Future>(future: F) -> F::Output { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(future) -} - fn installer() -> MetapackageInstaller { let io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = std::rc::Rc::new(std::cell::RefCell::new(NullIO::new())); |
