aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_disk_io_off_loop.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests/test_disk_io_off_loop.py')
-rw-r--r--packages/meshbay-node/tests/test_disk_io_off_loop.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/packages/meshbay-node/tests/test_disk_io_off_loop.py b/packages/meshbay-node/tests/test_disk_io_off_loop.py
index ceaf565..f98eceb 100644
--- a/packages/meshbay-node/tests/test_disk_io_off_loop.py
+++ b/packages/meshbay-node/tests/test_disk_io_off_loop.py
@@ -36,6 +36,7 @@ from meshbay_node.roots import Root, RootSet
from meshbay_node.transfers import LeaselessReads
from meshbay_node.transport import webrtc_server
from meshbay_node.transport.webrtc_server import WebRTCPeerSession
+from node_source import webrtc_files
from conftest import one_root, sealed_upload
@@ -238,9 +239,10 @@ def test_no_handler_touches_the_disk_on_the_loop():
The whole class, not the calls that were fixed.
Every measured test above exercises a handler that exists today; a new one
- that stats a root inline would pass all of them. So this walks the module's
- syntax tree instead and fails on any filesystem call outside the few
- functions written to be run through `off_disk`.
+ that stats a root inline would pass all of them. So this walks the syntax
+ tree of every module of the WebRTC transport instead and fails on any
+ filesystem call outside the few functions written to be run through
+ `off_disk`.
`entry_abs_path` and `safe_subdir` are in the list because both are
`Path.resolve()` underneath, and a resolve is syscalls whatever it is
@@ -274,14 +276,17 @@ def test_no_handler_touches_the_disk_on_the_loop():
found.append(f"{owner} calls {name}() at line {child.lineno}")
visit(child, owner)
- tree = ast.parse(Path(webrtc_server.__file__).read_text())
- for node in tree.body:
- if isinstance(node, ast.ClassDef):
- for member in node.body:
- if isinstance(member, (ast.FunctionDef, ast.AsyncFunctionDef)):
- visit(member, member.name)
- elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
- visit(node, node.name)
+ for path in webrtc_files():
+ tree = ast.parse(path.read_text(encoding="utf-8"))
+ before = len(found)
+ for node in tree.body:
+ if isinstance(node, ast.ClassDef):
+ for member in node.body:
+ if isinstance(member, (ast.FunctionDef, ast.AsyncFunctionDef)):
+ visit(member, member.name)
+ elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
+ visit(node, node.name)
+ found[before:] = [f"{path.name}: {f}" for f in found[before:]]
assert not found, (
"filesystem calls made from the event loop:\n "
@@ -362,8 +367,8 @@ def test_the_scratch_read_is_only_ever_reached_on_a_thread():
handler. Passed to `asyncio.to_thread` it appears in the syntax tree as a
name; called inline it appears as a call, which is what this refuses.
"""
- tree = ast.parse(Path(webrtc_server.__file__).read_text())
- direct = [n.lineno for n in ast.walk(tree)
+ direct = [f"{path.name}:{n.lineno}" for path in webrtc_files()
+ for n in ast.walk(ast.parse(path.read_text(encoding="utf-8")))
if isinstance(n, ast.Call)
and isinstance(n.func, ast.Name)
and n.func.id == "_read_scratch_capped"]