aquatic_ws: update tests to use simd-json

This commit is contained in:
Joakim Frostegård 2020-08-12 05:14:27 +02:00
parent 8c4d3e5cb9
commit acc1a0fd74
3 changed files with 24 additions and 25 deletions

View file

@ -33,7 +33,6 @@
scrape requests I suppose. scrape requests I suppose.
## aquatic_ws ## aquatic_ws
* update tests for simd-json
* config: multiple request workers * config: multiple request workers
* test transfer again with changes made: * test transfer again with changes made:
* crossbeam-channel * crossbeam-channel

View file

@ -565,10 +565,10 @@ mod tests {
#[test] #[test]
fn test_deserialize_info_hashes_vec(){ fn test_deserialize_info_hashes_vec(){
let input = r#"{ let mut input: String = r#"{
"action": "scrape", "action": "scrape",
"info_hash": ["aaaabbbbccccddddeeee", "aaaabbbbccccddddeeee"] "info_hash": ["aaaabbbbccccddddeeee", "aaaabbbbccccddddeeee"]
}"#; }"#.into();
let info_hashes = ScrapeRequestInfoHashes::Multiple( let info_hashes = ScrapeRequestInfoHashes::Multiple(
vec![ vec![
@ -582,17 +582,17 @@ mod tests {
info_hashes: Some(info_hashes) info_hashes: Some(info_hashes)
}; };
let observed: ScrapeRequest = serde_json::from_str(input).unwrap(); let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
assert_eq!(expected, observed); assert_eq!(expected, observed);
} }
#[test] #[test]
fn test_deserialize_info_hashes_str(){ fn test_deserialize_info_hashes_str(){
let input = r#"{ let mut input: String = r#"{
"action": "scrape", "action": "scrape",
"info_hash": "aaaabbbbccccddddeeee" "info_hash": "aaaabbbbccccddddeeee"
}"#; }"#.into();
let info_hashes = ScrapeRequestInfoHashes::Single( let info_hashes = ScrapeRequestInfoHashes::Single(
info_hash_from_bytes(b"aaaabbbbccccddddeeee") info_hash_from_bytes(b"aaaabbbbccccddddeeee")
@ -603,51 +603,51 @@ mod tests {
info_hashes: Some(info_hashes) info_hashes: Some(info_hashes)
}; };
let observed: ScrapeRequest = serde_json::from_str(input).unwrap(); let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
assert_eq!(expected, observed); assert_eq!(expected, observed);
} }
#[test] #[test]
fn test_deserialize_info_hashes_null(){ fn test_deserialize_info_hashes_null(){
let input = r#"{ let mut input: String = r#"{
"action": "scrape", "action": "scrape",
"info_hash": null "info_hash": null
}"#; }"#.into();
let expected = ScrapeRequest { let expected = ScrapeRequest {
action: ScrapeAction, action: ScrapeAction,
info_hashes: None info_hashes: None
}; };
let observed: ScrapeRequest = serde_json::from_str(input).unwrap(); let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
assert_eq!(expected, observed); assert_eq!(expected, observed);
} }
#[test] #[test]
fn test_deserialize_info_hashes_missing(){ fn test_deserialize_info_hashes_missing(){
let input = r#"{ let mut input: String = r#"{
"action": "scrape" "action": "scrape"
}"#; }"#.into();
let expected = ScrapeRequest { let expected = ScrapeRequest {
action: ScrapeAction, action: ScrapeAction,
info_hashes: None info_hashes: None
}; };
let observed: ScrapeRequest = serde_json::from_str(input).unwrap(); let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
assert_eq!(expected, observed); assert_eq!(expected, observed);
} }
#[quickcheck] #[quickcheck]
fn quickcheck_serde_identity_info_hashes(info_hashes: ScrapeRequestInfoHashes) -> bool { fn quickcheck_serde_identity_info_hashes(info_hashes: ScrapeRequestInfoHashes) -> bool {
let json = ::serde_json::to_string(&info_hashes).unwrap(); let mut json = ::simd_json::serde::to_string(&info_hashes).unwrap();
println!("{}", json); println!("{}", json);
let deserialized: ScrapeRequestInfoHashes = ::serde_json::from_str(&json).unwrap(); let deserialized: ScrapeRequestInfoHashes = ::simd_json::serde::from_str(&mut json).unwrap();
let success = info_hashes == deserialized; let success = info_hashes == deserialized;

View file

@ -131,20 +131,20 @@ mod tests {
#[test] #[test]
fn test_deserialize_20_bytes(){ fn test_deserialize_20_bytes(){
let input = r#""aaaabbbbccccddddeeee""#; let mut input = r#""aaaabbbbccccddddeeee""#.to_string();
let expected = info_hash_from_bytes(b"aaaabbbbccccddddeeee"); let expected = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
let observed: InfoHash = serde_json::from_str(input).unwrap(); let observed: InfoHash = ::simd_json::serde::from_str(&mut input).unwrap();
assert_eq!(observed, expected); assert_eq!(observed, expected);
let input = r#""aaaabbbbccccddddeee""#; let mut input = r#""aaaabbbbccccddddeee""#.to_string();
let res_info_hash: Result<InfoHash, _> = serde_json::from_str(input); let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
assert!(res_info_hash.is_err()); assert!(res_info_hash.is_err());
let input = r#""aaaabbbbccccddddeee𝕊""#; let mut input = r#""aaaabbbbccccddddeee𝕊""#.to_string();
let res_info_hash: Result<InfoHash, _> = serde_json::from_str(input); let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
assert!(res_info_hash.is_err()); assert!(res_info_hash.is_err());
} }
@ -153,16 +153,16 @@ mod tests {
fn test_serde_20_bytes(){ fn test_serde_20_bytes(){
let info_hash = info_hash_from_bytes(b"aaaabbbbccccddddeeee"); let info_hash = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
let out = serde_json::to_string(&info_hash).unwrap(); let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
let info_hash_2 = serde_json::from_str(&out).unwrap(); let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
assert_eq!(info_hash, info_hash_2); assert_eq!(info_hash, info_hash_2);
} }
#[quickcheck] #[quickcheck]
fn quickcheck_serde_20_bytes(info_hash: InfoHash) -> bool { fn quickcheck_serde_20_bytes(info_hash: InfoHash) -> bool {
let out = serde_json::to_string(&info_hash).unwrap(); let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
let info_hash_2 = serde_json::from_str(&out).unwrap(); let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
info_hash == info_hash_2 info_hash == info_hash_2
} }