Skip to content

Commit

Permalink
Merge pull request #126 from shiguredo/feature/e2e-test-degradation-p…
Browse files Browse the repository at this point in the history
…reference

degradation-preference のテストを整理する
  • Loading branch information
voluntas authored Jan 14, 2025
2 parents e81a3f4 + 097c3b2 commit 417a86e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 43 deletions.
101 changes: 62 additions & 39 deletions tests/test_degradation_preference.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import os
import sys
import time
import uuid

import pytest
from client import SoraClient, SoraDegradationPreference, SoraRole

VIDEO_CODEC_TYPE = "VP8"
VIDEO_BIT_RATE = 300
VIDEO_WIDTH = 960
VIDEO_HEIGHT = 528


@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform == "darwin",
reason="CI の macOS では性能がでないためスキップする",
)
def test_degradation_preference_maintain_framerate(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
Expand All @@ -18,11 +29,11 @@ def test_degradation_preference_maintain_framerate(setup):
channel_id,
audio=False,
video=True,
video_codec_type="VP8",
video_bit_rate=100,
video_codec_type=VIDEO_CODEC_TYPE,
video_bit_rate=VIDEO_BIT_RATE,
metadata=metadata,
video_width=1280,
video_height=720,
video_width=VIDEO_WIDTH,
video_height=VIDEO_HEIGHT,
degradation_preference=SoraDegradationPreference.MAINTAIN_FRAMERATE,
)
sendonly.connect(fake_video=True)
Expand All @@ -41,10 +52,10 @@ def test_degradation_preference_maintain_framerate(setup):
outbound_rtp_stats = next(s for s in sendonly_stats if s.get("type") == "outbound-rtp")
assert outbound_rtp_stats["bytesSent"] > 0
assert outbound_rtp_stats["packetsSent"] > 0
assert outbound_rtp_stats["frameWidth"] <= 320
assert outbound_rtp_stats["frameHeight"] <= 180
# ビットレートが 100 kbps 以下
assert outbound_rtp_stats["targetBitrate"] < 100_000
assert outbound_rtp_stats["frameWidth"] <= 640
assert outbound_rtp_stats["frameHeight"] <= 360
# ビットレートが 500 kbps 以下
assert outbound_rtp_stats["targetBitrate"] < VIDEO_BIT_RATE * 1000
# 20 以上を維持してる
assert outbound_rtp_stats["framesPerSecond"] > 20

Expand All @@ -56,6 +67,10 @@ def test_degradation_preference_maintain_framerate(setup):
)


@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform == "darwin",
reason="CI の macOS では性能がでないためスキップする",
)
def test_degradation_preference_maintain_resolution(setup):
"""
フレームレートがあまり変わらない
Expand All @@ -72,11 +87,11 @@ def test_degradation_preference_maintain_resolution(setup):
channel_id,
audio=False,
video=True,
video_codec_type="VP8",
video_bit_rate=100,
video_codec_type=VIDEO_CODEC_TYPE,
video_bit_rate=VIDEO_BIT_RATE,
metadata=metadata,
video_width=1280,
video_height=720,
video_width=VIDEO_WIDTH,
video_height=VIDEO_HEIGHT,
degradation_preference=SoraDegradationPreference.MAINTAIN_RESOLUTION,
)
sendonly.connect(fake_video=True)
Expand All @@ -89,17 +104,17 @@ def test_degradation_preference_maintain_resolution(setup):

# codec が無かったら StopIteration 例外が上がる
sendonly_codec_stats = next(s for s in sendonly_stats if s.get("type") == "codec")
assert sendonly_codec_stats["mimeType"] == "video/VP8"
assert sendonly_codec_stats["mimeType"] == f"video/{VIDEO_CODEC_TYPE}"

# outbound-rtp が無かったら StopIteration 例外が上がる
outbound_rtp_stats = next(s for s in sendonly_stats if s.get("type") == "outbound-rtp")
assert outbound_rtp_stats["bytesSent"] > 0
assert outbound_rtp_stats["packetsSent"] > 0
# 解像度が維持されてる
assert outbound_rtp_stats["frameWidth"] == 1280
assert outbound_rtp_stats["frameHeight"] == 720
# ビットレートが 100 kbps 以下
assert outbound_rtp_stats["targetBitrate"] < 100_000
assert outbound_rtp_stats["frameWidth"] == VIDEO_WIDTH
assert outbound_rtp_stats["frameHeight"] == VIDEO_HEIGHT
# ビットレートが 500 kbps 以下
assert outbound_rtp_stats["targetBitrate"] < VIDEO_BIT_RATE * 1000

print(
outbound_rtp_stats["frameWidth"],
Expand All @@ -109,6 +124,10 @@ def test_degradation_preference_maintain_resolution(setup):
)


@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform == "darwin",
reason="CI の macOS では性能がでないためスキップする",
)
def test_degradation_preference_balanced(setup):
"""
バランス思った以上に両方悪くなる
Expand All @@ -125,11 +144,11 @@ def test_degradation_preference_balanced(setup):
channel_id,
audio=False,
video=True,
video_codec_type="VP8",
video_bit_rate=100,
video_codec_type=VIDEO_CODEC_TYPE,
video_bit_rate=VIDEO_BIT_RATE,
metadata=metadata,
video_width=1280,
video_height=720,
video_width=VIDEO_WIDTH,
video_height=VIDEO_HEIGHT,
degradation_preference=SoraDegradationPreference.BALANCED,
)
sendonly.connect(fake_video=True)
Expand All @@ -142,18 +161,18 @@ def test_degradation_preference_balanced(setup):

# codec が無かったら StopIteration 例外が上がる
sendonly_codec_stats = next(s for s in sendonly_stats if s.get("type") == "codec")
assert sendonly_codec_stats["mimeType"] == "video/VP8"
assert sendonly_codec_stats["mimeType"] == f"video/{VIDEO_CODEC_TYPE}"

# outbound-rtp が無かったら StopIteration 例外が上がる
outbound_rtp_stats = next(s for s in sendonly_stats if s.get("type") == "outbound-rtp")
assert outbound_rtp_stats["bytesSent"] > 0
assert outbound_rtp_stats["packetsSent"] > 0
assert outbound_rtp_stats["frameWidth"] <= 320
assert outbound_rtp_stats["frameHeight"] <= 180
# ビットレートが 100 kbps 以下
assert outbound_rtp_stats["targetBitrate"] < 100_000
# フレームレートが 20 未満
assert outbound_rtp_stats["framesPerSecond"] < 20
assert outbound_rtp_stats["frameWidth"] <= 640
assert outbound_rtp_stats["frameHeight"] <= 360
# ビットレートが 500 kbps 未満
assert outbound_rtp_stats["targetBitrate"] < VIDEO_BIT_RATE * 1000
# フレームレートが 30 未満
assert outbound_rtp_stats["framesPerSecond"] < 30

print(
outbound_rtp_stats["frameWidth"],
Expand All @@ -163,6 +182,10 @@ def test_degradation_preference_balanced(setup):
)


@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform == "darwin",
reason="CI の macOS では性能がでないためスキップする",
)
def test_degradation_preference_disabled(setup):
"""
無効にする
Expand All @@ -179,11 +202,11 @@ def test_degradation_preference_disabled(setup):
channel_id,
audio=False,
video=True,
video_codec_type="VP8",
video_bit_rate=100,
video_codec_type=VIDEO_CODEC_TYPE,
video_bit_rate=VIDEO_BIT_RATE,
metadata=metadata,
video_width=1280,
video_height=720,
video_width=VIDEO_WIDTH,
video_height=VIDEO_HEIGHT,
degradation_preference=SoraDegradationPreference.DISABLED,
)
sendonly.connect(fake_video=True)
Expand All @@ -196,18 +219,18 @@ def test_degradation_preference_disabled(setup):

# codec が無かったら StopIteration 例外が上がる
sendonly_codec_stats = next(s for s in sendonly_stats if s.get("type") == "codec")
assert sendonly_codec_stats["mimeType"] == "video/VP8"
assert sendonly_codec_stats["mimeType"] == f"video/{VIDEO_CODEC_TYPE}"

# outbound-rtp が無かったら StopIteration 例外が上がる
outbound_rtp_stats = next(s for s in sendonly_stats if s.get("type") == "outbound-rtp")
assert outbound_rtp_stats["bytesSent"] > 0
assert outbound_rtp_stats["packetsSent"] > 0
assert outbound_rtp_stats["frameWidth"] == 1280
assert outbound_rtp_stats["frameHeight"] == 720
# ビットレートが 100 kbps 以下
assert outbound_rtp_stats["targetBitrate"] < 100_000
# フレームレートが 20 以上
assert outbound_rtp_stats["framesPerSecond"] >= 20
assert outbound_rtp_stats["frameWidth"] == VIDEO_WIDTH
assert outbound_rtp_stats["frameHeight"] == VIDEO_HEIGHT
# ビットレートが 500 kbps 未満
assert outbound_rtp_stats["targetBitrate"] < VIDEO_BIT_RATE * 1000
# フレームレートが 30 未満
assert outbound_rtp_stats["framesPerSecond"] < 30

print(
outbound_rtp_stats["frameWidth"],
Expand Down
6 changes: 5 additions & 1 deletion tests/test_simulcast.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import time
import uuid
Expand All @@ -6,6 +7,9 @@
from client import SoraClient, SoraRole


@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform == "darwin", reason="darwin では実行しない"
)
@pytest.mark.parametrize(
(
"video_codec_type",
Expand Down Expand Up @@ -113,7 +117,7 @@ def test_simulcast(
assert encoder_implementation in s["encoderImplementation"]

assert s["bytesSent"] > 1000
assert s["packetsSent"] > 20
assert s["packetsSent"] > 10
# targetBitrate が指定したビットレートの 90% 以上、100% 以下に収まることを確認
expected_bitrate = video_bit_rate * 1000
print(
Expand Down
14 changes: 11 additions & 3 deletions tests/test_sora_disconnect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import time
import uuid
Expand All @@ -10,7 +11,10 @@
from sora_sdk import SoraSignalingErrorCode


@pytest.mark.skipif(sys.platform != "linux", reason="linux でのみ実行する")
@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform != "linux",
reason="CI では linux でのみ実行する",
)
def test_websocket_signaling_only_disconnect_api(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
Expand Down Expand Up @@ -84,7 +88,9 @@ def test_websocket_signaling_only_lifetime_expired(setup):
assert conn.ws_close_reason == "LIFETIME-EXPIRED"


@pytest.mark.skipif(sys.platform != "linux", reason="linux でのみ実行する")
@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform != "linux", reason="linux でのみ実行する"
)
def test_websocket_datachannel_signaling_disconnect_api(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
Expand Down Expand Up @@ -158,7 +164,9 @@ def test_websocket_datachannel_signaling_lifetime_expired(setup):
assert conn.ws_close_reason == "LIFETIME-EXPIRED"


@pytest.mark.skipif(sys.platform != "linux", reason="linux でのみ実行する")
@pytest.mark.skipif(
os.getenv("CI") == "true" and sys.platform != "linux", reason="linux でのみ実行する"
)
def test_datachannel_only_signaling_disconnect_api(setup):
signaling_urls = setup.get("signaling_urls")
channel_id_prefix = setup.get("channel_id_prefix")
Expand Down

0 comments on commit 417a86e

Please sign in to comment.