diff mbox series

rust: Fix flaky assertions in oneshot tests

Message ID 20260325090543.3489042-1-Deepesh.Varatharajan@windriver.com
State Under Review
Headers show
Series rust: Fix flaky assertions in oneshot tests | expand

Commit Message

Varatharajan, Deepesh March 25, 2026, 9:05 a.m. UTC
From: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>

Fixes [YOCTO #16199]

Backport three commits from upstream to fix flaky assertions in oneshot tests

https://github.com/rust-lang/rust/commit/6970849fee93900b6eb28a64cf957157a9fb51b3
https://github.com/rust-lang/rust/commit/dab350a3ed7691201f6752c4375e8e6ab40b58b9
https://github.com/rust-lang/rust/commit/d02743e2fd7433ba2320fc85421a8a5927235b65

Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
---
 ...ix-flaky-assertions-in-oneshot-tests.patch | 72 +++++++++++++++++++
 meta/recipes-devtools/rust/rust-source.inc    |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 meta/recipes-devtools/rust/files/0001-Fix-flaky-assertions-in-oneshot-tests.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/files/0001-Fix-flaky-assertions-in-oneshot-tests.patch b/meta/recipes-devtools/rust/files/0001-Fix-flaky-assertions-in-oneshot-tests.patch
new file mode 100644
index 0000000000..be0e85dfbb
--- /dev/null
+++ b/meta/recipes-devtools/rust/files/0001-Fix-flaky-assertions-in-oneshot-tests.patch
@@ -0,0 +1,72 @@ 
+Backport three commits from upstream to fix flaky assertions in oneshot tests
+
+Upstream-Status: Backport [https://github.com/rust-lang/rust/commit/6970849fee93900b6eb28a64cf957157a9fb51b3]
+Upstream-Status: Backport [https://github.com/rust-lang/rust/commit/dab350a3ed7691201f6752c4375e8e6ab40b58b9]
+Upstream-Status: Backport [https://github.com/rust-lang/rust/commit/d02743e2fd7433ba2320fc85421a8a5927235b65]
+
+Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
+
+diff --git a/library/std/tests/sync/oneshot.rs b/library/std/tests/sync/oneshot.rs
+index 6a87c72..d8f3cd7 100644
+--- a/library/std/tests/sync/oneshot.rs
++++ b/library/std/tests/sync/oneshot.rs
+@@ -89,15 +89,15 @@ fn send_before_recv_timeout() {
+ 
+     assert!(sender.send(22i128).is_ok());
+ 
+-    let start = Instant::now();
+-
+     let timeout = Duration::from_secs(1);
+     match receiver.recv_timeout(timeout) {
+         Ok(22) => {}
+         _ => panic!("expected Ok(22)"),
+     }
+ 
+-    assert!(start.elapsed() < timeout);
++    // FIXME(#152648): There previously was a timing assertion here.
++    // This was removed, because under load there's no guarantee that the main thread is
++    // scheduled and run before `timeout` expires
+ }
+ 
+ #[test]
+@@ -127,6 +127,7 @@ fn recv_before_send() {
+ }
+ 
+ #[test]
++#[ignore = "Inherently flaky and has caused several CI failures"]
+ fn recv_timeout_before_send() {
+     let (sender, receiver) = oneshot::channel();
+ 
+@@ -135,6 +136,8 @@ fn recv_timeout_before_send() {
+         sender.send(99u128).unwrap();
+     });
+ 
++    // FIXME(#152145): Under load, there's no guarantee that thread `t` has
++    // ever been scheduled and run before this timeout expires.
+     match receiver.recv_timeout(Duration::from_secs(1)) {
+         Ok(99) => {}
+         _ => panic!("expected Ok(99)"),
+@@ -240,7 +243,9 @@ fn recv_deadline_passed() {
+     }
+ 
+     assert!(start.elapsed() >= timeout);
+-    assert!(start.elapsed() < timeout * 3);
++    // FIXME(#152878): An upper-bound assertion on the elapsed time was removed,
++    // because CI runners can starve individual threads for a surprisingly long
++    // time, leading to flaky failures.
+ }
+ 
+ #[test]
+@@ -253,8 +258,11 @@ fn recv_time_passed() {
+         Err(RecvTimeoutError::Timeout(_)) => {}
+         _ => panic!("expected timeout error"),
+     }
++
+     assert!(start.elapsed() >= timeout);
+-    assert!(start.elapsed() < timeout * 3);
++    // FIXME(#152878): An upper-bound assertion on the elapsed time was removed,
++    // because CI runners can starve individual threads for a surprisingly long
++    // time, leading to flaky failures.
+ }
+ 
+ #[test]
diff --git a/meta/recipes-devtools/rust/rust-source.inc b/meta/recipes-devtools/rust/rust-source.inc
index 47a0154cdc..4579b6bf6a 100644
--- a/meta/recipes-devtools/rust/rust-source.inc
+++ b/meta/recipes-devtools/rust/rust-source.inc
@@ -7,6 +7,7 @@  SRC_URI += "https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.xz;n
             file://0001-src-core-build_steps-tool.rs-switch-off-lto-for-rust.patch;patchdir=${RUSTSRC} \
             file://0001-riscv32-Define-plain-syscalls-as-their-time64-varian.patch;patchdir=${RUSTSRC} \
             file://0001-Update-call-llvm-intrinsics-test.patch;patchdir=${RUSTSRC} \
+            file://0001-Fix-flaky-assertions-in-oneshot-tests.patch;patchdir=${RUSTSRC} \
 "
 SRC_URI[rust.sha256sum] = "0b53ae34f5c0c3612cfe1de139f9167a018cd5737bc2205664fd69ba9b25f600"