Skip to content

Commit a488ff4

Browse files
committed
test(tui): isolate concurrent JSON framing
1 parent 5a195a9 commit a488ff4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tests/test_tui_gateway_server.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,12 +871,19 @@ def flush(self) -> None:
871871
return None
872872

873873

874-
def test_write_json_serializes_concurrent_writes(monkeypatch):
874+
def test_write_json_serializes_concurrent_writes():
875875
out = _ChunkyStdout()
876-
monkeypatch.setattr(server, "_real_stdout", out)
876+
transport = server.StdioTransport(lambda: out, threading.Lock())
877+
878+
def _write(payload: dict) -> None:
879+
token = server.bind_transport(transport)
880+
try:
881+
assert server.write_json(payload) is True
882+
finally:
883+
server.reset_transport(token)
877884

878885
threads = [
879-
threading.Thread(target=server.write_json, args=({"seq": i, "text": "x" * 24},))
886+
threading.Thread(target=_write, args=({"seq": i, "text": "x" * 24},))
880887
for i in range(8)
881888
]
882889

@@ -887,7 +894,6 @@ def test_write_json_serializes_concurrent_writes(monkeypatch):
887894
t.join()
888895

889896
lines = "".join(out.parts).splitlines()
890-
891897
assert len(lines) == 8
892898
assert {json.loads(line)["seq"] for line in lines} == set(range(8))
893899

0 commit comments

Comments
 (0)