Merge pull request #800 from ajwerner/deflake-loaded-at-take-2

integration-test: deflake test_loaded_at
pull/803/head
ajwerner 12 months ago committed by GitHub
commit c547dd7bcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -154,22 +154,36 @@ fn unload_xdp() {
fn test_loaded_at() { fn test_loaded_at() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Bpf::load(crate::TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
// SystemTime is not monotonic, which can cause this test to flake. We don't expect the clock
// timestamp to continuously jump around, so we add some retries. If the test is ever correct,
// we know that the value returned by loaded_at() was reasonable relative to SystemTime::now().
let mut failures = Vec::new();
for _ in 0..5 {
let t1 = SystemTime::now(); let t1 = SystemTime::now();
prog.load().unwrap(); prog.load().unwrap();
let t2 = SystemTime::now(); let t2 = SystemTime::now();
assert_loaded("pass");
let loaded_at = prog.info().unwrap().loaded_at(); let loaded_at = prog.info().unwrap().loaded_at();
prog.unload().unwrap();
let range = t1..t2; let range = t1..t2;
if range.contains(&loaded_at) {
failures.clear();
break;
}
failures.push(LoadedAtRange(loaded_at, range));
}
assert!( assert!(
range.contains(&loaded_at), failures.is_empty(),
"{range:?}.contains({loaded_at:?})" "loaded_at was not in range: {failures:?}",
); );
prog.unload().unwrap(); struct LoadedAtRange(SystemTime, std::ops::Range<SystemTime>);
impl std::fmt::Debug for LoadedAtRange {
assert_unloaded("pass"); fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self(loaded_at, range) = self;
write!(f, "{range:?}.contains({loaded_at:?})")
}
}
} }
#[test] #[test]

Loading…
Cancel
Save