Upgrade quickcheck to 1.0, adjust code, optimizing a slow test

This commit is contained in:
Joakim Frostegård 2021-02-04 19:34:44 +01:00
parent 72ff55ae5d
commit f9626ade57
19 changed files with 78 additions and 74 deletions

15
Cargo.lock generated
View file

@ -602,9 +602,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "env_logger"
version = "0.7.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e"
dependencies = [
"log",
"regex",
@ -1216,21 +1216,20 @@ dependencies = [
[[package]]
name = "quickcheck"
version = "0.9.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f"
checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6"
dependencies = [
"env_logger",
"log",
"rand 0.7.3",
"rand_core 0.5.1",
"rand 0.8.3",
]
[[package]]
name = "quickcheck_macros"
version = "0.9.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "608c156fd8e97febc07dc9c2e2c80bf74cfc6ef26893eae3daf8bc2bc94a4b7f"
checksum = "b22a693222d716a9587786f37ac3f6b4faedb5b80c23914e7303ff5a1d8016e9"
dependencies = [
"proc-macro2",
"quote",

View file

@ -35,6 +35,9 @@ aquatic_ws_protocol = { path = "aquatic_ws_protocol" }
debug = true
lto = true
[profile.test]
opt-level = 3
[profile.bench]
debug = true
opt-level = 3

View file

@ -39,5 +39,5 @@ smartstring = "0.2"
socket2 = { version = "0.3", features = ["reuseport"] }
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -21,5 +21,5 @@ rand_distr = "0.4"
serde = { version = "1", features = ["derive"] }
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -43,5 +43,5 @@ urlencoding = "1"
[dev-dependencies]
bendy = { version = "0.3", features = ["std", "serde"] }
criterion = "0.3"
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -60,7 +60,7 @@ impl FromStr for AnnounceEvent {
#[cfg(test)]
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];
for byte in arr.iter_mut(){
@ -74,7 +74,7 @@ impl quickcheck::Arbitrary for InfoHash {
#[cfg(test)]
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];
for byte in arr.iter_mut(){
@ -88,7 +88,7 @@ impl quickcheck::Arbitrary for PeerId {
#[cfg(test)]
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)){
(false, false) => Self::Started,
(true, false) => Self::Started,

View file

@ -322,7 +322,7 @@ mod tests {
}
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);
AnnounceRequest {
@ -339,7 +339,7 @@ mod tests {
}
impl Arbitrary for ScrapeRequest {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
ScrapeRequest {
info_hashes: Arbitrary::arbitrary(g),
}
@ -347,7 +347,7 @@ mod tests {
}
impl Arbitrary for Request {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
if Arbitrary::arbitrary(g){
Self::Announce(Arbitrary::arbitrary(g))
} else {

View file

@ -192,7 +192,7 @@ impl Response {
#[cfg(test)]
impl quickcheck::Arbitrary for ResponsePeer<Ipv4Addr> {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
ip_address: Ipv4Addr::arbitrary(g),
port: u16::arbitrary(g)
@ -203,7 +203,7 @@ impl quickcheck::Arbitrary for ResponsePeer<Ipv4Addr> {
#[cfg(test)]
impl quickcheck::Arbitrary for ResponsePeer<Ipv6Addr> {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
ip_address: Ipv6Addr::arbitrary(g),
port: u16::arbitrary(g)
@ -214,7 +214,7 @@ impl quickcheck::Arbitrary for ResponsePeer<Ipv6Addr> {
#[cfg(test)]
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))
}
}
@ -222,7 +222,7 @@ impl quickcheck::Arbitrary for ResponsePeerListV4 {
#[cfg(test)]
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))
}
}
@ -230,7 +230,7 @@ impl quickcheck::Arbitrary for ResponsePeerListV6 {
#[cfg(test)]
impl quickcheck::Arbitrary for ScrapeStatistics {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
complete: usize::arbitrary(g),
incomplete: usize::arbitrary(g),
@ -242,7 +242,7 @@ impl quickcheck::Arbitrary for ScrapeStatistics {
#[cfg(test)]
impl quickcheck::Arbitrary for AnnounceResponse {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
announce_interval: usize::arbitrary(g),
complete: usize::arbitrary(g),
@ -256,7 +256,7 @@ impl quickcheck::Arbitrary for AnnounceResponse {
#[cfg(test)]
impl quickcheck::Arbitrary for ScrapeResponse {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
files: BTreeMap::arbitrary(g),
}
@ -266,7 +266,7 @@ impl quickcheck::Arbitrary for ScrapeResponse {
#[cfg(test)]
impl quickcheck::Arbitrary for FailureResponse {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
failure_reason: String::arbitrary(g),
}

View file

@ -33,5 +33,5 @@ serde = { version = "1", features = ["derive"] }
socket2 = { version = "0.3", features = ["reuseport"] }
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -414,17 +414,19 @@ mod tests {
#[test]
fn test_extract_response_peers(){
fn prop(data: (u32, u16)) -> TestResult {
let gen_num_peers = data.0;
fn prop(data: (u16, u16)) -> TestResult {
let gen_num_peers = data.0 as u32;
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_peer = None;
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 {
opt_sender_key = Some(key);
@ -456,7 +458,7 @@ mod tests {
// Check that returned peers are unique (no overlap) and that sender
// isn't returned
let mut ip_addresses = HashSet::new();
let mut ip_addresses = HashSet::with_capacity(peers.len());
for peer in peers {
if peer == opt_sender_peer.clone().unwrap() || ip_addresses.contains(&peer.ip_address){
@ -471,6 +473,6 @@ mod tests {
TestResult::from_bool(success)
}
quickcheck(prop as fn((u32, u16)) -> TestResult);
quickcheck(prop as fn((u16, u16)) -> TestResult);
}
}

View file

@ -24,5 +24,5 @@ serde = { version = "1", features = ["derive"] }
socket2 = { version = "0.3", features = ["reuseport"] }
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -11,5 +11,5 @@ repository = "https://github.com/greatest-ape/aquatic"
byteorder = "1"
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -52,7 +52,7 @@ pub struct ResponsePeer {
#[cfg(test)]
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) {
IpVersion::IPv4
} else {
@ -64,7 +64,7 @@ impl quickcheck::Arbitrary for IpVersion {
#[cfg(test)]
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];
for byte in bytes.iter_mut() {
@ -78,7 +78,7 @@ impl quickcheck::Arbitrary for InfoHash {
#[cfg(test)]
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];
for byte in bytes.iter_mut() {
@ -92,7 +92,7 @@ impl quickcheck::Arbitrary for PeerId {
#[cfg(test)]
impl quickcheck::Arbitrary for ResponsePeer {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
ip_address: ::std::net::IpAddr::arbitrary(g),
port: Port(u16::arbitrary(g)),

View file

@ -292,7 +292,7 @@ mod tests {
use super::*;
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)){
(false, false) => Self::Started,
(true, false) => Self::Started,
@ -303,7 +303,7 @@ mod tests {
}
impl quickcheck::Arbitrary for ConnectRequest {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
transaction_id: TransactionId(i32::arbitrary(g)),
}
@ -311,7 +311,7 @@ mod tests {
}
impl quickcheck::Arbitrary for AnnounceRequest {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
connection_id: ConnectionId(i64::arbitrary(g)),
transaction_id: TransactionId(i32::arbitrary(g)),
@ -330,7 +330,7 @@ mod tests {
}
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(|_| {
InfoHash::arbitrary(g)
}).collect();

View file

@ -279,7 +279,7 @@ mod tests {
use super::*;
impl quickcheck::Arbitrary for TorrentScrapeStatistics {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
seeders: NumberOfPeers(i32::arbitrary(g)),
completed: NumberOfDownloads(i32::arbitrary(g)),
@ -289,7 +289,7 @@ mod tests {
}
impl quickcheck::Arbitrary for ConnectResponse {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
connection_id: ConnectionId(i64::arbitrary(g)),
transaction_id: TransactionId(i32::arbitrary(g)),
@ -298,7 +298,7 @@ mod tests {
}
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(|_| {
ResponsePeer::arbitrary(g)
}).collect();
@ -314,7 +314,7 @@ mod tests {
}
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(|_| {
TorrentScrapeStatistics::arbitrary(g)
}).collect();

View file

@ -37,5 +37,5 @@ socket2 = { version = "0.3", features = ["reuseport"] }
tungstenite = "0.11"
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -24,5 +24,5 @@ slab = "0.4"
tungstenite = "0.11"
[dev-dependencies]
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -26,5 +26,5 @@ tungstenite = "0.11"
[dev-dependencies]
criterion = "0.3"
quickcheck = "0.9"
quickcheck_macros = "0.9"
quickcheck = "1.0"
quickcheck_macros = "1.0"

View file

@ -320,7 +320,7 @@ mod tests {
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];
for byte in bytes.iter_mut() {
@ -335,25 +335,25 @@ mod tests {
}
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))
}
}
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))
}
}
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))
}
}
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)){
(false, false) => Self::Started,
(true, false) => Self::Started,
@ -364,7 +364,7 @@ mod tests {
}
impl Arbitrary for MiddlemanOfferToPeer {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
action: AnnounceAction,
peer_id: Arbitrary::arbitrary(g),
@ -376,7 +376,7 @@ mod tests {
}
impl Arbitrary for MiddlemanAnswerToPeer {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
action: AnnounceAction,
peer_id: Arbitrary::arbitrary(g),
@ -388,7 +388,7 @@ mod tests {
}
impl Arbitrary for AnnounceRequestOffer {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
offer_id: Arbitrary::arbitrary(g),
offer: sdp_json_value()
@ -397,7 +397,7 @@ mod tests {
}
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 mut offers: Option<Vec<AnnounceRequestOffer>> = None;
@ -436,7 +436,7 @@ mod tests {
}
impl Arbitrary for AnnounceResponse {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
action: AnnounceAction,
info_hash: Arbitrary::arbitrary(g),
@ -448,7 +448,7 @@ mod tests {
}
impl Arbitrary for ScrapeRequest {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
action: ScrapeAction,
info_hashes: Arbitrary::arbitrary(g),
@ -458,7 +458,7 @@ mod tests {
impl Arbitrary for ScrapeRequestInfoHashes {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
if Arbitrary::arbitrary(g) {
ScrapeRequestInfoHashes::Multiple(Arbitrary::arbitrary(g))
} else {
@ -468,7 +468,7 @@ mod tests {
}
impl Arbitrary for ScrapeStatistics {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
Self {
complete: Arbitrary::arbitrary(g),
incomplete: Arbitrary::arbitrary(g),
@ -478,7 +478,7 @@ mod tests {
}
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);
Self {
@ -489,7 +489,7 @@ mod tests {
}
impl Arbitrary for InMessage {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
if Arbitrary::arbitrary(g){
Self::AnnounceRequest(Arbitrary::arbitrary(g))
} else {
@ -499,7 +499,7 @@ mod tests {
}
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)){
(false, false) => Self::AnnounceResponse(Arbitrary::arbitrary(g)),
(true, false) => Self::ScrapeResponse(Arbitrary::arbitrary(g)),