Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Factors] in-process runtime and conformance tests #2732

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

rylev
Copy link
Collaborator

@rylev rylev commented Aug 20, 2024

This allows us to run runtime and conformance tests using the "in-process runtime" (as opposed to the Spin CLI spawned process runtime).

This requires a few refactorings that I think push us more towards other goals as well (namely spin-trigger being generic over the RuntimeFactors type).

The actual code for instantiating and triggering an HTTP trigger without running an actual HTTP server looks like this:

    let app = spin_app::App::new("my-app", locked_app);
    let trigger = HttpTrigger::new(&app, "127.0.0.1:80".parse().unwrap(), None)?;
    let mut builder = TriggerAppBuilder::new(trigger, PathBuf::from("."));
    let trigger_app = builder.build(app, TriggerAppOptions::default()).await?;
    let server = builder.trigger.into_server(trigger_app)?;
    server
        .handle(
              req,
              http::uri::Scheme::HTTP,
              (std::net::Ipv4Addr::LOCALHOST, 7000).into(),
         )
        .await?;

@rylev rylev requested a review from lann August 20, 2024 18:30
@rylev rylev changed the title [Factors] in-process conformance tests [Factors] in-process runtime and conformance tests Aug 20, 2024
@@ -333,6 +288,111 @@ impl HttpServer {
}
}

/// Handles a routed HTTP trigger request.
pub struct RequestHandler {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you say more about this change? It isn't clear how it relates to the conformance tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair this was from an evolutionary dead end. I do think it helps make things a bit easier to follow (at the expense of being slightly more verbose) by only giving the OutboundHttpInterceptor what it needs and nothing more. It encapsulates just the component handling and leaves out all the other HTTP sever stuff to the encapsulating HttpServer types.

I can revert it if you want me to though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its mostly just really hard to review the diff 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! If you aren't able to review, I'll revert that change tomorrow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted that change so hopefully the diff is a bit easier to read. Unfortunately, there's one spot where git's diffing still gets a bit confused.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rylev rylev requested a review from lann August 21, 2024 11:04
Comment on lines +203 to +255
let (abortable, abort_handle) = futures::future::abortable(run_fut);
ctrlc::set_handler(move || abort_handle.abort())?;
match abortable.await {
Ok(Ok(())) => {
tracing::info!("Trigger executor shut down: exiting");
Ok(())
}
Ok(Err(err)) => {
tracing::error!("Trigger executor failed");
Err(err)
}
Err(_aborted) => {
tracing::info!("User requested shutdown: exiting");
Ok(())
}
}
}

fn follow_components(&self) -> FollowComponents {
if self.silence_component_logs {
FollowComponents::None
} else if self.follow_components.is_empty() {
FollowComponents::All
} else {
let followed = self.follow_components.clone().into_iter().collect();
FollowComponents::Named(followed)
}
}
}

const SLOTH_WARNING_DELAY_MILLIS: u64 = 1250;

fn warn_if_wasm_build_slothful() -> sloth::SlothGuard {
#[cfg(debug_assertions)]
let message = "\
This is a debug build - preparing Wasm modules might take a few seconds\n\
If you're experiencing long startup times please switch to the release build";

#[cfg(not(debug_assertions))]
let message = "Preparing Wasm modules is taking a few seconds...";

sloth::warn_if_slothful(SLOTH_WARNING_DELAY_MILLIS, format!("{message}\n"))
}

fn help_heading<T: Trigger>() -> Option<&'static str> {
if T::TYPE == help::HelpArgsOnlyTrigger::TYPE {
Some("TRIGGER OPTIONS")
} else {
let heading = format!("{} TRIGGER OPTIONS", T::TYPE.to_uppercase());
let as_str = Box::new(heading).leak();
Some(as_str)
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all just moved from down below.

@@ -333,6 +288,111 @@ impl HttpServer {
}
}

/// Handles a routed HTTP trigger request.
pub struct RequestHandler {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted that change so hopefully the diff is a bit easier to read. Unfortunately, there's one spot where git's diffing still gets a bit confused.

@rylev rylev merged commit 66f357a into factors Aug 21, 2024
2 checks passed
@rylev rylev deleted the factors-conformance-tests branch August 21, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants