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

Function p2_cli_serve_quick_rebind_allowed

tests/all/cli_tests.rs:1934–1977  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1932 // process.
1933 #[tokio::test]
1934 async fn p2_cli_serve_quick_rebind_allowed() -> Result<()> {
1935 let wasm = P2_CLI_SERVE_ECHO_ENV_COMPONENT;
1936 let server = WasmtimeServe::new(wasm, |cmd| {
1937 cmd.arg("-Scli");
1938 })?;
1939 let addr = server.addr;
1940
1941 // Start up a `send` and `conn_task` which represents a connection to
1942 // this server.
1943 let (mut send, conn_task) = server.start_requests().await?;
1944 let _ = send
1945 .send_request(
1946 hyper::Request::builder()
1947 .uri("http://localhost/")
1948 .header("env", "FOO")
1949 .body(String::new())
1950 .context("failed to make request")?,
1951 )
1952 .await;
1953
1954 // ... once a response has been received (or at least the status
1955 // code/headers) then kill the server. THis is done while `conn_task`
1956 // and `send` are still alive so we're guaranteed that the other side
1957 // got a request (we got a response) and our connection is still open.
1958 //
1959 // This forces the address/port into the `TIME_WAIT` state. The rebind
1960 // below in the next process will fail if `SO_REUSEADDR` isn't set.
1961 drop(server);
1962 drop(send);
1963 let _ = conn_task.await;
1964
1965 // If this is successfully bound then we'll create `WasmtimeServe`
1966 // which reads off the first line of output to know which address was
1967 // bound.
1968 let _server2 = WasmtimeServe::spawn(
1969 super::get_wasmtime_command()?
1970 .arg("serve")
1971 .arg("-Scli")
1972 .arg(format!("--addr={addr}"))
1973 .arg(wasm),
1974 )?;
1975
1976 Ok(())
1977 }
1978
1979 #[tokio::test]
1980 async fn p2_cli_serve_with_print() -> Result<()> {

Callers

nothing calls this directly

Calls 12

spawnFunction · 0.85
get_wasmtime_commandFunction · 0.85
OkFunction · 0.85
start_requestsMethod · 0.80
bodyMethod · 0.80
newFunction · 0.50
builderFunction · 0.50
dropFunction · 0.50
argMethod · 0.45
send_requestMethod · 0.45
contextMethod · 0.45
headerMethod · 0.45

Tested by

no test coverage detected