A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Handle browser disconnects in the WebGL check server (#1142)
Aviel Cohen5efd1dd80495
diff --git a/tools/tests/test_web_check.py b/tools/tests/test_web_check.pyindex a552494f4..e29c139fe 100644--- a/tools/tests/test_web_check.py+++ b/tools/tests/test_web_check.py@@ -13,6 +13,34 @@ import pytestimport web_check as wc[email protected]("error", [BrokenPipeError, ConnectionResetError])+def test_server_client_disconnects_do_not_print_a_false_failure(error, capsys):+ server = wc.Server(("127.0.0.1", 0), wc.Handler)+ try:+ try:+ raise error("browser closed an outstanding response")+ except error:+ server.handle_error(None, server.server_address)+ finally:+ server.server_close()+ assert capsys.readouterr().err == ""++[email protected]("error", [ValueError, OSError])+def test_server_unexpected_request_errors_are_still_reported(error, capsys):+ server = wc.Server(("127.0.0.1", 0), wc.Handler)+ try:+ try:+ raise error("unexpected request failure")+ except error:+ server.handle_error(None, server.server_address)+ finally:+ server.server_close()+ report = capsys.readouterr().err+ assert "Traceback" in report+ assert f"{error.__name__}: unexpected request failure" in report++def test_console_lines_are_read_from_their_first_line():one = '[1010/025003.375619:INFO:CONSOLE:2] "GOLDEN OK 1950 abc", source: http://localhost:1/index.html (2)'assert wc.CONSOLE.search(one).group(1) == "GOLDEN OK 1950 abc"diff --git a/tools/web_check.py b/tools/web_check.pyindex 7124e3053..d20415204 100644--- a/tools/web_check.py+++ b/tools/web_check.py@@ -342,6 +342,12 @@ class Server(http.server.ThreadingHTTPServer):(BOOT FAIL <file>: Unknown Error). 128 is macOS's kern.ipc.somaxconn."""request_queue_size = 128+ def handle_error(self, request, client_address):+ # Closing the browser cancels outstanding responses. Keep other server failures visible.+ if isinstance(sys.exc_info()[1], (BrokenPipeError, ConnectionResetError)):+ return+ super().handle_error(request, client_address)+def serve(root: Path, port: int = 0) -> Server:server = Server(("127.0.0.1", port), functools.partial(Handler, directory=str(root)))