MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / cli_serve_hello_world

Function cli_serve_hello_world

tests/all/cli_tests.rs:2659–2705  ·  view source on GitHub ↗
(
        component: &str,
        connection_count: usize,
        requests_per_connection: usize,
        configure: impl FnOnce(&mut Command),
    )

Source from the content-addressed store, hash-verified

2657 }
2658
2659 async fn cli_serve_hello_world(
2660 component: &str,
2661 connection_count: usize,
2662 requests_per_connection: usize,
2663 configure: impl FnOnce(&mut Command),
2664 ) -> Result<()> {
2665 let server = std::sync::Arc::new(WasmtimeServe::new(component, configure)?);
2666
2667 let tasks = (0..connection_count).map({
2668 let server = server.clone();
2669 move |_| {
2670 tokio::task::spawn({
2671 let server = server.clone();
2672 async move {
2673 let (mut send, conn_task) = server.start_requests().await?;
2674
2675 for _ in 0..requests_per_connection {
2676 let result = WasmtimeServe::send_request_with(
2677 &mut send,
2678 hyper::Request::builder()
2679 .uri("http://localhost/")
2680 .body(String::new())
2681 .context("failed to make request")?,
2682 )
2683 .await?;
2684
2685 assert!(result.status().is_success());
2686 assert_eq!(result.body(), "Hello, WASI!");
2687 }
2688
2689 drop(send);
2690
2691 conn_task.await??;
2692
2693 wasmtime::error::Ok(())
2694 }
2695 })
2696 }
2697 });
2698
2699 for task in tasks {
2700 task.await??;
2701 }
2702
2703 std::sync::Arc::into_inner(server).unwrap().finish()?;
2704 Ok(())
2705 }
2706
2707 #[tokio::test]
2708 async fn p2_cli_serve_sleep() -> Result<()> {

Calls 13

spawnFunction · 0.85
OkFunction · 0.85
into_innerFunction · 0.85
start_requestsMethod · 0.80
bodyMethod · 0.80
newFunction · 0.50
builderFunction · 0.50
dropFunction · 0.50
mapMethod · 0.45
cloneMethod · 0.45
contextMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected