From: Pablo Galindo Salgado Date: Sun, 14 Dec 2025 03:31:42 +0000 (+0000) Subject: gh-142368: Fix race comparing locations in test_external_inspection (#142691) X-Git-Tag: v3.15.0a3~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2eb95375092149634bdc34978c4030a0e0b4b033;p=thirdparty%2FPython%2Fcpython.git gh-142368: Fix race comparing locations in test_external_inspection (#142691) --- diff --git a/Lib/test/test_external_inspection.py b/Lib/test/test_external_inspection.py index 4f3beb15f53b..4ebd8aeeb89e 100644 --- a/Lib/test/test_external_inspection.py +++ b/Lib/test/test_external_inspection.py @@ -3183,10 +3183,31 @@ sock.connect(('localhost', {port})) funcs_no_cache = [f.funcname for f in frames_no_cache] self.assertEqual(funcs_cached, funcs_no_cache) - # Same locations - locations_cached = [f.location for f in frames_cached] - locations_no_cache = [f.location for f in frames_no_cache] - self.assertEqual(locations_cached, locations_no_cache) + # For level3 (leaf frame), due to timing races we can be at either + # sock.sendall() or sock.recv() - both are valid. For parent frames, + # the locations should match exactly. + # Valid locations for level3: line 3 has two statements + # sock.sendall(b"ready") -> col 4-26 + # sock.recv(16) -> col 28-41 + level3_valid_cols = {(4, 26), (28, 41)} + + for i in range(len(frames_cached)): + loc_cached = frames_cached[i].location + loc_no_cache = frames_no_cache[i].location + + if frames_cached[i].funcname == "level3": + # Leaf frame: can be at either statement + self.assertIn( + (loc_cached.col_offset, loc_cached.end_col_offset), + level3_valid_cols, + ) + self.assertIn( + (loc_no_cache.col_offset, loc_no_cache.end_col_offset), + level3_valid_cols, + ) + else: + # Parent frames: must match exactly + self.assertEqual(loc_cached, loc_no_cache) @skip_if_not_supported @unittest.skipIf(