From f1c085ef62f612773eea971c00b495ab331110a6 Mon Sep 17 00:00:00 2001 From: Andrew Stoycos Date: Wed, 12 Jul 2023 14:13:22 -0400 Subject: [PATCH] fix loaded_programs() race in int-tests in the integration tests we recenctly switched to using our internal api to list programs. I was seeing times when this would race and panic internally (program fd was deleted by aya WHILE we were trying to get it). This ensures that the list succeeded without panicking. Signed-off-by: Andrew Stoycos --- test/integration-test/tests/load.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/integration-test/tests/load.rs b/test/integration-test/tests/load.rs index de076e87..695f2341 100644 --- a/test/integration-test/tests/load.rs +++ b/test/integration-test/tests/load.rs @@ -67,9 +67,12 @@ fn is_linked(prog_id: &u32) -> bool { macro_rules! assert_loaded_and_linked { ($name:literal, $loaded:expr) => { for i in 0..(MAX_RETRIES + 1) { + // Ignore race failures which can happen when the tests delete a + // program in the middle of a `loaded_programs()` call. let id = loaded_programs() - .find(|prog| prog.as_ref().unwrap().name() == $name.as_bytes()) - .map(|prog| Some(prog.unwrap().id())); + .filter_map(|prog| prog.ok()) + .find(|prog| prog.name() == $name.as_bytes()) + .map(|prog| Some(prog.id())); let mut linked = false; if let Some(prog_id) = id { linked = is_linked(&prog_id.unwrap()); @@ -94,7 +97,12 @@ macro_rules! assert_loaded_and_linked { macro_rules! assert_loaded { ($name:literal, $loaded:expr) => { for i in 0..(MAX_RETRIES + 1) { - let state = loaded_programs().any(|prog| prog.unwrap().name() == $name.as_bytes()); + // Ignore race failures which can happen when the tests delete a + // program in the middle of a `loaded_programs()` call. + let state = loaded_programs() + .filter_map(|prog| prog.ok()) + .any(|prog| prog.name() == $name.as_bytes()); + if state == $loaded { break; }