Skip to content

Commit

Permalink
MAINT print more details when test fails due to leaked proxy (pyodide…
Browse files Browse the repository at this point in the history
…#4545)

This should make debugging these failures way easier.

Example output:
```
leaked proxies:
tuple (1, 2) Traceback at creation:
    at trace_pyproxy_alloc (/home/rchatham/Documents/programming/pyodide/dist/pyodide.asm.js:3640:23)
    ...
```
  • Loading branch information
hoodmane authored Feb 23, 2024
1 parent 84977b8 commit 03496d8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ def pytest_runtest_call(item):
trace_hiwire_refs = (
trace_pyproxies and pytest.mark.skip_refcount_check.mark not in item.own_markers
)
yield from extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies)
yield from extra_checks_test_wrapper(
browser, trace_hiwire_refs, trace_pyproxies, item
)


def extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies):
def extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies, item):
"""Extra conditions for test to pass:
1. No explicit request for test to fail
2. No leaked JsRefs
Expand Down Expand Up @@ -250,6 +252,19 @@ def extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies):
if trace_pyproxies and trace_hiwire_refs:
delta_proxies = browser.get_num_proxies() - init_num_proxies
delta_keys = browser.get_num_hiwire_keys() - init_num_keys
if delta_proxies > 0:
pxs = browser.run_js(
"""
return Array.from(pyodide._module.pyproxy_alloc_map.entries(), ([x, s]) => [x.type, x.toString(), "Traceback at creation:" + s.replace("Error", "")])
"""
)
capman = item.config.pluginmanager.getplugin("capturemanager")
with capman.item_capture("call", item):
print("\n" + "!" * 40)
print("leaked proxies:")
for row in pxs:
print(*row)

assert (delta_proxies, delta_keys) == (0, 0) or delta_keys < 0
if trace_hiwire_refs:
delta_keys = browser.get_num_hiwire_keys() - init_num_keys
Expand Down

0 comments on commit 03496d8

Please sign in to comment.