From a4e5a1b39d40a74a602ee12ddc0033cdbb33a6de Mon Sep 17 00:00:00 2001 From: Chenhao Zuo Date: Tue, 24 Dec 2024 17:16:36 -0800 Subject: [PATCH] Fix the flaky test `buck2/shed/static_interner` Summary: The `test_disposition` test was sharing the static `STRING_INTERNER` variable with `test_intern,` and both tests used the string `"hello"`. When tests run in parallel, if `test_intern` runs first, it causes `test_disposition` to fail. This fix adds a dedicated `TEST_DISPOSITION_STRING` interner to isolate the tests from each other. It also move the test downside to separate from tests using `STRING_INTERNER` Reviewed By: blackm00n Differential Revision: D67626618 fbshipit-source-id: 6d51485f919a4c4b09608a7afe36242dbc405d41 --- shed/static_interner/src/lib.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/shed/static_interner/src/lib.rs b/shed/static_interner/src/lib.rs index 0cfafde828f0..0d2a968ea88a 100644 --- a/shed/static_interner/src/lib.rs +++ b/shed/static_interner/src/lib.rs @@ -311,17 +311,6 @@ mod tests { ); } - #[test] - fn test_disposition() { - let (val, disposition) = STRING_INTERNER.observed_intern("hello".to_owned()); - assert_eq!(val.to_string(), "hello".to_owned()); - assert!(std::matches!(disposition, InternDisposition::Computed)); - - let (val, disposition) = STRING_INTERNER.observed_intern("hello".to_owned()); - assert_eq!(val.to_string(), "hello".to_owned()); - assert!(std::matches!(disposition, InternDisposition::Interned)); - } - // Make sure things work with reallocation. #[test] fn test_resize() { @@ -351,6 +340,18 @@ mod tests { } } + static TEST_DISPOSITION_STRING: Interner = Interner::new(); + #[test] + fn test_disposition() { + let (val, disposition) = TEST_DISPOSITION_STRING.observed_intern("hello".to_owned()); + assert_eq!(val.to_string(), "hello".to_owned()); + assert!(std::matches!(disposition, InternDisposition::Computed)); + + let (val, disposition) = TEST_DISPOSITION_STRING.observed_intern("hello".to_owned()); + assert_eq!(val.to_string(), "hello".to_owned()); + assert!(std::matches!(disposition, InternDisposition::Interned)); + } + static TEST_GET_INTERNER: Interner = Interner::new(); #[test] fn test_get() {