|
|
|
@ -177,54 +177,8 @@ mod tests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
#[ignore]
|
|
|
|
|
async fn should_be_able_to_reconnect() {
|
|
|
|
|
let (tx, rx) = oneshot::channel();
|
|
|
|
|
|
|
|
|
|
// Spawn a task that will wait for a connection, send data,
|
|
|
|
|
// and receive data that it will return in the task
|
|
|
|
|
let task: JoinHandle<io::Result<()>> = tokio::spawn(async move {
|
|
|
|
|
let (inner_tx, inner_rx) = oneshot::channel();
|
|
|
|
|
let mut pipe = start_server(inner_tx).await?;
|
|
|
|
|
|
|
|
|
|
// Get first connection
|
|
|
|
|
pipe.connect().await?;
|
|
|
|
|
|
|
|
|
|
let addr = inner_rx.await.expect("Failed to get address");
|
|
|
|
|
|
|
|
|
|
// Listen for second connection
|
|
|
|
|
let pipe = ServerOptions::new().create(&addr)?;
|
|
|
|
|
|
|
|
|
|
tx.send(addr).expect("Failed to send address");
|
|
|
|
|
|
|
|
|
|
run_server(pipe).await
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Wait for the server to be ready
|
|
|
|
|
let address = rx.await.expect("Failed to get server address");
|
|
|
|
|
|
|
|
|
|
// Connect to the server
|
|
|
|
|
let mut conn = WindowsPipeTransport::connect(&address)
|
|
|
|
|
.await
|
|
|
|
|
.expect("Conn failed to connect");
|
|
|
|
|
|
|
|
|
|
// Reconnect to the pipe, send some bytes, and get some bytes
|
|
|
|
|
// TODO: We cannot restart a killed pipe server as we get permission
|
|
|
|
|
// denied, and we don't have an easy way to kill our pipe connection
|
|
|
|
|
// in some other way, so for now we just verify that a reconnect
|
|
|
|
|
// succeeds and it still works
|
|
|
|
|
let mut buf: [u8; 10] = [0; 10];
|
|
|
|
|
conn.reconnect().await.expect("Conn failed to reconnect");
|
|
|
|
|
|
|
|
|
|
conn.read_exact(&mut buf)
|
|
|
|
|
.await
|
|
|
|
|
.expect("Conn failed to read");
|
|
|
|
|
assert_eq!(&buf, b"hello conn");
|
|
|
|
|
|
|
|
|
|
conn.write_all(b"hello server")
|
|
|
|
|
.await
|
|
|
|
|
.expect("Conn failed to write");
|
|
|
|
|
|
|
|
|
|
// Verify that the task has completed by waiting on it
|
|
|
|
|
let _ = task.await.expect("Server task failed unexpectedly");
|
|
|
|
|
todo!();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|