mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
udp: add quickcheck test for ConnectionValidator
This commit is contained in:
parent
1e5b98bcf6
commit
07630d2e0c
1 changed files with 27 additions and 2 deletions
|
|
@ -267,9 +267,13 @@ impl State {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::Ipv6Addr;
|
||||
use std::net::{Ipv6Addr, SocketAddr};
|
||||
|
||||
use crate::{common::MAX_PACKET_SIZE, config::Config};
|
||||
use quickcheck_macros::quickcheck;
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_peer_status_from_event_and_bytes_left() {
|
||||
|
|
@ -323,4 +327,25 @@ mod tests {
|
|||
|
||||
assert!(buf.len() <= MAX_PACKET_SIZE);
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
fn test_connection_validator(addr: IpAddr, max_connection_age: u32) -> bool {
|
||||
let addr = CanonicalSocketAddr::new(SocketAddr::new(addr, 0));
|
||||
|
||||
let mut config = Config::default();
|
||||
|
||||
config.cleaning.max_connection_age = max_connection_age;
|
||||
|
||||
let mut validator = ConnectionValidator::new(&config).unwrap();
|
||||
|
||||
let connection_id = validator.create_connection_id(addr);
|
||||
|
||||
let valid = validator.connection_id_valid(addr, connection_id);
|
||||
|
||||
if max_connection_age == 0 {
|
||||
!valid
|
||||
} else {
|
||||
valid // Note: depends on that running this test takes less than a second
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue