Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Jun 15, 2022
1 parent aae0753 commit b87ad5c
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/advertisement/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async fn insert_same_node() {

let topic = Topic::new(std::str::from_utf8(&[1u8; 32]).unwrap()).hash();

ads.insert(enr.clone(), topic.clone()).unwrap();
ads.insert(enr.clone(), topic).unwrap();

// Since 2 seconds haven't passed
assert_eq!(
ads.insert(enr.clone(), topic.clone()).map_err(|e| e),
Err("Node already advertising this topic".into())
ads.insert(enr.clone(), topic).map_err(|e| e),
Err("Node already advertising this topic")
);

tokio::time::sleep(Duration::from_secs(2)).await;
Expand All @@ -49,19 +49,19 @@ async fn insert_ad_and_get_nodes() {
let topic_2 = Topic::new(std::str::from_utf8(&[2u8; 32]).unwrap()).hash();

// Add an ad for topic from enr
ads.insert(enr.clone(), topic.clone()).unwrap();
ads.insert(enr.clone(), topic).unwrap();

// The ad hasn't expired and duplicates are not allowed
assert_eq!(
ads.insert(enr.clone(), topic.clone()).map_err(|e| e),
Err("Node already advertising this topic".into())
ads.insert(enr.clone(), topic).map_err(|e| e),
Err("Node already advertising this topic")
);

// Add an ad for topic from enr_2
ads.insert(enr_2.clone(), topic.clone()).unwrap();
ads.insert(enr_2.clone(), topic).unwrap();

// Add an ad for topic_2 from enr
ads.insert(enr.clone(), topic_2.clone()).unwrap();
ads.insert(enr.clone(), topic_2).unwrap();

let nodes: Vec<&Enr> = ads
.get_ad_nodes(topic)
Expand Down Expand Up @@ -97,10 +97,10 @@ async fn ticket_wait_time_duration() {
let topic = Topic::new(std::str::from_utf8(&[1u8; 32]).unwrap()).hash();

// Add an add for topic
ads.insert(enr.clone(), topic.clone()).unwrap();
ads.insert(enr, topic).unwrap();

assert_gt!(
ads.ticket_wait_time(topic.clone()),
ads.ticket_wait_time(topic),
Some(Duration::from_secs(2))
);
assert_lt!(ads.ticket_wait_time(topic), Some(Duration::from_secs(3)));
Expand All @@ -125,16 +125,16 @@ async fn ticket_wait_time_full_table() {
let topic_2 = Topic::new(std::str::from_utf8(&[2u8; 32]).unwrap()).hash();

// Add 2 ads for topic
ads.insert(enr.clone(), topic.clone()).unwrap();
ads.insert(enr_2.clone(), topic.clone()).unwrap();
ads.insert(enr.clone(), topic).unwrap();
ads.insert(enr_2.clone(), topic).unwrap();

tokio::time::sleep(Duration::from_secs(2)).await;

// Add an ad for topic_2
ads.insert(enr.clone(), topic_2.clone()).unwrap();
ads.insert(enr.clone(), topic_2).unwrap();

// Now max_ads in table is reached so the second ad for topic_2 has to wait
assert_ne!(ads.ticket_wait_time(topic_2.clone()), None);
assert_ne!(ads.ticket_wait_time(topic_2), None);

tokio::time::sleep(Duration::from_secs(3)).await;

Expand Down Expand Up @@ -163,20 +163,20 @@ async fn ticket_wait_time_full_topic() {
let topic_2 = Topic::new(std::str::from_utf8(&[2u8; 32]).unwrap()).hash();

// Add 2 ads for topic
ads.insert(enr.clone(), topic.clone()).unwrap();
ads.insert(enr_2.clone(), topic.clone()).unwrap();
ads.insert(enr.clone(), topic).unwrap();
ads.insert(enr_2.clone(), topic).unwrap();

// Now max_ads_per_topic is reached for topic
assert_ne!(ads.ticket_wait_time(topic.clone()), None);
assert_ne!(ads.ticket_wait_time(topic), None);

// Add a topic_2 ad
ads.insert(enr, topic_2.clone()).unwrap();
ads.insert(enr, topic_2).unwrap();

// The table isn't full so topic_2 ads don't have to wait
assert_eq!(ads.ticket_wait_time(topic_2), None);

// But for topic they do until the first ads have expired
assert_ne!(ads.ticket_wait_time(topic.clone()), None);
assert_ne!(ads.ticket_wait_time(topic), None);

tokio::time::sleep(Duration::from_secs(3)).await;
assert_eq!(ads.ticket_wait_time(topic), None);
Expand Down

0 comments on commit b87ad5c

Please sign in to comment.