Skip to content

Commit cb9501a

Browse files
committed
テストの設定値を定数化し、帯域制限のテストメッセージを改善する
1 parent dcfe9c1 commit cb9501a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/test_tc.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
# pyroute2 がインストールされていない場合はスキップ
2323
pyroute2 = pytest.importorskip("pyroute2")
2424

25+
# テスト用の設定値
26+
INITIAL_BITRATE_KBPS = 1500 # 初期ビットレート (kbps)
27+
BANDWIDTH_LIMIT_KBPS = 250 # 帯域制限値 (kbps)
28+
MIN_BITRATE_BEFORE_LIMIT_KBPS = 750 # 制限前の最小ビットレート (kbps)
29+
2530

2631
def get_default_interface() -> str:
2732
"""デフォルトのネットワークインターフェース名を取得する。
@@ -287,7 +292,7 @@ def show_webrtc_stats(stats: list) -> None:
287292
def test_tc_egress_bandwidth_limit(settings):
288293
"""TURN ポート取得後に tc egress で帯域制限をかける。"""
289294
print("\n" + "=" * 60)
290-
print("テスト: tc egress 帯域制限 (250kbps) の適用")
295+
print(f"テスト: tc egress 帯域制限 ({BANDWIDTH_LIMIT_KBPS}kbps) の適用")
291296
print("=" * 60)
292297

293298
interface = get_default_interface()
@@ -296,9 +301,10 @@ def test_tc_egress_bandwidth_limit(settings):
296301
with SoraClient(
297302
settings,
298303
SoraRole.SENDONLY,
304+
simulcast=True,
299305
audio=False,
300306
video=True,
301-
video_bit_rate=1000,
307+
video_bit_rate=INITIAL_BITRATE_KBPS,
302308
) as sendonly:
303309
time.sleep(10)
304310

@@ -337,17 +343,16 @@ def test_tc_egress_bandwidth_limit(settings):
337343
print(
338344
f"\n制限前の targetBitrate: {target_bitrate_before} bps ({target_bitrate_before / 1000} kbps)"
339345
)
340-
# video_bit_rate=1000 を指定しているので、750kbps 以上あることを確認
341-
assert target_bitrate_before >= 750 * 1000, (
342-
f"制限前の targetBitrate が想定より低い: {target_bitrate_before} bps < 750000 bps"
346+
# video_bit_rate を指定しているので、MIN_BITRATE_BEFORE_LIMIT_KBPS 以上あることを確認
347+
assert target_bitrate_before >= MIN_BITRATE_BEFORE_LIMIT_KBPS * 1000, (
348+
f"制限前の targetBitrate が想定より低い: {target_bitrate_before} bps < {MIN_BITRATE_BEFORE_LIMIT_KBPS * 1000} bps"
343349
)
344350

345351
# tc egress で帯域制限を設定
346352
with TCEgressManager(interface=interface) as tc:
347-
bandwidth_kbps = 250
348353
# 帯域制限を設定
349-
print(f"\nステップ 1: tc egress 帯域制限 {bandwidth_kbps}kbps を適用")
350-
tc.add_bandwidth_limit(rate_kbps=bandwidth_kbps)
354+
print(f"\nステップ 1: tc egress 帯域制限 {BANDWIDTH_LIMIT_KBPS}kbps を適用")
355+
tc.add_bandwidth_limit(rate_kbps=BANDWIDTH_LIMIT_KBPS)
351356

352357
# tc の設定が存在することを確認
353358
print("\nステップ 2: tc 設定を確認")
@@ -389,10 +394,10 @@ def test_tc_egress_bandwidth_limit(settings):
389394

390395
target_bitrate = outbound_rtp["targetBitrate"]
391396
print(f"\n確認: targetBitrate = {target_bitrate} bps ({target_bitrate / 1000} kbps)")
392-
print(f"期待値: {bandwidth_kbps} kbps 以下")
397+
print(f"期待値: {BANDWIDTH_LIMIT_KBPS} kbps 以下")
393398
# 帯域制限が効いているか確認(多少のオーバーヘッドを考慮)
394-
assert target_bitrate <= bandwidth_kbps * 1000 * 1.2, (
395-
f"targetBitrate が帯域制限を超えています: {target_bitrate} bps > {bandwidth_kbps * 1000} bps"
399+
assert target_bitrate <= BANDWIDTH_LIMIT_KBPS * 1000 * 1.2, (
400+
f"targetBitrate が帯域制限を超えています: {target_bitrate} bps > {BANDWIDTH_LIMIT_KBPS * 1000} bps"
396401
)
397402

398403
print("\n帯域制限が有効な状態でテスト完了")

0 commit comments

Comments
 (0)