| 103 | |
| 104 | @contextlib.contextmanager |
| 105 | def flight_server(self, scenario_name=None): |
| 106 | cmd = _FLIGHT_SERVER_CMD + ['-port=0'] |
| 107 | if scenario_name: |
| 108 | cmd = cmd + ["-scenario", scenario_name] |
| 109 | if self.debug: |
| 110 | log(" ".join(cmd)) |
| 111 | server = subprocess.Popen( |
| 112 | cmd, |
| 113 | stdout=subprocess.PIPE, |
| 114 | stderr=subprocess.PIPE, |
| 115 | ) |
| 116 | try: |
| 117 | output = server.stdout.readline().decode() |
| 118 | if not output.startswith("Server listening on localhost:"): |
| 119 | server.kill() |
| 120 | out, err = server.communicate() |
| 121 | raise RuntimeError( |
| 122 | "Flight-C++ server did not start properly, " |
| 123 | f"stdout:\n{output + out.decode()}\n\nstderr:\n{err.decode()}\n" |
| 124 | ) |
| 125 | port = int(output.split(":")[1]) |
| 126 | yield port |
| 127 | finally: |
| 128 | server.kill() |
| 129 | server.wait(5) |
| 130 | |
| 131 | def flight_request(self, port, json_path=None, scenario_name=None): |
| 132 | cmd = _FLIGHT_CLIENT_CMD + [f'-port={port}'] |