chore(trading): add console test

This commit is contained in:
bwallacee
2023-11-07 09:58:53 +00:00
parent 5d246a6c23
commit b59c9cf2ad
8 changed files with 49 additions and 32 deletions
+3 -3
View File
@@ -55,9 +55,9 @@ cypress.env.json
#console-test
apps/console-test/node_modules/
apps/console-test//test-results/
apps/console-test//playwright-report/
apps/console-test//playwright/.cache/
apps/console-test/test-results/
apps/console-test/playwright-report/
apps/console-test/playwright/.cache/
apps/console-test/*.pyc
apps/console-test/.pytest_cache
apps/console-test/traces/
+3 -3
View File
@@ -13,7 +13,7 @@
1. **Install Docker**: Follow the instructions on the [offical Docker website](https://docs.docker.com/desktop/).
1. **Install Dependencies**:
```bash
npm run install:console-test
npm run trading:test:install
```
If you want to run against specific vega binaries you can update the command in package.json
@@ -32,7 +32,7 @@ If you want to run against specific vega binaries you can update the command in
1. **Run the tests**: To run a specific test (or group of tests) using its name, use the following command:
```bash
npm run console-test -- "test_name" -s --headed
npm run trading:test -- "test_name" -s --headed
```
## Running Tests in Parallel
@@ -40,5 +40,5 @@ If you want to run against specific vega binaries you can update the command in
If you want to run tests in parallel, use the --numprocesses auto option. --dist loadfile makes sure that there are no multiple runners assigned to single test file:
```bash
npm run console-test:all
npm run trading:test:all
```
+33 -19
View File
@@ -6,6 +6,7 @@ import json
import requests
import time
import subprocess
import socket
from contextlib import contextmanager
from vega_sim.null_service import VegaServiceNull
@@ -47,11 +48,17 @@ def pytest_configure(config):
level=config.getini("log_file_level"),
)
@pytest.fixture(scope="session", autouse=True)
""" @pytest.fixture(scope="session", autouse=True)
def build_trading_platform():
# Build the trading platform before any tests run
print("Building the trading platform...")
subprocess.run(["yarn", "nx", "build", "trading"], check=True)
subprocess.run(["yarn", "nx", "build", "trading"], check=True) """
def find_free_port():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))
s.listen(1)
return s.getsockname()[1]
# Start VegaServiceNull and start up docker container for website
@contextmanager
@@ -76,17 +83,20 @@ def init_vega(request=None):
seconds_per_block=seconds_per_block,
) as vega:
try:
# Start the development server
port = find_free_port()
env = os.environ.copy()
env["PORT"] = str(vega.console_port)
logger.info(f"Starting the trading platform server on port {vega.console_port}...")
serve_command = ["yarn", "nx", "serve", "trading", "--port", str(vega.console_port)]
env["PORT"] = str(port)
logger.info(f"Starting the trading platform server on port {port}...")
serve_command = ["yarn", "nx", "serve", "trading", "--port", str(port)]
serve_process = subprocess.Popen(serve_command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
yield vega
except docker.errors.APIError as e:
logger.info(f"Container creation failed.")
logger.info(e)
raise e
#TODO add proper check for server
logger.info("Waiting for the server to start...")
time.sleep(10) # Adjust this time as necessary.
yield vega, port
finally:
# Shutdown actions below this line
logger.info("Shutting down the trading platform server...")
serve_process.terminate()
try:
@@ -97,10 +107,10 @@ def init_vega(request=None):
@contextmanager
def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest):
def init_page(vega: VegaServiceNull, port, browser: Browser, request: pytest.FixtureRequest):
with browser.new_context(
viewport={"width": 1920, "height": 1080},
base_url=f"http://localhost:{vega.console_port}",
base_url=f"http://localhost:{port}",
) as context, context.new_page() as page:
context.tracing.start(screenshots=True, snapshots=True, sources=True)
try:
@@ -109,7 +119,7 @@ def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRe
while attempts < 100:
try:
code = requests.get(
f"http://localhost:{vega.console_port}/"
f"http://localhost:{port}/"
).status_code
if code == 200:
break
@@ -144,19 +154,23 @@ def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRe
except Exception as e:
logger.error(f"Failed to save trace: {e}")
@pytest.fixture()
def vega_port(request):
with init_vega(request) as vega_instance:
_, port = vega_instance # Unpack only port here if you want to yield just the port.
yield port
# default vega & page fixtures with function scope (refreshed at each test) that can be used in tests
# separate fixtures may be defined in tests if we prefer different scope
@pytest.fixture
def vega(request):
with init_vega(request) as vega:
with init_vega(request) as vega_tuple:
vega, _ = vega_tuple
yield vega
@pytest.fixture
def page(vega, browser, request):
with init_page(vega, browser, request) as page:
yield page
def page(vega, vega_port, browser, request):
with init_page(vega, vega_port, browser, request) as page_instance:
yield page_instance
# Set auth token so eager connection for MarketSim wallet is successful
+1 -1
View File
@@ -1,5 +1,5 @@
from collections import namedtuple
from vega_sim.service import VegaService, PeggedOrder
from vega_sim.service import VegaService
from actions.vega import submit_multiple_orders, submit_order, submit_liquidity
@@ -17,7 +17,8 @@ expire = "expire"
@pytest.fixture(scope="module")
def vega(request):
with init_vega(request) as vega:
with init_vega(request) as vega_tuple:
vega, _ = vega_tuple
yield vega
@@ -5,7 +5,8 @@ from fixtures.market import setup_continuous_market
@pytest.fixture(scope="module")
def vega(request):
with init_vega(request) as vega:
with init_vega(request) as vega_tuple:
vega, _ = vega_tuple
yield vega
@pytest.fixture(scope="module")
@@ -15,7 +15,8 @@ deal_ticket_deposit_dialog_button = "deal-ticket-deposit-dialog-button"
@pytest.fixture(scope="module")
def vega(request):
with init_vega(request) as vega:
with init_vega(request) as vega_tuple:
vega, _ = vega_tuple
yield vega
+3 -3
View File
@@ -14,9 +14,9 @@
"e2e:all": "nx run-many --all --target=e2e",
"vegacapsule": "vegacapsule network bootstrap --config-path=../frontend-monorepo/vegacapsule/config.hcl",
"release": "git checkout develop ; git pull ; node scripts/make-release.js",
"install:console-test": "cd apps/console-test && poetry install && poetry run playwright install chromium && python -m vega_sim.tools.load_binaries --force --version v0.73.1",
"console-test": "cd apps/console-test && poetry run pytest -k",
"console-test:all": "cd apps/console-test && poetry run pytest -s --numprocesses 6 --dist loadfile"
"trading:test:install": "cd apps/console-test && poetry install && poetry shell && poetry run playwright install chromium && python -m vega_sim.tools.load_binaries --force --version v0.73.1",
"trading:test": "cd apps/console-test && poetry run pytest -k",
"trading:test:all": "cd apps/console-test && poetry run pytest -s --numprocesses 6 --dist loadfile"
},
"engines": {
"node": ">=16.15.1"