Skip to content

Commit d07acb9

Browse files
committed
Add perf recording tests
1 parent 71894a2 commit d07acb9

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

tests/test_browser.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import choreographer as choreo
1+
import asyncio
2+
23
import logistro
34
import pytest
5+
6+
import choreographer as choreo
47
from choreographer import errors
58
from choreographer.protocol import devtools_async
69

@@ -115,6 +118,39 @@ async def test_browser_send_command(browser):
115118
await browser.send_command(command=12345)
116119

117120

121+
@pytest.mark.asyncio
122+
async def test_browser_send_command_with_perf(browser):
123+
_logger.info("testing...")
124+
perfs = []
125+
126+
# Run multiple commands and collect perf data
127+
for _ in range(3):
128+
response, perf = await browser.send_command(
129+
command="Target.getTargets",
130+
with_perf=True,
131+
)
132+
assert "result" in response and "targetInfos" in response["result"] # noqa: PT018 I like this assertion
133+
134+
# Validate perf is a tuple of 3 floats
135+
assert isinstance(perf, tuple)
136+
assert all(isinstance(t, float) for t in perf)
137+
138+
# Validate timing makes sense (write_start <= write_end <= read_end)
139+
write_start, write_end, read_end = perf
140+
assert write_start <= write_end <= read_end
141+
142+
perfs.append(perf)
143+
await asyncio.sleep(0.1)
144+
145+
# Verify each perf tuple is distinct and sequential
146+
for i in range(len(perfs) - 1):
147+
_, _, prev_read_end = perfs[i]
148+
next_write_start, _, _ = perfs[i + 1]
149+
150+
# Next command should start after previous command ended
151+
assert prev_read_end <= next_write_start, "Commands should be sequential"
152+
153+
118154
@pytest.mark.asyncio
119155
async def test_populate_targets(browser):
120156
_logger.info("testing...")

tests/test_tab.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logistro
44
import pytest
5+
56
from choreographer import errors
67
from choreographer.protocol import devtools_async
78

@@ -80,7 +81,7 @@ async def count_event(_r):
8081
assert "Page.*" in next(iter(tab.sessions.values())).subscriptions
8182
await tab.send_command("Page.enable")
8283
await tab.send_command("Page.reload")
83-
await asyncio.sleep(0.5)
84+
await asyncio.sleep(0.15)
8485
assert counter > old_counter
8586

8687
tab.unsubscribe("Page.*")

0 commit comments

Comments
 (0)