mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_ws: update tests to use simd-json
This commit is contained in:
parent
8c4d3e5cb9
commit
acc1a0fd74
3 changed files with 24 additions and 25 deletions
1
TODO.md
1
TODO.md
|
|
@ -33,7 +33,6 @@
|
|||
scrape requests I suppose.
|
||||
|
||||
## aquatic_ws
|
||||
* update tests for simd-json
|
||||
* config: multiple request workers
|
||||
* test transfer again with changes made:
|
||||
* crossbeam-channel
|
||||
|
|
|
|||
|
|
@ -565,10 +565,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_deserialize_info_hashes_vec(){
|
||||
let input = r#"{
|
||||
let mut input: String = r#"{
|
||||
"action": "scrape",
|
||||
"info_hash": ["aaaabbbbccccddddeeee", "aaaabbbbccccddddeeee"]
|
||||
}"#;
|
||||
}"#.into();
|
||||
|
||||
let info_hashes = ScrapeRequestInfoHashes::Multiple(
|
||||
vec![
|
||||
|
|
@ -582,17 +582,17 @@ mod tests {
|
|||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_info_hashes_str(){
|
||||
let input = r#"{
|
||||
let mut input: String = r#"{
|
||||
"action": "scrape",
|
||||
"info_hash": "aaaabbbbccccddddeeee"
|
||||
}"#;
|
||||
}"#.into();
|
||||
|
||||
let info_hashes = ScrapeRequestInfoHashes::Single(
|
||||
info_hash_from_bytes(b"aaaabbbbccccddddeeee")
|
||||
|
|
@ -603,51 +603,51 @@ mod tests {
|
|||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_info_hashes_null(){
|
||||
let input = r#"{
|
||||
let mut input: String = r#"{
|
||||
"action": "scrape",
|
||||
"info_hash": null
|
||||
}"#;
|
||||
}"#.into();
|
||||
|
||||
let expected = ScrapeRequest {
|
||||
action: ScrapeAction,
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_info_hashes_missing(){
|
||||
let input = r#"{
|
||||
let mut input: String = r#"{
|
||||
"action": "scrape"
|
||||
}"#;
|
||||
}"#.into();
|
||||
|
||||
let expected = ScrapeRequest {
|
||||
action: ScrapeAction,
|
||||
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);
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -131,20 +131,20 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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 observed: InfoHash = serde_json::from_str(input).unwrap();
|
||||
let observed: InfoHash = ::simd_json::serde::from_str(&mut input).unwrap();
|
||||
|
||||
assert_eq!(observed, expected);
|
||||
|
||||
let input = r#""aaaabbbbccccddddeee""#;
|
||||
let res_info_hash: Result<InfoHash, _> = serde_json::from_str(input);
|
||||
let mut input = r#""aaaabbbbccccddddeee""#.to_string();
|
||||
let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
|
||||
|
||||
assert!(res_info_hash.is_err());
|
||||
|
||||
let input = r#""aaaabbbbccccddddeee𝕊""#;
|
||||
let res_info_hash: Result<InfoHash, _> = serde_json::from_str(input);
|
||||
let mut input = r#""aaaabbbbccccddddeee𝕊""#.to_string();
|
||||
let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
|
||||
|
||||
assert!(res_info_hash.is_err());
|
||||
}
|
||||
|
|
@ -153,16 +153,16 @@ mod tests {
|
|||
fn test_serde_20_bytes(){
|
||||
let info_hash = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
|
||||
|
||||
let out = serde_json::to_string(&info_hash).unwrap();
|
||||
let info_hash_2 = serde_json::from_str(&out).unwrap();
|
||||
let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
|
||||
let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
|
||||
|
||||
assert_eq!(info_hash, info_hash_2);
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
fn quickcheck_serde_20_bytes(info_hash: InfoHash) -> bool {
|
||||
let out = serde_json::to_string(&info_hash).unwrap();
|
||||
let info_hash_2 = serde_json::from_str(&out).unwrap();
|
||||
let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
|
||||
let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
|
||||
|
||||
info_hash == info_hash_2
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue