Sockets: running actors get TCP, UDP, and DNS through wasi:sockets; candidates get no network
This commit is contained in:
@@ -831,3 +831,34 @@ async fn candidates_receive_version_and_preexisting_spawn_state() {
|
||||
assert_eq!(successful, 2);
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn running_actors_have_sockets_and_candidates_do_not() {
|
||||
// A TCP server on the host that answers each line with "echo: <line>".
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let address = listener.local_addr().unwrap().to_string();
|
||||
tokio::spawn(async move {
|
||||
while let Ok((stream, _)) = listener.accept().await {
|
||||
tokio::spawn(async move {
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
let (read, mut write) = stream.into_split();
|
||||
let mut lines = tokio::io::BufReader::new(read).lines();
|
||||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
let _ = write.write_all(format!("echo: {line}\n").as_bytes()).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let world = create_world("sockets");
|
||||
let wasm = toolbox_wasm().clone();
|
||||
let (host, mut mailbox) = start(&world).await;
|
||||
let tcp = json!({"type": "tcp", "address": address, "text": "hi"});
|
||||
// The candidate test expects the connection to fail.
|
||||
let offline = source_with_test(&world, "offline", json!({"steps": [{"send": tcp, "expect": {"type": "error"}}]}));
|
||||
assert_eq!(spawn_actor(&host, &mut mailbox, "net", &wasm, &offline).await.body["type"], "spawned");
|
||||
|
||||
let answer = ask(&host, &mut mailbox, "net", tcp).await;
|
||||
assert_eq!(answer.body, json!({"type": "tcp", "line": "echo: hi"}));
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user