mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Upgrade quickcheck to 1.0, adjust code, optimizing a slow test
This commit is contained in:
parent
72ff55ae5d
commit
f9626ade57
19 changed files with 78 additions and 74 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
|
@ -602,9 +602,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_logger"
|
name = "env_logger"
|
||||||
version = "0.7.1"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
@ -1216,21 +1216,20 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quickcheck"
|
name = "quickcheck"
|
||||||
version = "0.9.2"
|
version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f"
|
checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.7.3",
|
"rand 0.8.3",
|
||||||
"rand_core 0.5.1",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quickcheck_macros"
|
name = "quickcheck_macros"
|
||||||
version = "0.9.1"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "608c156fd8e97febc07dc9c2e2c80bf74cfc6ef26893eae3daf8bc2bc94a4b7f"
|
checksum = "b22a693222d716a9587786f37ac3f6b4faedb5b80c23914e7303ff5a1d8016e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ aquatic_ws_protocol = { path = "aquatic_ws_protocol" }
|
||||||
debug = true
|
debug = true
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
|
[profile.test]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
[profile.bench]
|
[profile.bench]
|
||||||
debug = true
|
debug = true
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
|
||||||
|
|
@ -39,5 +39,5 @@ smartstring = "0.2"
|
||||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,5 @@ rand_distr = "0.4"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -43,5 +43,5 @@ urlencoding = "1"
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bendy = { version = "0.3", features = ["std", "serde"] }
|
bendy = { version = "0.3", features = ["std", "serde"] }
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
@ -60,7 +60,7 @@ impl FromStr for AnnounceEvent {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for InfoHash {
|
impl quickcheck::Arbitrary for InfoHash {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let mut arr = [b'0'; 20];
|
let mut arr = [b'0'; 20];
|
||||||
|
|
||||||
for byte in arr.iter_mut(){
|
for byte in arr.iter_mut(){
|
||||||
|
|
@ -74,7 +74,7 @@ impl quickcheck::Arbitrary for InfoHash {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for PeerId {
|
impl quickcheck::Arbitrary for PeerId {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let mut arr = [b'0'; 20];
|
let mut arr = [b'0'; 20];
|
||||||
|
|
||||||
for byte in arr.iter_mut(){
|
for byte in arr.iter_mut(){
|
||||||
|
|
@ -88,7 +88,7 @@ impl quickcheck::Arbitrary for PeerId {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for AnnounceEvent {
|
impl quickcheck::Arbitrary for AnnounceEvent {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
match (bool::arbitrary(g), bool::arbitrary(g)){
|
match (bool::arbitrary(g), bool::arbitrary(g)){
|
||||||
(false, false) => Self::Started,
|
(false, false) => Self::Started,
|
||||||
(true, false) => Self::Started,
|
(true, false) => Self::Started,
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for AnnounceRequest {
|
impl Arbitrary for AnnounceRequest {
|
||||||
fn arbitrary<G: Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut Gen) -> Self {
|
||||||
let key: Option<String> = Arbitrary::arbitrary(g);
|
let key: Option<String> = Arbitrary::arbitrary(g);
|
||||||
|
|
||||||
AnnounceRequest {
|
AnnounceRequest {
|
||||||
|
|
@ -339,7 +339,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for ScrapeRequest {
|
impl Arbitrary for ScrapeRequest {
|
||||||
fn arbitrary<G: Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut Gen) -> Self {
|
||||||
ScrapeRequest {
|
ScrapeRequest {
|
||||||
info_hashes: Arbitrary::arbitrary(g),
|
info_hashes: Arbitrary::arbitrary(g),
|
||||||
}
|
}
|
||||||
|
|
@ -347,7 +347,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for Request {
|
impl Arbitrary for Request {
|
||||||
fn arbitrary<G: Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut Gen) -> Self {
|
||||||
if Arbitrary::arbitrary(g){
|
if Arbitrary::arbitrary(g){
|
||||||
Self::Announce(Arbitrary::arbitrary(g))
|
Self::Announce(Arbitrary::arbitrary(g))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ impl Response {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ResponsePeer<Ipv4Addr> {
|
impl quickcheck::Arbitrary for ResponsePeer<Ipv4Addr> {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ip_address: Ipv4Addr::arbitrary(g),
|
ip_address: Ipv4Addr::arbitrary(g),
|
||||||
port: u16::arbitrary(g)
|
port: u16::arbitrary(g)
|
||||||
|
|
@ -203,7 +203,7 @@ impl quickcheck::Arbitrary for ResponsePeer<Ipv4Addr> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ResponsePeer<Ipv6Addr> {
|
impl quickcheck::Arbitrary for ResponsePeer<Ipv6Addr> {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ip_address: Ipv6Addr::arbitrary(g),
|
ip_address: Ipv6Addr::arbitrary(g),
|
||||||
port: u16::arbitrary(g)
|
port: u16::arbitrary(g)
|
||||||
|
|
@ -214,7 +214,7 @@ impl quickcheck::Arbitrary for ResponsePeer<Ipv6Addr> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ResponsePeerListV4 {
|
impl quickcheck::Arbitrary for ResponsePeerListV4 {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self(Vec::arbitrary(g))
|
Self(Vec::arbitrary(g))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +222,7 @@ impl quickcheck::Arbitrary for ResponsePeerListV4 {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ResponsePeerListV6 {
|
impl quickcheck::Arbitrary for ResponsePeerListV6 {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self(Vec::arbitrary(g))
|
Self(Vec::arbitrary(g))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +230,7 @@ impl quickcheck::Arbitrary for ResponsePeerListV6 {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ScrapeStatistics {
|
impl quickcheck::Arbitrary for ScrapeStatistics {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
complete: usize::arbitrary(g),
|
complete: usize::arbitrary(g),
|
||||||
incomplete: usize::arbitrary(g),
|
incomplete: usize::arbitrary(g),
|
||||||
|
|
@ -242,7 +242,7 @@ impl quickcheck::Arbitrary for ScrapeStatistics {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for AnnounceResponse {
|
impl quickcheck::Arbitrary for AnnounceResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
announce_interval: usize::arbitrary(g),
|
announce_interval: usize::arbitrary(g),
|
||||||
complete: usize::arbitrary(g),
|
complete: usize::arbitrary(g),
|
||||||
|
|
@ -256,7 +256,7 @@ impl quickcheck::Arbitrary for AnnounceResponse {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ScrapeResponse {
|
impl quickcheck::Arbitrary for ScrapeResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
files: BTreeMap::arbitrary(g),
|
files: BTreeMap::arbitrary(g),
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +266,7 @@ impl quickcheck::Arbitrary for ScrapeResponse {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for FailureResponse {
|
impl quickcheck::Arbitrary for FailureResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
failure_reason: String::arbitrary(g),
|
failure_reason: String::arbitrary(g),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,5 @@ serde = { version = "1", features = ["derive"] }
|
||||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -414,17 +414,19 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_extract_response_peers(){
|
fn test_extract_response_peers(){
|
||||||
fn prop(data: (u32, u16)) -> TestResult {
|
fn prop(data: (u16, u16)) -> TestResult {
|
||||||
let gen_num_peers = data.0;
|
let gen_num_peers = data.0 as u32;
|
||||||
let req_num_peers = data.1 as usize;
|
let req_num_peers = data.1 as usize;
|
||||||
|
|
||||||
let mut peer_map: PeerMap<Ipv4Addr> = IndexMap::new();
|
let mut peer_map: PeerMap<Ipv4Addr> = IndexMap::with_capacity(
|
||||||
|
gen_num_peers as usize
|
||||||
|
);
|
||||||
|
|
||||||
let mut opt_sender_key = None;
|
let mut opt_sender_key = None;
|
||||||
let mut opt_sender_peer = None;
|
let mut opt_sender_peer = None;
|
||||||
|
|
||||||
for i in 0..gen_num_peers {
|
for i in 0..gen_num_peers {
|
||||||
let (key, value) = gen_peer_map_key_and_value(i);
|
let (key, value) = gen_peer_map_key_and_value((i << 16) + i);
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
opt_sender_key = Some(key);
|
opt_sender_key = Some(key);
|
||||||
|
|
@ -456,7 +458,7 @@ mod tests {
|
||||||
// Check that returned peers are unique (no overlap) and that sender
|
// Check that returned peers are unique (no overlap) and that sender
|
||||||
// isn't returned
|
// isn't returned
|
||||||
|
|
||||||
let mut ip_addresses = HashSet::new();
|
let mut ip_addresses = HashSet::with_capacity(peers.len());
|
||||||
|
|
||||||
for peer in peers {
|
for peer in peers {
|
||||||
if peer == opt_sender_peer.clone().unwrap() || ip_addresses.contains(&peer.ip_address){
|
if peer == opt_sender_peer.clone().unwrap() || ip_addresses.contains(&peer.ip_address){
|
||||||
|
|
@ -471,6 +473,6 @@ mod tests {
|
||||||
TestResult::from_bool(success)
|
TestResult::from_bool(success)
|
||||||
}
|
}
|
||||||
|
|
||||||
quickcheck(prop as fn((u32, u16)) -> TestResult);
|
quickcheck(prop as fn((u16, u16)) -> TestResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,5 +24,5 @@ serde = { version = "1", features = ["derive"] }
|
||||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ repository = "https://github.com/greatest-ape/aquatic"
|
||||||
byteorder = "1"
|
byteorder = "1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
@ -52,7 +52,7 @@ pub struct ResponsePeer {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for IpVersion {
|
impl quickcheck::Arbitrary for IpVersion {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
if bool::arbitrary(g) {
|
if bool::arbitrary(g) {
|
||||||
IpVersion::IPv4
|
IpVersion::IPv4
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -64,7 +64,7 @@ impl quickcheck::Arbitrary for IpVersion {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for InfoHash {
|
impl quickcheck::Arbitrary for InfoHash {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let mut bytes = [0u8; 20];
|
let mut bytes = [0u8; 20];
|
||||||
|
|
||||||
for byte in bytes.iter_mut() {
|
for byte in bytes.iter_mut() {
|
||||||
|
|
@ -78,7 +78,7 @@ impl quickcheck::Arbitrary for InfoHash {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for PeerId {
|
impl quickcheck::Arbitrary for PeerId {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let mut bytes = [0u8; 20];
|
let mut bytes = [0u8; 20];
|
||||||
|
|
||||||
for byte in bytes.iter_mut() {
|
for byte in bytes.iter_mut() {
|
||||||
|
|
@ -92,7 +92,7 @@ impl quickcheck::Arbitrary for PeerId {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl quickcheck::Arbitrary for ResponsePeer {
|
impl quickcheck::Arbitrary for ResponsePeer {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ip_address: ::std::net::IpAddr::arbitrary(g),
|
ip_address: ::std::net::IpAddr::arbitrary(g),
|
||||||
port: Port(u16::arbitrary(g)),
|
port: Port(u16::arbitrary(g)),
|
||||||
|
|
|
||||||
|
|
@ -292,7 +292,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for AnnounceEvent {
|
impl quickcheck::Arbitrary for AnnounceEvent {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
match (bool::arbitrary(g), bool::arbitrary(g)){
|
match (bool::arbitrary(g), bool::arbitrary(g)){
|
||||||
(false, false) => Self::Started,
|
(false, false) => Self::Started,
|
||||||
(true, false) => Self::Started,
|
(true, false) => Self::Started,
|
||||||
|
|
@ -303,7 +303,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for ConnectRequest {
|
impl quickcheck::Arbitrary for ConnectRequest {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transaction_id: TransactionId(i32::arbitrary(g)),
|
transaction_id: TransactionId(i32::arbitrary(g)),
|
||||||
}
|
}
|
||||||
|
|
@ -311,7 +311,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for AnnounceRequest {
|
impl quickcheck::Arbitrary for AnnounceRequest {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connection_id: ConnectionId(i64::arbitrary(g)),
|
connection_id: ConnectionId(i64::arbitrary(g)),
|
||||||
transaction_id: TransactionId(i32::arbitrary(g)),
|
transaction_id: TransactionId(i32::arbitrary(g)),
|
||||||
|
|
@ -330,7 +330,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for ScrapeRequest {
|
impl quickcheck::Arbitrary for ScrapeRequest {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let info_hashes = (0..u8::arbitrary(g)).map(|_| {
|
let info_hashes = (0..u8::arbitrary(g)).map(|_| {
|
||||||
InfoHash::arbitrary(g)
|
InfoHash::arbitrary(g)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for TorrentScrapeStatistics {
|
impl quickcheck::Arbitrary for TorrentScrapeStatistics {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
seeders: NumberOfPeers(i32::arbitrary(g)),
|
seeders: NumberOfPeers(i32::arbitrary(g)),
|
||||||
completed: NumberOfDownloads(i32::arbitrary(g)),
|
completed: NumberOfDownloads(i32::arbitrary(g)),
|
||||||
|
|
@ -289,7 +289,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for ConnectResponse {
|
impl quickcheck::Arbitrary for ConnectResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connection_id: ConnectionId(i64::arbitrary(g)),
|
connection_id: ConnectionId(i64::arbitrary(g)),
|
||||||
transaction_id: TransactionId(i32::arbitrary(g)),
|
transaction_id: TransactionId(i32::arbitrary(g)),
|
||||||
|
|
@ -298,7 +298,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for AnnounceResponse {
|
impl quickcheck::Arbitrary for AnnounceResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let peers = (0..u8::arbitrary(g)).map(|_| {
|
let peers = (0..u8::arbitrary(g)).map(|_| {
|
||||||
ResponsePeer::arbitrary(g)
|
ResponsePeer::arbitrary(g)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
@ -314,7 +314,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl quickcheck::Arbitrary for ScrapeResponse {
|
impl quickcheck::Arbitrary for ScrapeResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let torrent_stats = (0..u8::arbitrary(g)).map(|_| {
|
let torrent_stats = (0..u8::arbitrary(g)).map(|_| {
|
||||||
TorrentScrapeStatistics::arbitrary(g)
|
TorrentScrapeStatistics::arbitrary(g)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
|
||||||
|
|
@ -37,5 +37,5 @@ socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
tungstenite = "0.11"
|
tungstenite = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,5 @@ slab = "0.4"
|
||||||
tungstenite = "0.11"
|
tungstenite = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,5 @@ tungstenite = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
quickcheck = "0.9"
|
quickcheck = "1.0"
|
||||||
quickcheck_macros = "0.9"
|
quickcheck_macros = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,7 @@ mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn arbitrary_20_bytes<G: quickcheck::Gen>(g: &mut G) -> [u8; 20] {
|
fn arbitrary_20_bytes(g: &mut quickcheck::Gen) -> [u8; 20] {
|
||||||
let mut bytes = [0u8; 20];
|
let mut bytes = [0u8; 20];
|
||||||
|
|
||||||
for byte in bytes.iter_mut() {
|
for byte in bytes.iter_mut() {
|
||||||
|
|
@ -335,25 +335,25 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for InfoHash {
|
impl Arbitrary for InfoHash {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self(arbitrary_20_bytes(g))
|
Self(arbitrary_20_bytes(g))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for PeerId {
|
impl Arbitrary for PeerId {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self(arbitrary_20_bytes(g))
|
Self(arbitrary_20_bytes(g))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for OfferId {
|
impl Arbitrary for OfferId {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self(arbitrary_20_bytes(g))
|
Self(arbitrary_20_bytes(g))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for AnnounceEvent {
|
impl Arbitrary for AnnounceEvent {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
match (bool::arbitrary(g), bool::arbitrary(g)){
|
match (bool::arbitrary(g), bool::arbitrary(g)){
|
||||||
(false, false) => Self::Started,
|
(false, false) => Self::Started,
|
||||||
(true, false) => Self::Started,
|
(true, false) => Self::Started,
|
||||||
|
|
@ -364,7 +364,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for MiddlemanOfferToPeer {
|
impl Arbitrary for MiddlemanOfferToPeer {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
action: AnnounceAction,
|
action: AnnounceAction,
|
||||||
peer_id: Arbitrary::arbitrary(g),
|
peer_id: Arbitrary::arbitrary(g),
|
||||||
|
|
@ -376,7 +376,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for MiddlemanAnswerToPeer {
|
impl Arbitrary for MiddlemanAnswerToPeer {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
action: AnnounceAction,
|
action: AnnounceAction,
|
||||||
peer_id: Arbitrary::arbitrary(g),
|
peer_id: Arbitrary::arbitrary(g),
|
||||||
|
|
@ -388,7 +388,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for AnnounceRequestOffer {
|
impl Arbitrary for AnnounceRequestOffer {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
offer_id: Arbitrary::arbitrary(g),
|
offer_id: Arbitrary::arbitrary(g),
|
||||||
offer: sdp_json_value()
|
offer: sdp_json_value()
|
||||||
|
|
@ -397,7 +397,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for AnnounceRequest {
|
impl Arbitrary for AnnounceRequest {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let has_offers_or_answer_or_neither: Option<bool> = Arbitrary::arbitrary(g);
|
let has_offers_or_answer_or_neither: Option<bool> = Arbitrary::arbitrary(g);
|
||||||
|
|
||||||
let mut offers: Option<Vec<AnnounceRequestOffer>> = None;
|
let mut offers: Option<Vec<AnnounceRequestOffer>> = None;
|
||||||
|
|
@ -436,7 +436,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for AnnounceResponse {
|
impl Arbitrary for AnnounceResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
action: AnnounceAction,
|
action: AnnounceAction,
|
||||||
info_hash: Arbitrary::arbitrary(g),
|
info_hash: Arbitrary::arbitrary(g),
|
||||||
|
|
@ -448,7 +448,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for ScrapeRequest {
|
impl Arbitrary for ScrapeRequest {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
action: ScrapeAction,
|
action: ScrapeAction,
|
||||||
info_hashes: Arbitrary::arbitrary(g),
|
info_hashes: Arbitrary::arbitrary(g),
|
||||||
|
|
@ -458,7 +458,7 @@ mod tests {
|
||||||
|
|
||||||
|
|
||||||
impl Arbitrary for ScrapeRequestInfoHashes {
|
impl Arbitrary for ScrapeRequestInfoHashes {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
if Arbitrary::arbitrary(g) {
|
if Arbitrary::arbitrary(g) {
|
||||||
ScrapeRequestInfoHashes::Multiple(Arbitrary::arbitrary(g))
|
ScrapeRequestInfoHashes::Multiple(Arbitrary::arbitrary(g))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -468,7 +468,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for ScrapeStatistics {
|
impl Arbitrary for ScrapeStatistics {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
Self {
|
Self {
|
||||||
complete: Arbitrary::arbitrary(g),
|
complete: Arbitrary::arbitrary(g),
|
||||||
incomplete: Arbitrary::arbitrary(g),
|
incomplete: Arbitrary::arbitrary(g),
|
||||||
|
|
@ -478,7 +478,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for ScrapeResponse {
|
impl Arbitrary for ScrapeResponse {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
let files: Vec<(InfoHash, ScrapeStatistics)> = Arbitrary::arbitrary(g);
|
let files: Vec<(InfoHash, ScrapeStatistics)> = Arbitrary::arbitrary(g);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -489,7 +489,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for InMessage {
|
impl Arbitrary for InMessage {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
if Arbitrary::arbitrary(g){
|
if Arbitrary::arbitrary(g){
|
||||||
Self::AnnounceRequest(Arbitrary::arbitrary(g))
|
Self::AnnounceRequest(Arbitrary::arbitrary(g))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -499,7 +499,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arbitrary for OutMessage {
|
impl Arbitrary for OutMessage {
|
||||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||||
match (Arbitrary::arbitrary(g), Arbitrary::arbitrary(g)){
|
match (Arbitrary::arbitrary(g), Arbitrary::arbitrary(g)){
|
||||||
(false, false) => Self::AnnounceResponse(Arbitrary::arbitrary(g)),
|
(false, false) => Self::AnnounceResponse(Arbitrary::arbitrary(g)),
|
||||||
(true, false) => Self::ScrapeResponse(Arbitrary::arbitrary(g)),
|
(true, false) => Self::ScrapeResponse(Arbitrary::arbitrary(g)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue