Skip to content

Commit

Permalink
Add unix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
t4lz committed Mar 15, 2023
1 parent 43553e8 commit f768f27
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ jobs:
- run: |
cd tests/rust-e2e-fileops
cargo build
- run: |
cd tests/rust-unix-socket-client
cargo build
- name: download image
uses: actions/download-artifact@v2
with:
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"sample/rust",
"tests",
"tests/rust-e2e-fileops",
"tests/rust-unix-socket-client",
]

# latest commits on rustls suppress certificate verification
Expand Down
1 change: 1 addition & 0 deletions tests/rust-unix-socket-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
19 changes: 19 additions & 0 deletions tests/rust-unix-socket-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "rust-unix-socket-client"
version.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true
publish.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.26", features = ["rt", "rt-multi-thread", "macros", "net", "io-util"] }
19 changes: 19 additions & 0 deletions tests/rust-unix-socket-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::env;

use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::UnixStream,
};

#[tokio::main]
async fn main() {
let socket_path = env::args()
.nth(1)
.unwrap_or("/app/unix-socket-server.sock".to_string());
let mut stream = UnixStream::connect(socket_path).await.unwrap();
let buf = b"Stop copying me!";
stream.write_all(buf).await.unwrap();
let mut answer_buf = [0u8; 16];
stream.read_exact(&mut answer_buf).await.unwrap();
assert_eq!(&answer_buf, buf)
}
32 changes: 32 additions & 0 deletions tests/src/traffic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,36 @@ mod traffic {
let res = process.child.wait().await.unwrap();
assert!(res.success());
}

/// Verify that when executed with mirrord an app can connect to a unix socket on the cluster.
///
/// 1. Deploy to the cluster a server that listens to a pathname unix socket and echos incoming
/// data.
/// 2. Run with mirrord a client application that connects to that socket, sends data, verifies
/// its echo and panics if anything went wrong
/// 3. Verify the client app did not panic.
#[rstest]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[timeout(Duration::from_secs(120))]
pub async fn outgoing_unix_stream_pathname(
#[future]
// TODO: change to image from test-images repo!
#[with("default", "ClusterIP", "t4lz/unix-socket-server:latest", "unix-echo")]
service: KubeService,
) {
let service = service.await;
let executable = vec!["../target/debug/rust-unix-socket-client"];

// Tell mirrord to connect remotely to the pathname the deployed app is listening on.
let env = Some(vec![(
"MIRRORD_OUTGOING_REMOTE_UNIX_STREAMS",
"/app/unix-socket-server.sock",
)]);
let mut process = run_exec(executable, &service.target, None, None, env).await;
let res = process.child.wait().await.unwrap();

// The test application panics if it does not successfully connect to the socket, send data,
// and get the same data back. So if it exits with success everything worked.
assert!(res.success());
}
}

0 comments on commit f768f27

Please sign in to comment.