chore(trading): static vega port trading e2e (#5520)
This commit is contained in:
parent
10add7c236
commit
145792f216
@ -1,2 +1,3 @@
|
|||||||
CONSOLE_IMAGE_NAME=vegaprotocol/trading:latest
|
CONSOLE_IMAGE_NAME=vegaprotocol/trading:latest
|
||||||
VEGA_VERSION=v0.73.9
|
VEGA_VERSION=v0.73.9
|
||||||
|
LOCAL_SERVER=false
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
CONSOLE_IMAGE_NAME=vegaprotocol/trading:main
|
CONSOLE_IMAGE_NAME=vegaprotocol/trading:main
|
||||||
VEGA_VERSION=v0.73.8
|
VEGA_VERSION=v0.73.8
|
||||||
|
LOCAL_SERVER=false
|
@ -127,11 +127,7 @@ yarn nx serve trading
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Once console is served you can use the flag --local-server
|
Once console is served you can update the .env file to have local_server to true.
|
||||||
|
|
||||||
```bash
|
|
||||||
poetry run pytest -k "test_name" -s --headed --local-server
|
|
||||||
```
|
|
||||||
|
|
||||||
## Running Tests in Parallel 🔢
|
## Running Tests in Parallel 🔢
|
||||||
|
|
||||||
|
@ -6,9 +6,10 @@ import requests
|
|||||||
import time
|
import time
|
||||||
import docker
|
import docker
|
||||||
import http.server
|
import http.server
|
||||||
|
import sys
|
||||||
|
from dotenv import load_dotenv
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from vega_sim.null_service import VegaServiceNull
|
from vega_sim.null_service import VegaServiceNull, Ports
|
||||||
from playwright.sync_api import Browser, Page
|
from playwright.sync_api import Browser, Page
|
||||||
from config import console_image_name, vega_version
|
from config import console_image_name, vega_version
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
@ -19,7 +20,6 @@ from fixtures.market import (
|
|||||||
setup_perps_market,
|
setup_perps_market,
|
||||||
)
|
)
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Workaround for current xdist issue with displaying live logs from multiple workers
|
# Workaround for current xdist issue with displaying live logs from multiple workers
|
||||||
# https://github.com/pytest-dev/pytest-xdist/issues/402
|
# https://github.com/pytest-dev/pytest-xdist/issues/402
|
||||||
@ -28,6 +28,8 @@ sys.stdout = sys.stderr
|
|||||||
docker_client = docker.from_env()
|
docker_client = docker.from_env()
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(tryfirst=True)
|
@pytest.hookimpl(tryfirst=True)
|
||||||
def pytest_runtest_makereport(item, call):
|
def pytest_runtest_makereport(item, call):
|
||||||
@ -49,16 +51,24 @@ def pytest_configure(config):
|
|||||||
level=config.getini("log_file_level"),
|
level=config.getini("log_file_level"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CustomHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
class CustomHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
# Set the path to your website's directory here
|
# Set the path to your website's directory here
|
||||||
if self.path == '/':
|
if self.path == "/":
|
||||||
self.path = 'dist/apps/trading/exported/index.html'
|
self.path = "dist/apps/trading/exported/index.html"
|
||||||
return http.server.SimpleHTTPRequestHandler.do_GET(self)
|
return http.server.SimpleHTTPRequestHandler.do_GET(self)
|
||||||
|
|
||||||
|
|
||||||
# Start VegaServiceNull
|
# Start VegaServiceNull
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def init_vega(request=None):
|
def init_vega(request=None):
|
||||||
|
local_server = os.getenv("LOCAL_SERVER", "false").lower() == "true"
|
||||||
|
port_config = None
|
||||||
|
if local_server:
|
||||||
|
port_config = {
|
||||||
|
Ports.DATA_NODE_REST: 8001,
|
||||||
|
}
|
||||||
default_seconds = 1
|
default_seconds = 1
|
||||||
seconds_per_block = default_seconds
|
seconds_per_block = default_seconds
|
||||||
if request and hasattr(request, "param"):
|
if request and hasattr(request, "param"):
|
||||||
@ -70,21 +80,26 @@ def init_vega(request=None):
|
|||||||
)
|
)
|
||||||
logger.info(f"Using console image: {console_image_name}")
|
logger.info(f"Using console image: {console_image_name}")
|
||||||
logger.info(f"Using vega version: {vega_version}")
|
logger.info(f"Using vega version: {vega_version}")
|
||||||
with VegaServiceNull(
|
|
||||||
run_with_console=False,
|
vega_service_args = {
|
||||||
launch_graphql=False,
|
"run_with_console": False,
|
||||||
retain_log_files=True,
|
"launch_graphql": False,
|
||||||
use_full_vega_wallet=True,
|
"retain_log_files": True,
|
||||||
store_transactions=True,
|
"use_full_vega_wallet": True,
|
||||||
transactions_per_block=1000,
|
"store_transactions": True,
|
||||||
seconds_per_block=seconds_per_block,
|
"transactions_per_block": 1000,
|
||||||
genesis_time= datetime.now() - timedelta(days=1),
|
"seconds_per_block": seconds_per_block,
|
||||||
) as vega:
|
"genesis_time": datetime.now() - timedelta(days=1),
|
||||||
|
}
|
||||||
|
|
||||||
|
if port_config is not None:
|
||||||
|
vega_service_args["port_config"] = port_config
|
||||||
|
|
||||||
|
with VegaServiceNull(**vega_service_args) as vega:
|
||||||
try:
|
try:
|
||||||
container = docker_client.containers.run(
|
container = docker_client.containers.run(
|
||||||
console_image_name, detach=True, ports={"80/tcp": vega.console_port}
|
console_image_name, detach=True, ports={"80/tcp": vega.console_port}
|
||||||
)
|
)
|
||||||
# docker setup
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Container {container.id} started",
|
f"Container {container.id} started",
|
||||||
extra={"worker_id": os.environ.get("PYTEST_XDIST_WORKER")},
|
extra={"worker_id": os.environ.get("PYTEST_XDIST_WORKER")},
|
||||||
@ -97,23 +112,13 @@ def init_vega(request=None):
|
|||||||
finally:
|
finally:
|
||||||
logger.info(f"Stopping container {container.id}")
|
logger.info(f"Stopping container {container.id}")
|
||||||
container.stop()
|
container.stop()
|
||||||
# Remove the container
|
|
||||||
logger.info(f"Removing container {container.id}")
|
logger.info(f"Removing container {container.id}")
|
||||||
container.remove()
|
container.remove()
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
|
||||||
parser.addoption(
|
|
||||||
"--local-server", action="store_true", default=False,
|
|
||||||
help="Build and serve locally instead of using a container"
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def local_server(pytestconfig):
|
|
||||||
return pytestconfig.getoption("--local-server")
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest, local_server: bool):
|
def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest):
|
||||||
|
local_server = os.getenv("LOCAL_SERVER", "false").lower() == "true"
|
||||||
server_port = "4200" if local_server else str(vega.console_port)
|
server_port = "4200" if local_server else str(vega.console_port)
|
||||||
with browser.new_context(
|
with browser.new_context(
|
||||||
viewport={"width": 1920, "height": 1080},
|
viewport={"width": 1920, "height": 1080},
|
||||||
@ -125,9 +130,7 @@ def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRe
|
|||||||
attempts = 0
|
attempts = 0
|
||||||
while attempts < 100:
|
while attempts < 100:
|
||||||
try:
|
try:
|
||||||
code = requests.get(
|
code = requests.get(f"http://localhost:{server_port}/").status_code
|
||||||
f"http://localhost:{server_port}/"
|
|
||||||
).status_code
|
|
||||||
if code == 200:
|
if code == 200:
|
||||||
break
|
break
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
@ -172,8 +175,8 @@ def vega(request):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def page(vega, browser, request, local_server):
|
def page(vega, browser, request):
|
||||||
with init_page(vega, browser, request, local_server) as page_instance:
|
with init_page(vega, browser, request) as page_instance:
|
||||||
yield page_instance
|
yield page_instance
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ def vega():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request, local_server):
|
def page(vega, browser, request):
|
||||||
with init_page(vega, browser, request, local_server) as page:
|
with init_page(vega, browser, request) as page:
|
||||||
setup_continuous_market(vega)
|
setup_continuous_market(vega)
|
||||||
risk_accepted_setup(page)
|
risk_accepted_setup(page)
|
||||||
page.goto("/")
|
page.goto("/")
|
||||||
|
@ -11,8 +11,8 @@ def vega(request):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request, local_server):
|
def page(vega, browser, request):
|
||||||
with init_page(vega, browser, request, local_server) as page:
|
with init_page(vega, browser, request) as page:
|
||||||
risk_accepted_setup(page)
|
risk_accepted_setup(page)
|
||||||
page.goto("/#/markets/all")
|
page.goto("/#/markets/all")
|
||||||
yield page
|
yield page
|
||||||
|
@ -12,8 +12,8 @@ def vega():
|
|||||||
|
|
||||||
# we can reuse single page instance in all tests
|
# we can reuse single page instance in all tests
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request, local_server):
|
def page(vega, browser, request):
|
||||||
with init_page(vega, browser, request, local_server) as page:
|
with init_page(vega, browser, request) as page:
|
||||||
yield page
|
yield page
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ def markets(vega: VegaService):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request, local_server):
|
def page(vega, browser, request):
|
||||||
with init_page(vega, browser, request, local_server) as page:
|
with init_page(vega, browser, request) as page:
|
||||||
risk_accepted_setup(page)
|
risk_accepted_setup(page)
|
||||||
auth_setup(vega, page)
|
auth_setup(vega, page)
|
||||||
page.goto("/")
|
page.goto("/")
|
||||||
|
Loading…
Reference in New Issue
Block a user