Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b11469a
GH-91048: Add utils for printing the call stack for asyncio tasks
pablogsal May 1, 2025
7f800e8
Maybe
pablogsal May 2, 2025
c5e4efe
Maybe
pablogsal May 2, 2025
1c982b1
Maybe
pablogsal May 2, 2025
2d94cde
fix configure
pablogsal May 2, 2025
0a9a496
fix configure
pablogsal May 2, 2025
db47ff3
fix configure
mgmacias95 May 2, 2025
6f8bd4c
some tests + fixes
mgmacias95 May 2, 2025
152b3d7
improve tests
mgmacias95 May 2, 2025
955ef27
dsf
pablogsal May 2, 2025
65aee3c
dsf
pablogsal May 2, 2025
51e689e
test fixes
pablogsal May 3, 2025
1d27348
test fixes
pablogsal May 3, 2025
1d1b0e9
test fixes
pablogsal May 3, 2025
edad4d1
test fixes
pablogsal May 3, 2025
199589c
Fix free threading offsets
pablogsal May 3, 2025
9e87032
Fix free threading offsets AGAIN
pablogsal May 3, 2025
69e9221
Debugging
pablogsal May 3, 2025
b6cb609
More tests
pablogsal May 3, 2025
2dd3452
Add news entry
pablogsal May 3, 2025
a84a171
Doc fixes
pablogsal May 3, 2025
0f75edc
Fix doc build
ambv May 3, 2025
c3a6bcb
Add Yury
ambv May 3, 2025
5e1cb87
fix: Show independent tasks in the table
mgmacias95 May 3, 2025
d92b520
Merge pull request #101 from mgmacias95/GH-91048-tasks
pablogsal May 3, 2025
af6a8bf
Temporarily skip test_async_global_awaited_by on free-threading
ambv May 3, 2025
8db5dbe
Drop the `tools`. It's cleaner.
ambv May 3, 2025
6f8aa6b
Satisfy the linting gods
ambv May 3, 2025
8d566c6
chore: Refactor
mgmacias95 May 4, 2025
977c15a
Merge pull request #103 from mgmacias95/GH-91048-tasks
pablogsal May 4, 2025
9dbe00d
Doc fixes
pablogsal May 4, 2025
c56782b
Type fixes
pablogsal May 4, 2025
293337f
Type fixes
pablogsal May 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test fixes
  • Loading branch information
pablogsal committed May 3, 2025
commit 51e689ed04fd38afb7e637ff88b564eaefd76732
227 changes: 195 additions & 32 deletions Lib/test/test_asyncio/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


# mock output of get_all_awaited_by function.
TEST_INPUTS = [
TEST_INPUTS_TREE = [
[
# test case containing a task called timer being awaited in two
# different subtasks part of a TaskGroup (root1 and root2) which call
Expand Down Expand Up @@ -80,7 +80,6 @@
),
(0, []),
),
([]),
(
[
[
Expand Down Expand Up @@ -121,6 +120,184 @@
]
]
),
],
[
# test case containing two roots
(
(
9,
[
(5, "Task-5", []),
(6, "Task-6", [[["main2"], 5]]),
(7, "Task-7", [[["main2"], 5]]),
(8, "Task-8", [[["main2"], 5]]),
],
),
(
10,
[
(1, "Task-1", []),
(2, "Task-2", [[["main"], 1]]),
(3, "Task-3", [[["main"], 1]]),
(4, "Task-4", [[["main"], 1]]),
],
),
(11, []),
(0, []),
),
(
[
[
"└── (T) Task-5",
" └── main2",
" ├── (T) Task-6",
" ├── (T) Task-7",
" └── (T) Task-8",
],
[
"└── (T) Task-1",
" └── main",
" ├── (T) Task-2",
" ├── (T) Task-3",
" └── (T) Task-4",
],
]
),
],
]

TEST_INPUTS_CYCLES_TREE = [
[
# this test case contains a cycle: two tasks awaiting each other.
(
[
(
1,
[
(2, "Task-1", []),
(
3,
"a",
[[["awaiter2"], 4], [["main"], 2]],
),
(4, "b", [[["awaiter"], 3]]),
],
),
(0, []),
]
),
([[4, 3, 4]]),
],
[
# this test case contains two cycles
(
[
(
1,
[
(2, "Task-1", []),
(
3,
"A",
[[["nested", "nested", "task_b"], 4]],
),
(
4,
"B",
[
[["nested", "nested", "task_c"], 5],
[["nested", "nested", "task_a"], 3],
],
),
(5, "C", [[["nested", "nested"], 6]]),
(
6,
"Task-2",
[[["nested", "nested", "task_b"], 4]],
),
],
),
(0, []),
]
),
([[4, 3, 4], [4, 6, 5, 4]]),
],
]

TEST_INPUTS_TABLE = [
[
# test case containing a task called timer being awaited in two
# different subtasks part of a TaskGroup (root1 and root2) which call
# awaiter functions.
(
(
1,
[
(2, "Task-1", []),
(
3,
"timer",
[
[["awaiter3", "awaiter2", "awaiter"], 4],
[["awaiter1_3", "awaiter1_2", "awaiter1"], 5],
[["awaiter1_3", "awaiter1_2", "awaiter1"], 6],
[["awaiter3", "awaiter2", "awaiter"], 7],
],
),
(
8,
"root1",
[[["_aexit", "__aexit__", "main"], 2]],
),
(
9,
"root2",
[[["_aexit", "__aexit__", "main"], 2]],
),
(
4,
"child1_1",
[
[
["_aexit", "__aexit__", "blocho_caller", "bloch"],
8,
]
],
),
(
6,
"child2_1",
[
[
["_aexit", "__aexit__", "blocho_caller", "bloch"],
8,
]
],
),
(
7,
"child1_2",
[
[
["_aexit", "__aexit__", "blocho_caller", "bloch"],
9,
]
],
),
(
5,
"child2_2",
[
[
["_aexit", "__aexit__", "blocho_caller", "bloch"],
9,
]
],
),
],
),
(0, []),
),
(
[
[
Expand Down Expand Up @@ -230,25 +407,6 @@
(11, []),
(0, []),
),
([]),
(
[
[
"└── (T) Task-5",
" └── main2",
" ├── (T) Task-6",
" ├── (T) Task-7",
" └── (T) Task-8",
],
[
"└── (T) Task-1",
" └── main",
" ├── (T) Task-2",
" ├── (T) Task-3",
" └── (T) Task-4",
],
]
),
(
[
[9, "0x6", "Task-6", "main2", "Task-5", "0x5"],
Expand All @@ -260,7 +418,7 @@
]
),
],
# Tests cycle detection.
# CASES WITH CYCLES
[
# this test case contains a cycle: two tasks awaiting each other.
(
Expand All @@ -280,8 +438,6 @@
(0, []),
]
),
([[4, 3, 4]]),
([]),
(
[
[1, "0x3", "a", "awaiter2", "b", "0x4"],
Expand Down Expand Up @@ -322,8 +478,6 @@
(0, []),
]
),
([[4, 3, 4], [4, 6, 5, 4]]),
([]),
(
[
[
Expand Down Expand Up @@ -372,15 +526,24 @@
]


class TestAsyncioTools(unittest.TestCase):
class TestAsyncioToolsTree(unittest.TestCase):

def test_asyncio_utils(self):
for input_, cycles, tree, table in TEST_INPUTS:
if cycles:
for input_, tree in TEST_INPUTS_TREE:
with self.subTest(input_):
self.assertEqual(tools.print_async_tree(input_), tree)

def test_asyncio_utils_cycles(self):
for input_, cycles in TEST_INPUTS_CYCLES_TREE:
with self.subTest(input_):
try:
tools.print_async_tree(input_)
except tools.CycleFoundException as e:
self.assertEqual(e.cycles, cycles)
else:
self.assertEqual(tools.print_async_tree(input_), tree)
self.assertEqual(tools.build_task_table(input_), table)


class TestAsyncioToolsTable(unittest.TestCase):
def test_asyncio_utils(self):
for input_, table in TEST_INPUTS_TABLE:
with self.subTest(input_):
self.assertEqual(tools.build_task_table(input_), table)
Loading