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

wasmtime-wasi: Unexpected InputStream::subscribe wake up #9691

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/test-programs/src/bin/preview2_tcp_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ fn test_tcp_shutdown_should_not_lose_data(net: &Network, family: IpAddressFamily
});
}

/// InputStream::subscribe should not wake up if there is no data to read.
fn test_tcp_input_stream_should_not_wake_on_empty_data(net: &Network, family: IpAddressFamily) {
setup(net, family, |server, client| {
use test_programs::wasi::clocks::monotonic_clock::subscribe_duration;
let timeout_100ms = 100_000_000;

// Send some data to the server
client.output.blocking_write_and_flush(b"Hi!").unwrap();

server.input.subscribe().block();
let res = server.input.read(512).unwrap();
assert_eq!(res, b"Hi!", "Expected to receive data");

// Don't send any data

let res = server
.input
.subscribe()
.block_until(&subscribe_duration(timeout_100ms));
assert!(res.is_err(), "Expected to time out cause no data was sent");
});
}

fn main() {
let net = Network::default();

Expand All @@ -123,6 +146,9 @@ fn main() {

test_tcp_shutdown_should_not_lose_data(&net, IpAddressFamily::Ipv4);
test_tcp_shutdown_should_not_lose_data(&net, IpAddressFamily::Ipv6);

test_tcp_input_stream_should_not_wake_on_empty_data(&net, IpAddressFamily::Ipv4);
test_tcp_input_stream_should_not_wake_on_empty_data(&net, IpAddressFamily::Ipv6);
}

struct Connection {
Expand Down
Loading