Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer committed Feb 12, 2025
1 parent 09a8ad2 commit 49be144
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions relay-server/src/middlewares/body_timing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ mod tests {
}
}

fn captures_match(captures: Vec<String>, expected: &str) -> bool {
let (head, tail) = expected.split_once("|h").unwrap();
captures.len() == 1 && captures[0].starts_with(head) && captures[0].ends_with(tail)
}

#[test]
fn test_empty_body() {
let captures = with_capturing_test_client(|| {
Expand All @@ -182,10 +187,10 @@ mod tests {

let _ = pinned.poll_frame(&mut cx);
});
assert_eq!(
assert!(captures_match(
captures,
["requests.body_read.duration:0|ms|#route:unknown,size:lt1KB,status:completed"]
);
"requests.body_read.duration:0|h|#route:unknown,size:lt1KB,status:completed"
));
}

#[test]
Expand All @@ -201,10 +206,10 @@ mod tests {
let _ = pinned.as_mut().poll_frame(&mut cx);
let _ = pinned.as_mut().poll_frame(&mut cx);
});
assert_eq!(
assert!(captures_match(
captures,
["requests.body_read.duration:0|ms|#route:unknown,size:lt1KB,status:completed"]
);
"requests.body_read.duration:0|h|#route:unknown,size:lt1KB,status:completed"
));
}

#[test]
Expand All @@ -219,10 +224,11 @@ mod tests {

let _ = pinned.poll_frame(&mut cx);
});
assert_eq!(

assert!(captures_match(
captures,
["requests.body_read.duration:0|ms|#route:unknown,size:lt1KB,status:dropped"]
)
"requests.body_read.duration:0|h|#route:unknown,size:lt1KB,status:dropped"
))
}

#[test]
Expand All @@ -246,10 +252,10 @@ mod tests {
let pinned = Pin::new(&mut timed_body);
let _ = pinned.poll_frame(&mut cx);
});
assert_eq!(
assert!(captures_match(
captures,
["requests.body_read.duration:0|ms|#route:unknown,size:lt1KB,status:failed"]
)
"requests.body_read.duration:0|h|#route:unknown,size:lt1KB,status:failed"
))
}

#[test]
Expand All @@ -266,10 +272,10 @@ mod tests {
let mut pinned = Pin::new(&mut timed_body);
while let Poll::Ready(Some(Ok(_))) = pinned.as_mut().poll_frame(&mut cx) {}
});
assert_eq!(
assert!(captures_match(
captures,
["requests.body_read.duration:0|ms|#route:unknown,size:lt10KB,status:completed"]
)
"requests.body_read.duration:0|h|#route:unknown,size:lt10KB,status:completed"
))
}

#[test]
Expand Down

0 comments on commit 49be144

Please sign in to comment.