diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/tokio-uds/tests/stream.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tokio-uds/tests/stream.rs')
-rw-r--r-- | third_party/rust/tokio-uds/tests/stream.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/third_party/rust/tokio-uds/tests/stream.rs b/third_party/rust/tokio-uds/tests/stream.rs new file mode 100644 index 0000000000..ebb1835243 --- /dev/null +++ b/third_party/rust/tokio-uds/tests/stream.rs @@ -0,0 +1,55 @@ +#![cfg(unix)] + +extern crate futures; +extern crate tokio; +extern crate tokio_uds; + +extern crate tempfile; + +use tokio_uds::*; + +use tokio::io; +use tokio::runtime::current_thread::Runtime; + +use futures::{Future, Stream}; +use futures::sync::oneshot; +use tempfile::Builder; + +macro_rules! t { + ($e:expr) => (match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {:?}", stringify!($e), e), + }) +} + +#[test] +fn echo() { + let dir = Builder::new().prefix("tokio-uds-tests").tempdir().unwrap(); + let sock_path = dir.path().join("connect.sock"); + + let mut rt = Runtime::new().unwrap(); + + let server = t!(UnixListener::bind(&sock_path)); + let (tx, rx) = oneshot::channel(); + + rt.spawn({ + server.incoming() + .into_future() + .and_then(move |(sock, _)| { + tx.send(sock.unwrap()).unwrap(); + Ok(()) + }) + .map_err(|e| panic!("err={:?}", e)) + }); + + let client = rt.block_on(UnixStream::connect(&sock_path)).unwrap(); + let server = rt.block_on(rx).unwrap(); + + // Write to the client + rt.block_on(io::write_all(client, b"hello")).unwrap(); + + // Read from the server + let (_, buf) = rt.block_on(io::read_to_end(server, vec![])).unwrap(); + + assert_eq!(buf, b"hello"); +} |