Skip to content

Commit

Permalink
Merge pull request #2214 from fermyon/remove-services
Browse files Browse the repository at this point in the history
Don't pass services when constructing Spin instance in runtime test
  • Loading branch information
rylev authored Jan 8, 2024
2 parents 638798a + 3e0045b commit a69161f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 4 additions & 2 deletions tests/runtime-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use anyhow::Context;
use services::Services;

/// A callback to create a runtime given a path to a temporary directory and a set of services
pub type RuntimeCreator = dyn Fn(&Path, &mut Services) -> anyhow::Result<Box<dyn Runtime>>;
pub type RuntimeCreator = dyn Fn(&Path) -> anyhow::Result<Box<dyn Runtime>>;

/// Configuration for the test suite
pub struct Config {
Expand Down Expand Up @@ -63,7 +63,9 @@ pub fn bootstrap_and_run(test_path: &Path, config: &Config) -> anyhow::Result<()
log::trace!("Temporary directory: {}", temp.path().display());
let mut services = services::start_services(test_path)?;
copy_manifest(test_path, &temp, &mut services)?;
let runtime = &mut *(config.create_runtime)(temp.path(), &mut services)?;
services.error().context("services have failed")?;
let runtime = &mut *(config.create_runtime)(temp.path())?;
services.error().context("services have failed")?;
run_test(runtime, test_path, config.on_error);
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/runtime-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fn main() -> anyhow::Result<()> {
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests"));

let config = Config {
create_runtime: Box::new(move |temp, services| {
Ok(Box::new(Spin::start(&spin_binary_path, temp, services)?) as _)
create_runtime: Box::new(move |temp| {
Ok(Box::new(Spin::start(&spin_binary_path, temp)?) as _)
}),
tests_path,
on_error: OnTestError::Log,
Expand Down
10 changes: 3 additions & 7 deletions tests/runtime-tests/src/spin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{io::OutputStream, services::Services, Runtime, TestResult};
use crate::{io::OutputStream, Runtime, TestResult};
use std::{
path::Path,
process::{Command, Stdio},
Expand All @@ -13,11 +13,8 @@ pub struct Spin {
}

impl Spin {
pub fn start(
spin_binary_path: &Path,
current_dir: &Path,
services: &mut Services,
) -> Result<Self, anyhow::Error> {
/// Start Spin in `current_dir` using the binary at `spin_binary_path`
pub fn start(spin_binary_path: &Path, current_dir: &Path) -> anyhow::Result<Self> {
let port = get_random_port()?;
let mut child = Command::new(spin_binary_path)
.arg("up")
Expand All @@ -37,7 +34,6 @@ impl Spin {
};
let start = std::time::Instant::now();
loop {
services.error()?;
match std::net::TcpStream::connect(format!("127.0.0.1:{port}")) {
Ok(_) => {
log::debug!("Spin started on port {}.", spin.port);
Expand Down
4 changes: 2 additions & 2 deletions tests/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod runtime_tests {
let tests_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/runtime-tests/tests");
let config = Config {
create_runtime: Box::new(move |temp, services| {
Ok(Box::new(Spin::start(&spin_binary_path, temp, services)?) as _)
create_runtime: Box::new(move |temp| {
Ok(Box::new(Spin::start(&spin_binary_path, temp)?) as _)
}),
tests_path,
on_error: runtime_tests::OnTestError::Panic,
Expand Down

0 comments on commit a69161f

Please sign in to comment.