graphql-engine/server/tests-py/remote_server.py
Samir Talwar 710a33bf45 CI: Run the Python tests in the "new" mode, one HGE per test class.
Part of [NDAT-257](https://hasurahq.atlassian.net/browse/NDAT-257).

This runs the Python tests in parallel, all at once, with each test class spinning up HGE and configuring it appropriately. Once we are confident this works, we can remove most of the old jobs, drastically reducing the number of machines we need to run the Python tests.

For now we are only running on PostgreSQL 15. Once this is merged, we can expand to all supported PostgreSQL versions, and then Citus, MS SQL Server, and BigQuery.

[NDAT-257]: https://hasurahq.atlassian.net/browse/NDAT-257?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7780
GitOrigin-RevId: 174511fc3e3bcd4ea968e3ade6c867c3aa84096a
2023-02-03 14:09:29 +00:00

31 lines
825 B
Python

import os
import subprocess
from typing import Optional
import ports
class NodeGraphQL:
def __init__(self, cmd: list[str], env: dict[str, str] = {}, port: Optional[int] = None):
self.cmd = cmd
self.env = env
self.port = port if port else ports.find_free_port()
self.proc: Optional[subprocess.Popen[bytes]] = None
def start(self):
self.proc = subprocess.Popen(self.cmd, env={**os.environ, **self.env, 'PORT': str(self.port)})
try:
ports.wait_for_port(self.port, timeout = 30)
except:
self.proc.kill()
self.proc = None
raise
def stop(self):
if self.proc:
self.proc.terminate()
self.proc = None
@property
def url(self):
return f'http://localhost:{self.port}'