aports/community/babeltrace/fix-test_message_iterator.py-hangs-on-Python-3.12.patch
2024-04-12 11:59:22 +02:00

49 lines
2.0 KiB
Diff

From da110483eccb522d3db135a903bb1366cd039207 Mon Sep 17 00:00:00 2001
From: Michael Jeanson <mjeanson@debian.org>
Date: Fri, 16 Jun 2023 12:12:52 -0400
Subject: [PATCH] fix: test_message_iterator.py hangs on Python 3.12
Starting with Python 3.12 'None' is immortal, its refcount operations
are NO-OP and sys.getrefcount() will return a static value of UINT_MAX
on 64-bit and UINT_MAX >> 2 on 32-bit.
This basically transform 'test_try_again_many_times' in an almost
infinite loop and hangs the testsuite.
Detect this by checking if the refcount on 'None' is incremented after
assigning to a variable and skip the test if it's not the case.
See PEP-0683[1] for the gory details.
[1] https://peps.python.org/pep-0683/
Change-Id: Id07658245d524288ce7606cb0a011ad97068dad1
Signed-off-by: Michael Jeanson <mjeanson@debian.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10381
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
---
tests/bindings/python/bt2/test_message_iterator.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py
index 3cbe26f25..651a66b55 100644
--- a/tests/bindings/python/bt2/test_message_iterator.py
+++ b/tests/bindings/python/bt2/test_message_iterator.py
@@ -331,6 +331,14 @@ def __init__(self, config, params, obj):
# This verifies that we are not missing an incref of Py_None, making the
# refcount of Py_None reach 0.
def test_try_again_many_times(self):
+ # Starting with Python 3.12, `None` is immortal: its reference
+ # count operations are no-op. Skip this test in that case.
+ before = sys.getrefcount(None)
+ dummy = None # noqa: F841
+
+ if before == sys.getrefcount(None):
+ raise unittest.SkipTest("`None` is immortal")
+
class MyIter(bt2._UserMessageIterator):
def __next__(self):
raise bt2.TryAgain