Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] pytest を利用した Momo の E2E テストを追加する #352

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
386872a
pytest の準備
voluntas Sep 3, 2024
f137554
一旦雑に追加
voluntas Sep 3, 2024
6feafbc
e2e test を追加
voluntas Sep 3, 2024
b703b77
build-workflow を一時的に無効にする
voluntas Sep 3, 2024
fc0afbe
test_momo.py のパスを修正
voluntas Sep 3, 2024
76a16d7
おためし v4l2loopback-dkms
voluntas Sep 3, 2024
0f50d72
apt
voluntas Sep 3, 2024
19441f6
ubuntu でのお試し
voluntas Sep 3, 2024
f96e684
お試し
voluntas Sep 3, 2024
752256c
一旦不要なコード削除
voluntas Sep 3, 2024
36290bc
ビルド準備が足りてなかった
voluntas Sep 3, 2024
34158fb
お試し
voluntas Sep 3, 2024
2a850a8
これでどうだ
voluntas Sep 3, 2024
f0892e6
デバッグログ削除
voluntas Sep 3, 2024
4efa01b
ubuntu 22.04
voluntas Sep 3, 2024
501c4e5
momo
voluntas Sep 3, 2024
6256039
no-audio-device が重複してた
voluntas Sep 3, 2024
d365099
環境変数化する
voluntas Sep 3, 2024
118476c
チャレンジ
voluntas Sep 3, 2024
fc09a83
no-video-device を削除
voluntas Sep 3, 2024
cfbf2a3
/dev/video0 があるはず
voluntas Sep 3, 2024
2b1a341
確認
voluntas Sep 3, 2024
b905806
整理
voluntas Sep 3, 2024
764f17e
Merge branch 'develop' into feature/add-pytest-e2e-test
voluntas Sep 16, 2024
6d1e548
uv に変更する
voluntas Sep 16, 2024
4a0200f
変更履歴を更新する
voluntas Sep 16, 2024
1179788
[e2e] uv sync
voluntas Sep 16, 2024
d872ce8
移動
voluntas Sep 16, 2024
32f3a6a
[e2e] Momo のバージョンを上げる
voluntas Sep 16, 2024
d2484b0
momo/momo にする
voluntas Sep 16, 2024
e2fe0b1
Merge branch 'develop' into feature/add-pytest-e2e-test
voluntas Sep 16, 2024
f00544b
mv
voluntas Sep 16, 2024
98bd679
--video-device を明示的にしていしてみる
voluntas Sep 16, 2024
e1ec3d4
デバッグ
voluntas Sep 16, 2024
ab7ca5f
Merge branch 'develop' into feature/add-pytest-e2e-test
voluntas Oct 20, 2024
f8960a2
setup-uv@3
voluntas Oct 20, 2024
4d0ba39
build はしない
voluntas Oct 20, 2024
9a973e1
2024.1.0
voluntas Oct 20, 2024
8274e4e
momo --version
voluntas Oct 20, 2024
3486a5e
uv sync --upgrade
voluntas Nov 6, 2024
553aa03
Merge branch 'develop' into feature/add-pytest-e2e-test
voluntas Nov 6, 2024
c905b2d
色々情報追加
voluntas Nov 6, 2024
d6f8604
確認コード
voluntas Nov 6, 2024
9f32cfd
sudo
voluntas Nov 6, 2024
91e8add
sudo 付けてみる
voluntas Nov 6, 2024
5a66299
色々変える
voluntas Nov 6, 2024
0489e24
env 設定
voluntas Nov 6, 2024
75b2f83
metadata
voluntas Nov 6, 2024
5dc9403
てすと
voluntas Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: build-workflow

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

jobs:
build-windows:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: e2e-test

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

jobs:
e2e-test-ubuntu:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
# - ubuntu-24.04
env:
TEST_SIGNALING_URLS: ${{ secrets.TEST_SIGNALING_URLS }}
TEST_CHANNEL_ID_PREFIX: ${{ secrets.TEST_CHANNEL_ID_PREFIX }}
TEST_SECRET_KEY: ${{ secrets.TEST_SECRET_KEY }}
MOMO_VERSION: "2024.1.0"
MOMO_ARCH: "x86_64"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: |
sudo apt update
sudo apt install -y ffmpeg v4l2loopback-dkms v4l2loopback-utils linux-modules-extra-$(uname -r)
- run: |
curl -LO https://github.com/shiguredo/momo/releases/download/${{ env.MOMO_VERSION}}/momo-${{ env.MOMO_VERSION }}_${{ matrix.os }}_${{ env.MOMO_ARCH }}.tar.gz
tar -xzf momo-${{ env.MOMO_VERSION }}_${{ matrix.os }}_${{ env.MOMO_ARCH }}.tar.gz
mkdir -p _build/${{ matrix.os }}_${{ env.MOMO_ARCH }}/release/momo
# chmod 755 momo-${{ env.MOMO_VERSION }}_${{ matrix.os }}_${{ env.MOMO_ARCH }}/momo
chmod 755 momo/momo
# mv momo-${{ env.MOMO_VERSION }}_${{ matrix.os }}_${{ env.MOMO_ARCH }}/momo ${{ github.workspace }}/_build/${{ matrix.os }}_${{ env.MOMO_ARCH }}/release/momo/
mv momo/momo ${{ github.workspace }}/_build/${{ matrix.os }}_${{ env.MOMO_ARCH }}/release/momo/
- uses: astral-sh/setup-uv@v3
- name: setup v4l2loopback
run: |
sudo modprobe v4l2loopback devices=1 video_nr=0 exclusive_caps=1 card_label='VCamera'
ls -l /dev/video0
- run: |
sudo v4l2-ctl --device /dev/video0 --all
sudo v4l2-ctl --device /dev/video0 --list-formats-ext
- run: /home/runner/work/momo/momo/_build/ubuntu-22.04_x86_64/release/momo/momo --version
- run: uv sync
working-directory: ./test
- run: |
uv run pytest test_momo.py -s
working-directory: ./test
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ webrtc_logs_0
/_source
/_install
/_package

# python
.venv
.pytest_cache
__pycache__

# vscode
build

# .env
.env
!.env.template
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@

### misc

- [ADD] pytest を利用した E2E テストを追加
- @voluntas
- [CHANGE] SDL2 のダウンロード先を GitHub に変更する
- @voluntas
- [UPDATE] Github Actions の actions/download-artifact をアップデート
Expand Down
4 changes: 4 additions & 0 deletions test/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TEST_SIGNALING_URLS=wss://sora.example.com/signaling
TEST_CHANNEL_ID_PREFIX=momo_
TEST_SECRET_KEY=secret
TEST_API_URL=https://sora.example.com/api
1 change: 1 addition & 0 deletions test/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
36 changes: 36 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

import pytest
from dotenv import load_dotenv


@pytest.fixture
def setup():
# 環境変数読み込み
load_dotenv()

# signaling_url 単体か複数かをランダムで決めてテストする
if (test_signaling_urls := os.environ.get("TEST_SIGNALING_URLS")) is None:
raise ValueError("TEST_SIGNALING_URLS is required.")

# , で区切って ['wss://...', ...] に変換
test_signaling_urls = test_signaling_urls.split(",")

if (test_channel_id_prefix := os.environ.get("TEST_CHANNEL_ID_PREFIX")) is None:
raise ValueError("TEST_CHANNEL_ID_PREFIX is required.")

if (test_secret_key := os.environ.get("TEST_SECRET_KEY")) is None:
raise ValueError("TEST_SECRET_KEY is required.")

# if (test_api_url := os.environ.get("TEST_API_URL")) is None:
# raise ValueError("TEST_API_URL is required.")

return {
"signaling_urls": test_signaling_urls,
"channel_id_prefix": test_channel_id_prefix,
# "secret": test_secret_key,
# "api_url": test_api_url,
"metadata": {"access_token": test_secret_key},
# openh264_path は str | None でよい
# "openh264_path": os.environ.get("OPENH264_PATH"),
}
113 changes: 113 additions & 0 deletions test/momo_sora.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import json
import platform
import signal
import subprocess
import sys
import threading
import time
import uuid
from pathlib import Path

# プラットフォームに応じたリリースディレクトリの設定
RELEASE_DIR = Path(__file__).resolve().parent.parent / Path("_build/")

# TODO: 環境変数で CI か Local で見に行くパスを変えるようにする
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-22.04_x86_64/release/momo"
else:
raise OSError(f"Unsupported platform: {platform.system()}")


class Momo:
signaling_urls: list[str]
channel_id_prefix: str
metadata: dict[str, str]
port: int

def __init__(
self,
signaling_urls: list[str],
channel_id_prefix: str,
metadata: dict[str, str],
):
self.signaling_urls = signaling_urls
self.channel_id_prefix = channel_id_prefix
self.metadata = metadata

self.channel_id = f"{self.channel_id_prefix}_{uuid.uuid4()}"

self.port = 5000

self.executable = RELEASE_DIR / "momo"
assert self.executable.exists()
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):
print(self.executable)
args = [
str(self.executable),
"sora",
"--signaling-urls",
",".join(self.signaling_urls),
"--channel-id",
self.channel_id_prefix,
# "--video-device",
# これは GitHub Actions 用
# "VCamera",
"--metadata",
json.dumps(self.metadata),
]
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):
if not self.executable.exists():
raise FileNotFoundError(f"Executable file not found: {self.executable}")

self.thread = threading.Thread(target=self.run_app)
self.thread.start()
self.is_running = True

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

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

def stop(self):
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(timeout=5)
self.is_running = False
print("Momo stopped")
21 changes: 21 additions & 0 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "momo-e2e-test"
version = "2013.3.8"
requires-python = ">= 3.12"
dependencies = [
"pytest>=8.3",
"pytest-timeout>=2.3",
"python-dotenv>=1.0",
]

[tool.uv]
package = false
managed = true
dev-dependencies = ["ruff"]

[tool.pytest.ini_options]
timeout = 45

[tool.ruff]
target-version = "py312"
line-length = 100
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_sora import Momo


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

time.sleep(3)

momo.stop()
Loading
Loading