Skip to content

Commit

Permalink
chore(test): test server()
Browse files Browse the repository at this point in the history
Signed-off-by: Wataru Ishida <wataru.ishid@gmail.com>
  • Loading branch information
ishidawataru committed Mar 25, 2024
1 parent 43d5865 commit bb3c3f8
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions reduction_server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,71 @@ pub(crate) fn server(args: Args) {
do_server::<bf16>(args);
}
}

// test
#[cfg(test)]
mod tests {
use super::*;
use crate::client::client;
use crate::utils::tests::initialize;
use clap::Parser;

fn do_test(dt: &str) {
initialize();
let nrank = 4;
let server = {
let dt = dt.to_string();
std::thread::spawn(move || {
let nrank = format!("{}", nrank);
let args = Args::parse_from([
"--verbose", // doesn't work without specifying a flag that doesn't take an argument
"--port",
"8080",
"--data-type",
&dt,
"--nrank",
&nrank,
"--nreq",
"1", // when using socket plugin, concurrent recv/send requests doesn't work
]);
server(args);
})
};
(0..nrank)
.map(|_| {
let dt = dt.to_string();
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(100));
let args = Args::parse_from([
"--client",
"--address",
"127.0.0.1:8080",
"--data-type",
&dt,
"--nreq",
"1", // when using socket plugin, concurrent recv/send requests doesn't work
]);
client(args);
})
})
.collect::<Vec<_>>()
.into_iter()
.for_each(|h| h.join().unwrap());
server.join().unwrap();
}

#[test]
fn test_server_f32() {
do_test("f32");
}

#[test]
fn test_server_f16() {
do_test("f16");
}

#[test]
fn test_server_bf16() {
do_test("bf16");
}
}

0 comments on commit bb3c3f8

Please sign in to comment.