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

Check netem cmd sucess and pytest-timeout pkg existence #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions hw/1_tcp/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
import pkgutil

def pytest_configure(config):
found_pytest_timeout = False
for pkg in pkgutil.iter_modules():
if pkg.name == "pytest_timeout":
found_pytest_timeout = True
break
if not found_pytest_timeout:
pytest.exit(
"pytest-timeout not found. Please install it via package manager " +
"(usually, package name is python3-pytest-timeout) or pip " +
"(sudo pip install python3-pytest-timeout)."
)
14 changes: 11 additions & 3 deletions hw/1_tcp/protocol_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import random
from contextlib import closing
import platform

import pytest
from testable_thread import TestableThread
Expand Down Expand Up @@ -44,7 +45,6 @@ def run_test(client_class, server_class, iterations, msg_size=None):

current_netem_state = None


def setup_netem(packet_loss, duplicate, reorder):
global current_netem_state
if current_netem_state == (packet_loss, duplicate, reorder):
Expand All @@ -54,8 +54,16 @@ def setup_netem(packet_loss, duplicate, reorder):
if reorder > 0:
netem_cmd += f" reorder {100 - reorder}%"
netem_cmd += " delay 10ms rate 1Mbit"
os.system(netem_cmd)

return_code = os.system(netem_cmd)
if return_code != 0:
message = "Could not configure netem. Please check tc executable is available."
if platform.system() != "Linux":
message = (
"Linux is needed in order to execute tests. " +
"If docker is available, you can use it."
)
# Also exits even if not under pytest.
pytest.exit(message)

@pytest.mark.parametrize("iterations", [10, 50, 100])
@pytest.mark.timeout(30)
Expand Down
2 changes: 1 addition & 1 deletion hw/1_tcp/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -xeuo pipefail

pytest -v protocol_test.py -o log_cli=true --durations=0
pytest -v protocol_test.py -o log_cli=true --durations=0 --capture=sys