diff mbox series

[meta-python] python3-yappi: Fix a flaky gevent ptest

Message ID 20261205080524.1026093-1-khem.raj@oss.qualcomm.com
State New
Headers show
Series [meta-python] python3-yappi: Fix a flaky gevent ptest | expand

Commit Message

Khem Raj Dec. 5, 2026, 8:05 a.m. UTC
test_context_cbks_reset_to_default expects the worker thread, which burns
50ms of CPU, to sort before the main thread by total time. On a loaded
QEMU guest the main thread can use more than that while gevent creates its
hub, which swaps the order and fails the test. Look the stats up by thread
id instead.

Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
 ...ts-Look-up-thread-stats-by-thread-id.patch | 49 +++++++++++++++++++
 .../python/python3-yappi_1.7.7.bb             |  1 +
 2 files changed, 50 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-yappi/0004-tests-Look-up-thread-stats-by-thread-id.patch
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-yappi/0004-tests-Look-up-thread-stats-by-thread-id.patch b/meta-python/recipes-devtools/python/python3-yappi/0004-tests-Look-up-thread-stats-by-thread-id.patch
new file mode 100644
index 0000000000..ef45a724e6
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-yappi/0004-tests-Look-up-thread-stats-by-thread-id.patch
@@ -0,0 +1,49 @@ 
+From 11b7485d904da0fe2c5f3dc9bc71285a99b57f05 Mon Sep 17 00:00:00 2001
+From: Khem Raj <khem.raj@oss.qualcomm.com>
+Date: Fri, 4 Dec 2026 18:30:56 -0800
+Subject: [PATCH] tests: Look up thread stats by thread id in
+ test_context_cbks_reset_to_default
+
+The test assumed ThreadA, which burns 50ms of CPU, sorts before the main
+thread by ttot. The main thread also accumulates CPU time while gevent
+creates its hub for the greenlet, and on a slow or loaded machine (e.g.
+a QEMU guest) that can exceed 50ms, swapping the order:
+
+  AssertionError: 140529029749696 != 140528074962624
+
+Match the stats to threads by tid instead of relying on the sort order.
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
+---
+ tests/test_gevent.py | 13 +++++++++----
+ 1 file changed, 9 insertions(+), 4 deletions(-)
+
+diff --git a/tests/test_gevent.py b/tests/test_gevent.py
+index ed9e6ae..882d51a 100644
+--- a/tests/test_gevent.py
++++ b/tests/test_gevent.py
+@@ -151,13 +151,18 @@ class TestAPI(GeventTest):
+             len(tstats), 2, "Incorrect number of contexts captured"
+         )
+ 
+-        # First stat should be of threadA since it is sorted by ttot
+-        statsA = tstats[0]
++        # Look the stats up by thread id: the main thread can use more CPU
++        # than threadA (e.g. while gevent creates its hub), so the ttot
++        # order is not fixed.
++        stats = {s.tid: s for s in tstats}
++        main_thread = threading.current_thread()
++        self.assertEqual(set(stats), {t.ident, main_thread.ident})
++
++        statsA = stats[t.ident]
+         self.assertEqual(statsA.tid, t.ident)
+         self.assertEqual(statsA.name, t.__class__.__name__)
+ 
+-        statsMain = tstats[1]
+-        main_thread = threading.current_thread()
++        statsMain = stats[main_thread.ident]
+         self.assertEqual(statsMain.tid, main_thread.ident)
+         self.assertEqual(statsMain.name, main_thread.__class__.__name__)
+ 
diff --git a/meta-python/recipes-devtools/python/python3-yappi_1.7.7.bb b/meta-python/recipes-devtools/python/python3-yappi_1.7.7.bb
index 9a0a38b9bc..8c4546fe76 100644
--- a/meta-python/recipes-devtools/python/python3-yappi_1.7.7.bb
+++ b/meta-python/recipes-devtools/python/python3-yappi_1.7.7.bb
@@ -8,6 +8,7 @@  LIC_FILES_CHKSUM = "file://LICENSE;md5=71c208c9a4fd864385eb69ad4caa3bee"
 SRC_URI = "git://github.com/sumerc/yappi.git;protocol=https;branch=master;tag=v${PV} \
            file://0002-Fix-import-of-tests.utils-to-enable-pytest.patch \
            file://0003-Detect-suspended-coroutines-on-Python-3.15-and-newer.patch \
+           file://0004-tests-Look-up-thread-stats-by-thread-id.patch \
            "
 SRCREV = "d6593ea0bce0a13c65bd44511c3cee858b5985e8"
 UPSTREAM_CHECK_GITTAGREGEX = "^v(?P<pver>\d+(\.\d+)+)$"