From 478ef923472b47cd064c9e0356a2451cf3829df5 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 21:53:11 +0900 Subject: [PATCH 1/9] Add test standalone --- e2e_tests/test_server.py | 26 ++++++++++++++++++++ e2e_tests/test_standalone/__init__.py | 0 e2e_tests/test_standalone/test_study_list.py | 22 +++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 e2e_tests/test_standalone/__init__.py create mode 100644 e2e_tests/test_standalone/test_study_list.py diff --git a/e2e_tests/test_server.py b/e2e_tests/test_server.py index b6d147343..cc41d73a5 100644 --- a/e2e_tests/test_server.py +++ b/e2e_tests/test_server.py @@ -1,5 +1,7 @@ import socket import threading +import http.server +import socketserver from wsgiref.simple_server import make_server import optuna @@ -33,3 +35,27 @@ def stop_server() -> None: request.addfinalizer(stop_server) return f"http://{addr}:{port}/dashboard" + + +def make_standalone_server(request: pytest.FixtureRequest) -> str: + addr = "127.0.0.1" + port = get_free_port() + directory = "/Users/k-umezawa/dev/optuna-dashboard/standalone_app/" + + Handler = http.server.SimpleHTTPRequestHandler + httpd = socketserver.TCPServer(("", port), lambda *args, **kwargs: Handler(*args, directory=directory, **kwargs)) + + def serve_httpd(): + httpd.serve_forever() + + thread = threading.Thread(target=serve_httpd) + thread.start() + + def stop_server() -> None: + httpd.shutdown() + httpd.server_close() + thread.join() + + request.addfinalizer(stop_server) + + return f"http://{addr}:{port}" diff --git a/e2e_tests/test_standalone/__init__.py b/e2e_tests/test_standalone/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/e2e_tests/test_standalone/test_study_list.py b/e2e_tests/test_standalone/test_study_list.py new file mode 100644 index 000000000..c2cbcb75a --- /dev/null +++ b/e2e_tests/test_standalone/test_study_list.py @@ -0,0 +1,22 @@ +from playwright.sync_api import Page +import pytest + +from ..test_server import make_standalone_server + + +@pytest.fixture +def server_url(request: pytest.FixtureRequest) -> str: + return make_standalone_server(request) + + +def test_home( + page: Page, + server_url: str, +) -> None: + url = f"{server_url}" + page.goto(url) + element = page.get_by_role("heading") + assert element is not None + title = element.text_content() + assert title is not None + assert title == "Optuna Dashboard (Wasm ver.)" \ No newline at end of file From 102dec04a34cdaceabda64ffa36f7ea4034eb323 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 22:02:22 +0900 Subject: [PATCH 2/9] Add github actions --- ...{e2e-tests.yml => e2e-dashboard-tests.yml} | 4 +- .github/workflows/e2e-standalone-tests.yml | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) rename .github/workflows/{e2e-tests.yml => e2e-dashboard-tests.yml} (94%) create mode 100644 .github/workflows/e2e-standalone-tests.yml diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-dashboard-tests.yml similarity index 94% rename from .github/workflows/e2e-tests.yml rename to .github/workflows/e2e-dashboard-tests.yml index 4665f676f..cb2ed8cf5 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-dashboard-tests.yml @@ -1,10 +1,10 @@ -name: e2e-tests +name: e2e-dashboard-tests on: pull_request: branches: - main paths: - - '.github/workflows/e2e-tests.yml' + - '.github/workflows/e2e-dashboard-tests.yml' - '**.py' - '**.ts' - '**.tsx' diff --git a/.github/workflows/e2e-standalone-tests.yml b/.github/workflows/e2e-standalone-tests.yml new file mode 100644 index 000000000..7dceb0597 --- /dev/null +++ b/.github/workflows/e2e-standalone-tests.yml @@ -0,0 +1,43 @@ +name: e2e-standalone-tests +on: + pull_request: + branches: + - main + paths: + - '.github/workflows/e2e-standalone-tests.yml' + - '**.py' + - '**.ts' + - '**.tsx' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' +jobs: + test: + runs-on: ubuntu-20.04 + strategy: + matrix: + optuna-version: ['optuna==2.10.0', 'git+https://github.com/optuna/optuna.git'] + steps: + - uses: actions/checkout@v3 + + - name: Install Rust toolchains + uses: dtolnay/rust-toolchain@stable + + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Build standalone_app + env: + PUBLIC_PATH: /optuna-dashboard/public/ + run: make MODE="prd" standalone_app/public/bundle.js + + - name: Install the required browsers + run: playwright install + + - name: Run e2e tests + run: pytest e2e_tests/test_standalone From aabfaefdec2bd7508e63d8143fd2901cc3727cb7 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 22:04:38 +0900 Subject: [PATCH 3/9] Move dashboard e2e test files --- e2e_tests/{ => test_dashboard}/test_usecases/__init__.py | 0 .../{ => test_dashboard}/test_usecases/test_study_history.py | 0 e2e_tests/{ => test_dashboard}/visual_regression_test.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename e2e_tests/{ => test_dashboard}/test_usecases/__init__.py (100%) rename e2e_tests/{ => test_dashboard}/test_usecases/test_study_history.py (100%) rename e2e_tests/{ => test_dashboard}/visual_regression_test.py (100%) diff --git a/e2e_tests/test_usecases/__init__.py b/e2e_tests/test_dashboard/test_usecases/__init__.py similarity index 100% rename from e2e_tests/test_usecases/__init__.py rename to e2e_tests/test_dashboard/test_usecases/__init__.py diff --git a/e2e_tests/test_usecases/test_study_history.py b/e2e_tests/test_dashboard/test_usecases/test_study_history.py similarity index 100% rename from e2e_tests/test_usecases/test_study_history.py rename to e2e_tests/test_dashboard/test_usecases/test_study_history.py diff --git a/e2e_tests/visual_regression_test.py b/e2e_tests/test_dashboard/visual_regression_test.py similarity index 100% rename from e2e_tests/visual_regression_test.py rename to e2e_tests/test_dashboard/visual_regression_test.py From 2a94f59451486a8fd1b4abfc7e88ef8231fe4caa Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 22:09:49 +0900 Subject: [PATCH 4/9] Fix path --- .github/workflows/e2e-dashboard-tests.yml | 2 +- e2e_tests/test_dashboard/test_usecases/test_study_history.py | 2 +- e2e_tests/test_dashboard/visual_regression_test.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-dashboard-tests.yml b/.github/workflows/e2e-dashboard-tests.yml index cb2ed8cf5..c8912b9ac 100644 --- a/.github/workflows/e2e-dashboard-tests.yml +++ b/.github/workflows/e2e-dashboard-tests.yml @@ -47,4 +47,4 @@ jobs: run: playwright install - name: Run e2e tests - run: pytest e2e_tests + run: pytest e2e_tests/test_dashboard diff --git a/e2e_tests/test_dashboard/test_usecases/test_study_history.py b/e2e_tests/test_dashboard/test_usecases/test_study_history.py index e37b8f5a6..6c22b16b3 100644 --- a/e2e_tests/test_dashboard/test_usecases/test_study_history.py +++ b/e2e_tests/test_dashboard/test_usecases/test_study_history.py @@ -2,7 +2,7 @@ from playwright.sync_api import Page import pytest -from ..test_server import make_test_server +from ...test_server import make_test_server def make_test_storage() -> optuna.storages.InMemoryStorage: diff --git a/e2e_tests/test_dashboard/visual_regression_test.py b/e2e_tests/test_dashboard/visual_regression_test.py index d83fbb5f3..ea6ff9305 100644 --- a/e2e_tests/test_dashboard/visual_regression_test.py +++ b/e2e_tests/test_dashboard/visual_regression_test.py @@ -4,7 +4,7 @@ from playwright.sync_api import Page import pytest -from .test_server import make_test_server +from ..test_server import make_test_server @pytest.fixture From 3e6a2bfa4453f7e7231d626e8dd277ac5b2c4a4b Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 22:33:24 +0900 Subject: [PATCH 5/9] Fix some errors --- .github/workflows/e2e-standalone-tests.yml | 10 ++++++++++ e2e_tests/test_dashboard/__init__.py | 0 2 files changed, 10 insertions(+) create mode 100644 e2e_tests/test_dashboard/__init__.py diff --git a/.github/workflows/e2e-standalone-tests.yml b/.github/workflows/e2e-standalone-tests.yml index 7dceb0597..2187982b5 100644 --- a/.github/workflows/e2e-standalone-tests.yml +++ b/.github/workflows/e2e-standalone-tests.yml @@ -31,6 +31,16 @@ jobs: with: node-version: '18' + - name: Setup Optuna ${{ matrix.optuna-version }} + run: | + python -m pip install --progress-bar off --upgrade pip setuptools + python -m pip install --progress-bar off --upgrade ${{ matrix.optuna-version }} + + - name: Install dependencies + run: | + python -m pip install --progress-bar off . + python -m pip install --progress-bar off pytest-playwright + - name: Build standalone_app env: PUBLIC_PATH: /optuna-dashboard/public/ diff --git a/e2e_tests/test_dashboard/__init__.py b/e2e_tests/test_dashboard/__init__.py new file mode 100644 index 000000000..e69de29bb From 3ab4be4ce318f31a8b998a89054b35393f6e7f3d Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 22:34:24 +0900 Subject: [PATCH 6/9] Fix lint --- e2e_tests/test_server.py | 8 +++++--- e2e_tests/test_standalone/test_study_list.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/e2e_tests/test_server.py b/e2e_tests/test_server.py index cc41d73a5..898861810 100644 --- a/e2e_tests/test_server.py +++ b/e2e_tests/test_server.py @@ -1,7 +1,7 @@ -import socket -import threading import http.server +import socket import socketserver +import threading from wsgiref.simple_server import make_server import optuna @@ -43,7 +43,9 @@ def make_standalone_server(request: pytest.FixtureRequest) -> str: directory = "/Users/k-umezawa/dev/optuna-dashboard/standalone_app/" Handler = http.server.SimpleHTTPRequestHandler - httpd = socketserver.TCPServer(("", port), lambda *args, **kwargs: Handler(*args, directory=directory, **kwargs)) + httpd = socketserver.TCPServer( + ("", port), lambda *args, **kwargs: Handler(*args, directory=directory, **kwargs) + ) def serve_httpd(): httpd.serve_forever() diff --git a/e2e_tests/test_standalone/test_study_list.py b/e2e_tests/test_standalone/test_study_list.py index c2cbcb75a..b0d4735e4 100644 --- a/e2e_tests/test_standalone/test_study_list.py +++ b/e2e_tests/test_standalone/test_study_list.py @@ -19,4 +19,4 @@ def test_home( assert element is not None title = element.text_content() assert title is not None - assert title == "Optuna Dashboard (Wasm ver.)" \ No newline at end of file + assert title == "Optuna Dashboard (Wasm ver.)" From 6f4724f73346a63decee69b4bdd549c6dbef6f6a Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Tue, 10 Oct 2023 23:00:03 +0900 Subject: [PATCH 7/9] Fix public path --- .github/workflows/e2e-standalone-tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/e2e-standalone-tests.yml b/.github/workflows/e2e-standalone-tests.yml index 2187982b5..2de6d6107 100644 --- a/.github/workflows/e2e-standalone-tests.yml +++ b/.github/workflows/e2e-standalone-tests.yml @@ -42,8 +42,6 @@ jobs: python -m pip install --progress-bar off pytest-playwright - name: Build standalone_app - env: - PUBLIC_PATH: /optuna-dashboard/public/ run: make MODE="prd" standalone_app/public/bundle.js - name: Install the required browsers From b71a86225bad395f803e905b4f8649776e285395 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sun, 15 Oct 2023 16:51:17 +0900 Subject: [PATCH 8/9] Enable ssh --- .github/workflows/e2e-standalone-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/e2e-standalone-tests.yml b/.github/workflows/e2e-standalone-tests.yml index 2de6d6107..b27246be8 100644 --- a/.github/workflows/e2e-standalone-tests.yml +++ b/.github/workflows/e2e-standalone-tests.yml @@ -44,6 +44,9 @@ jobs: - name: Build standalone_app run: make MODE="prd" standalone_app/public/bundle.js + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Install the required browsers run: playwright install From 844ac81cb2dabcf70b16de3fe094c59cc7332d98 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sun, 15 Oct 2023 17:08:47 +0900 Subject: [PATCH 9/9] Fix directory path --- .github/workflows/e2e-standalone-tests.yml | 3 --- e2e_tests/test_server.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/e2e-standalone-tests.yml b/.github/workflows/e2e-standalone-tests.yml index b27246be8..2de6d6107 100644 --- a/.github/workflows/e2e-standalone-tests.yml +++ b/.github/workflows/e2e-standalone-tests.yml @@ -44,9 +44,6 @@ jobs: - name: Build standalone_app run: make MODE="prd" standalone_app/public/bundle.js - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - - name: Install the required browsers run: playwright install diff --git a/e2e_tests/test_server.py b/e2e_tests/test_server.py index 898861810..a15acc683 100644 --- a/e2e_tests/test_server.py +++ b/e2e_tests/test_server.py @@ -40,7 +40,7 @@ def stop_server() -> None: def make_standalone_server(request: pytest.FixtureRequest) -> str: addr = "127.0.0.1" port = get_free_port() - directory = "/Users/k-umezawa/dev/optuna-dashboard/standalone_app/" + directory = "./standalone_app/" Handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(