Skip to content
Open
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
9 changes: 6 additions & 3 deletions crates/core/src/foundation/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl Write for Socket {
#[cfg(all(test, unix))]
mod tests {
use std::io::{BufRead, BufReader};
use std::net::Shutdown;
use std::os::unix::net::UnixListener;

use super::*;
Expand All @@ -189,15 +190,17 @@ mod tests {
let listener = UnixListener::bind(&path).unwrap();
socket.send(b"{\"first\":1}\n").unwrap();
let (accepted, _) = listener.accept().unwrap();
let mut lines = BufReader::new(accepted).lines();
let mut lines = BufReader::new(&accepted).lines();
assert_eq!(lines.next().unwrap().unwrap(), r#"{"first":1}"#);

// The listener closing the connection triggers a reconnect on the next write without losing the line...
drop(lines);
// Shut down instead of dropping, since a child another test spawns may hold a copy of the descriptor...
accepted.shutdown(Shutdown::Both).unwrap();
socket.send(b"{\"second\":2}\n").unwrap();
let (accepted, _) = listener.accept().unwrap();
let received: Vec<String> = BufReader::new(accepted).lines().take(1).map(Result::unwrap).collect();
let received: Vec<String> = BufReader::new(&accepted).lines().take(1).map(Result::unwrap).collect();
assert_eq!(received, [r#"{"second":2}"#]);
accepted.shutdown(Shutdown::Both).unwrap();

// When the listener is gone completely, writes fail and drop the line...
drop(listener);
Expand Down