Skip to content

Commit

Permalink
Add unit test for datagen, timer and create_client (#104)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #104

# What
* Add unit test for create_client when tls information not given, should panic.
* Add unit test for timer. qps, silent and elapsed_str function
* Add unit test for random_data. check the length of result

# Why
* need to improve code coverage

Reviewed By: wenqingren

Differential Revision: D40491828

fbshipit-source-id: c5d3fd324788464fd202265371cc275c2779e4f8
  • Loading branch information
Jian Cao authored and facebook-github-bot committed Oct 19, 2022
1 parent 382d1cb commit f385da8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common/datagen/datagen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,15 @@ mod test {
let res = gen::write_slice_to_file(input, 1, p);
assert!(res.is_ok());
}

#[test]
fn test_random_data() {
let size = 10;
let intrsct = size / 2;
let size_player = size - intrsct;

let data = gen::random_data(size_player, size_player, intrsct);

assert_eq!(data.player_a.len(), 10);
}
}
33 changes: 33 additions & 0 deletions common/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,37 @@ mod tests {
.build();
}
}

#[test]
fn test_qps() {
let t = Builder::new()
.label("foo")
.extra_label("bar")
.size(199)
.build();
t.qps("test", 10);
}

#[test]
fn test_silent() {
let t = Builder::default()
.label("foo")
.silent(true)
.extra_label("bar")
.size(199)
.build();
assert!(t.silent);
}

#[test]
fn test_elapsed_str() {
let t = Builder::new()
.label("foo")
.silent(true)
.extra_label("bar")
.size(199)
.build();
t.elapsed_str(Some("1"));
t.elapsed_log(Some("1"));
}
}
29 changes: 29 additions & 0 deletions protocol-rpc/src/connect/create_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,32 @@ pub fn create_client(

context
}

#[cfg(test)]
mod test {
use super::*;

#[test]
#[should_panic]
fn test_create_client_tls_panic() {
let no_tls = false;

let host_pre: Option<&str> = Some("localhost:10009");
let tls_dir = None;
let tls_key = None;
let tls_cert = None;
let tls_ca = None;
let tls_domain = None;

let _ = create_client(
no_tls,
host_pre,
tls_dir,
tls_key,
tls_cert,
tls_ca,
tls_domain,
"private-id-multi-key".to_string(),
);
}
}

0 comments on commit f385da8

Please sign in to comment.