From ea6698055db8aca66cbc50e56fd92d514c69b9a4 Mon Sep 17 00:00:00 2001 From: Quanwei Zhou Date: Mon, 7 Oct 2024 20:57:51 +0800 Subject: [PATCH 1/5] client: cargo fmt --all cargo fmt --all Fixes: #255 Signed-off-by: Quanwei Zhou --- example/client.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/example/client.rs b/example/client.rs index 04b96722..57699f29 100644 --- a/example/client.rs +++ b/example/client.rs @@ -53,7 +53,10 @@ fn main() { panic!("not expecting an error from the example server: {:?}", e) } Ok(x) => { - panic!("not expecting a OK response from the example server: {:?}", x) + panic!( + "not expecting a OK response from the example server: {:?}", + x + ) } } println!( @@ -107,7 +110,10 @@ fn main() { panic!("not expecting an error from the example server: {:?}", e) } Ok(s) => { - panic!("not expecting a OK response from the example server: {:?}", s) + panic!( + "not expecting a OK response from the example server: {:?}", + s + ) } }; println!( From ffc8735b6d0c9d16d4258db4258c80c9d3c49684 Mon Sep 17 00:00:00 2001 From: Quanwei Zhou Date: Mon, 7 Oct 2024 21:00:00 +0800 Subject: [PATCH 2/5] example: add debug info for tests add debug info for tests Fixes: #255 Signed-off-by: Quanwei Zhou --- tests/sync-test.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/sync-test.rs b/tests/sync-test.rs index a5a92149..e15f0412 100644 --- a/tests/sync-test.rs +++ b/tests/sync-test.rs @@ -1,6 +1,6 @@ use std::{ io::{BufRead, BufReader}, - process::Command, + process::{Child, Command}, time::Duration, }; @@ -22,13 +22,19 @@ fn run_sync_example() -> Result<(), Box> { }); let output = client.stdout.unwrap(); BufReader::new(output).lines().for_each(|line| { - println!("{}", line.unwrap()); + println!("client output: {}", line.unwrap()); }); break; } match client.try_wait() { Ok(Some(status)) => { + println!( + "Client exited with status: {:?} success {}", + &status, + &status.success() + ); + wait_with_output("client", client); client_succeeded = status.success(); break; } @@ -45,6 +51,7 @@ fn run_sync_example() -> Result<(), Box> { // be sure to clean up the server, the client should have run to completion server.kill()?; + wait_with_output("server", server); assert!(client_succeeded); Ok(()) } @@ -59,3 +66,18 @@ fn run_example(example: &str) -> Command { .current_dir("example"); cmd } + +fn wait_with_output(name: &str, cmd: Child) { + if let Ok(output) = cmd.wait_with_output() { + println!("==== {name} output begin"); + println!("==== stdout:"); + output.stdout.lines().for_each(|line| { + println!("{}", line.unwrap()); + }); + println!("==== stderr:"); + output.stderr.lines().for_each(|line| { + println!("{}", line.unwrap()); + }); + println!("==== {name} output end"); + } +} From fb5278b05335899f950f3876f3de1984298e59d8 Mon Sep 17 00:00:00 2001 From: Quanwei Zhou Date: Tue, 8 Oct 2024 09:19:12 +0800 Subject: [PATCH 3/5] example: check client fd leak check client fd leak Fixes: #255 Signed-off-by: Quanwei Zhou --- example/client.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/example/client.rs b/example/client.rs index 57699f29..71881ce4 100644 --- a/example/client.rs +++ b/example/client.rs @@ -23,7 +23,36 @@ use ttrpc::error::Error; use ttrpc::proto::Code; use ttrpc::Client; +#[cfg(not(target_os = "linux"))] +fn get_fd_count() -> usize { + // currently not support get fd count + 0 +} + +#[cfg(target_os = "linux")] +fn get_fd_count() -> usize { + let path = "/proc/self/fd"; + let count = std::fs::read_dir(path).unwrap().count(); + println!("get fd count {}", count); + count +} + fn main() { + connect_once(); + let expected_fd_count = get_fd_count(); + + // connect 3 times and check the fd leak. + for index in 0..3 { + connect_once(); + let current_fd_count = get_fd_count(); + assert_eq!( + expected_fd_count, current_fd_count, + "check fd count in {index}" + ); + } +} + +fn connect_once() { simple_logging::log_to_stderr(LevelFilter::Trace); let c = Client::connect(utils::SOCK_ADDR).unwrap(); From 5c0da46c2ef065566cc3833ade435768fe03c979 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Wed, 9 Oct 2024 16:33:57 +0800 Subject: [PATCH 4/5] gh-action: Set bash shell for bvt workflow It's important for windows to fail correctly. Further: https://github.com/actions/runner-images/issues/6668 Signed-off-by: Tim Zhang --- .github/workflows/bvt.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/bvt.yml b/.github/workflows/bvt.yml index ba6f519d..78cdd898 100644 --- a/.github/workflows/bvt.yml +++ b/.github/workflows/bvt.yml @@ -29,6 +29,9 @@ jobs: make -C compiler make -C ttrpc-codegen make -C example build-examples + # It's important for windows to fail correctly + # https://github.com/actions/runner-images/issues/6668 + shell: bash deny: runs-on: ubuntu-latest From e4d0d209cabb138b4cb7d1117ad9371855e3bf36 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Wed, 9 Oct 2024 16:39:16 +0800 Subject: [PATCH 5/5] example: speed up sync-test By removing sleep from client.rs, and remoing retry. Signed-off-by: Tim Zhang --- example/client.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/example/client.rs b/example/client.rs index 71881ce4..cdd3d083 100644 --- a/example/client.rs +++ b/example/client.rs @@ -18,6 +18,7 @@ mod utils; use log::LevelFilter; use protocols::sync::{agent, agent_ttrpc, health, health_ttrpc}; use std::thread; +use std::time::Duration; use ttrpc::context::{self, Context}; use ttrpc::error::Error; use ttrpc::proto::Code; @@ -38,18 +39,12 @@ fn get_fd_count() -> usize { } fn main() { - connect_once(); let expected_fd_count = get_fd_count(); - - // connect 3 times and check the fd leak. - for index in 0..3 { - connect_once(); - let current_fd_count = get_fd_count(); - assert_eq!( - expected_fd_count, current_fd_count, - "check fd count in {index}" - ); - } + connect_once(); + // Give some time for fd to be released in the other thread + thread::sleep(Duration::from_secs(1)); + let current_fd_count = get_fd_count(); + assert_eq!(current_fd_count, expected_fd_count, "check fd count"); } fn connect_once() { @@ -151,9 +146,6 @@ fn connect_once() { now.elapsed() ); - println!("\nsleep 2 seconds ...\n"); - thread::sleep(std::time::Duration::from_secs(2)); - let version = hc.version(default_ctx(), &health::CheckRequest::new()); assert_eq!("mock.0.1", version.as_ref().unwrap().agent_version.as_str()); assert_eq!("0.0.1", version.as_ref().unwrap().grpc_version.as_str());