Skip to content

Commit

Permalink
Fix the flaky test buck2/shed/static_interner
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Nero5023 authored and facebook-github-bot committed Dec 25, 2024
1 parent c2b2357 commit a4e5a1b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions shed/static_interner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -351,6 +340,18 @@ mod tests {
}
}

static TEST_DISPOSITION_STRING: Interner<String> = 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<String> = Interner::new();
#[test]
fn test_get() {
Expand Down

0 comments on commit a4e5a1b

Please sign in to comment.