Skip to content

Commit

Permalink
e2e test を追加
Browse files Browse the repository at this point in the history
ただし、カメラデバイスが掴めずエラーになる可能性あり。
  • Loading branch information
voluntas committed Sep 3, 2024
1 parent f137554 commit 6feafbc
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 10 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: e2e-test

on:
push:
paths-ignore:
- "doc/**"
- "html/**"
- "**.md"
- "THANKS"
- "LICENSE"
- "NOTICE"

jobs:
e2e-test-macos:
strategy:
fail-fast: false
matrix:
name:
- macos_arm64
name: Build momo for ${{ matrix.name }}
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- run: python3 run.py ${{ matrix.name }}
- uses: eifinger/setup-rye@v3
with:
version: 'latest'
- run: rye sync
working-directory: ./test
- run: rye run pytest test/test_momo.py
working-directory: ./test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ webrtc_logs_0

# python
.venv
.pytest_cache
__pycache__

# vscode
build
66 changes: 57 additions & 9 deletions test/momo.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,79 @@
import platform
import signal
import subprocess
import sys
import threading
import time
from pathlib import Path

# プラットフォームに応じたリリースディレクトリの設定
RELEASE_DIR = Path(__file__).resolve().parent.parent / Path("_build/")
if platform.system() == "Darwin":
if platform.machine() == "arm64":
RELEASE_DIR = RELEASE_DIR / "macos_arm64/release/momo"
elif platform.system() == "Linux":
# ubuntu 24.04 かどうかの確認が必要
# ubuntu 22.04 と 24.04 がある
RELEASE_DIR = RELEASE_DIR / "ubuntu-24.04_x86_64/release/momo"
else:
raise OSError(f"Unsupported platform: {platform.system()}")


class Momo:
def __init__(self):
pass
def __init__(self, port=5000):
self.executable = RELEASE_DIR / "momo"
self.port = port
self.process = None
self.thread = None
self.is_running = False

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()

def run_app(self, args):
self.process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.process.wait()
self.is_running = False
def run_app(self):
# test モードでポートだけ指定してあげる
args = [str(self.executable), "test", "--port", str(self.port)]
try:
self.process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.process.wait()
except Exception as e:
print(f"Error running momo: {e}", file=sys.stderr)
finally:
self.is_running = False

def start(self):
self.thread = threading.Thread(target=self.run_app, args=())
if not self.executable.exists():
raise FileNotFoundError(f"Momo executable not found: {self.executable}")

self.thread = threading.Thread(target=self.run_app)
self.thread.start()
self.is_running = True
time.sleep(1) # アプリケーションの起動を待つ

# momoの起動を確認
start_time = time.time()
while time.time() - start_time < 10: # 10秒のタイムアウト
if self.process and self.process.poll() is None:
print(f"Momo started on port {self.port}")
return
time.sleep(0.1)

raise TimeoutError("Momo failed to start within the timeout period")

def stop(self):
pass
if self.is_running and self.process:
# SIGINT を送信 (Ctrl+C と同等)
self.process.send_signal(signal.SIGINT)
try:
# プロセスが終了するのを最大5秒間待つ
self.process.wait(timeout=5)
except subprocess.TimeoutExpired:
# タイムアウトした場合、強制終了
print("Momo did not terminate gracefully. Forcing termination.", file=sys.stderr)
self.process.kill()

self.thread.join()
self.is_running = False
print("Momo stopped")
5 changes: 4 additions & 1 deletion test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name = "momo-e2e-test"
version = "2013.3.8"
requires-python = ">= 3.12"
dependencies = ["pytest>=8.3.2"]
dependencies = [
"pytest>=8.3.2",
"pytest-timeout>=2.3.1",
]

[tool.rye]
virtual = true
Expand Down
2 changes: 2 additions & 0 deletions test/requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ packaging==24.1
pluggy==1.5.0
# via pytest
pytest==8.3.2
# via pytest-timeout
pytest-timeout==2.3.1
ruff==0.6.3
2 changes: 2 additions & 0 deletions test/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ packaging==24.1
pluggy==1.5.0
# via pytest
pytest==8.3.2
# via pytest-timeout
pytest-timeout==2.3.1
12 changes: 12 additions & 0 deletions test/test_momo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import time

from momo import Momo


def test_start_and_stop():
with Momo() as momo:
momo.start()

time.sleep(3)

momo.stop()

0 comments on commit 6feafbc

Please sign in to comment.