diff options
Diffstat (limited to 'graph/test_transport.py')
| -rw-r--r-- | graph/test_transport.py | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/graph/test_transport.py b/graph/test_transport.py index d0026b97..f1834403 100644 --- a/graph/test_transport.py +++ b/graph/test_transport.py @@ -46,15 +46,15 @@ def compile_frames(stream): def check(chapter): root = Path(__file__).resolve().parent.parent number = int(chapter.removeprefix("chapter")) - assert number == 4 or 18 <= number <= 25 + assert 1 <= number <= 25 chapter_dir = root / chapter - package = "com.seaofnodes.simple." + ("print." if number == 4 or number >= 20 else "") + package = "com.seaofnodes.simple.print." log = root / "build" / "graph-transport" / (chapter + ".log") log.parent.mkdir(parents=True, exist_ok=True) with log.open("w") as output: process = subprocess.Popen( ["java", "-ea", "-Dsimple.graph.open=false", "-cp", - "build/classes/main", package + "JSViewer"], + "build/classes/main", package + "SimpleGraphObserver"], cwd=chapter_dir, stdout=output, stderr=subprocess.STDOUT) try: deadline = time.monotonic() + 10 @@ -69,9 +69,8 @@ def check(chapter): time.sleep(.05) assert url and url.startswith("http://127.0.0.1:"), log.read_text() # The browser must be able to load all assets before connecting. - for asset in ("index.html", "viewer.js", "layout.js", "render.js", "legacy.js", - "vendor/elk-api.js", "vendor/elk-worker.min.js", "vendor/d3.v7.min.js", - "vendor/d3-graphviz.js", "vendor/graphviz.umd.js"): + for asset in ("index.html", "viewer.js", "layout.js", "render.js", + "vendor/elk-api.js", "vendor/elk-worker.min.js", "vendor/d3.v7.min.js"): with urllib.request.urlopen(url.rsplit("/", 1)[0] + "/" + asset, timeout=3) as response: assert response.status == 200 @@ -93,9 +92,8 @@ def check(chapter): else: raise AssertionError("Responded before headers ended: " + repr(early)) client.settimeout(3) - shared = number in (4, 25) # A frame in the same write as the upgrade must not get lost in a reader buffer. - client.sendall(b"\r\n" + (packet(b'hello', op=9) if shared else b'')) + client.sendall(b"\r\n" + packet(b'hello', op=9)) with client.makefile("rb") as stream: assert stream.readline() == b"HTTP/1.1 101 Switching Protocols\r\n" headers = [] @@ -107,25 +105,24 @@ def check(chapter): headers.append(line) assert b"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" in headers assert stream.read(3) == b"\x81\x01!", "Missing source request" - if shared: - assert frame(stream) == (10, b'hello') - # Larger than both the old 1 KB buffer and the 16-bit length field. - data = packet(b' ' * 70000 + b'return 3;') - client.sendall(data[:3]) - time.sleep(.05) - for start in range(3, len(data), 509): - client.sendall(data[start:start + 509]) - frames = compile_frames(stream) - assert frames and all('snap' in f for f in frames) - # Split a UTF-8 code point across fragments, with an interleaved PING. - client.sendall(packet(b'\xc3', fin=False) + packet(b'ping', op=9) + packet(b'\xa9', op=0)) - assert frame(stream) == (10, b'ping') - errors = compile_frames(stream) - assert any('error' in f for f in errors) - assert '\u00e9' in log.read_text() - client.sendall(packet(b'return 4;')) - frames = compile_frames(stream) - assert frames and all('snap' in f for f in frames) + assert frame(stream) == (10, b'hello') + # Larger than both the old 1 KB buffer and the 16-bit length field. + data = packet(b' ' * 70000 + b'return 3;') + client.sendall(data[:3]) + time.sleep(.05) + for start in range(3, len(data), 509): + client.sendall(data[start:start + 509]) + frames = compile_frames(stream) + assert frames and all('snap' in f for f in frames) + # Split a UTF-8 code point across fragments, with an interleaved PING. + client.sendall(packet(b'return 3; \xc3', fin=False) + packet(b'ping', op=9) + packet(b'\xa9', op=0)) + assert frame(stream) == (10, b'ping') + errors = compile_frames(stream) + assert any('error' in f for f in errors) + assert '\u00e9' in log.read_text() + client.sendall(packet(b'return 4;')) + frames = compile_frames(stream) + assert frames and all('snap' in f for f in frames) # Masked 'null' asks the compiler to exit normally. mask = b"abcd" payload = bytes(byte ^ mask[i % 4] for i, byte in enumerate(b"null")) @@ -144,7 +141,7 @@ def check(chapter): process.terminate() process.wait(timeout=5) print(chapter + ": HTTP assets, fragmented upgrade, greeting, and shutdown passed" + - ("; large frames, UTF-8 fragments, ping, and compile-error recovery passed" if number in (4, 25) else "")) + "; large frames, UTF-8 fragments, ping, and compile-error recovery passed") if __name__ == "__main__": |
