|
1 | | -import choreographer as choreo |
| 1 | +import asyncio |
| 2 | + |
2 | 3 | import logistro |
3 | 4 | import pytest |
| 5 | + |
| 6 | +import choreographer as choreo |
4 | 7 | from choreographer import errors |
5 | 8 | from choreographer.protocol import devtools_async |
6 | 9 |
|
@@ -115,6 +118,39 @@ async def test_browser_send_command(browser): |
115 | 118 | await browser.send_command(command=12345) |
116 | 119 |
|
117 | 120 |
|
| 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 | + |
118 | 154 | @pytest.mark.asyncio |
119 | 155 | async def test_populate_targets(browser): |
120 | 156 | _logger.info("testing...") |
|
0 commit comments