Skip to content
Snippets Groups Projects
Unverified Commit b0d3067f authored by Sergey V's avatar Sergey V
Browse files

refactor(test): make xdist_worker_number a fixture

parent a06ff88d
No related branches found
No related tags found
No related merge requests found
......@@ -23,13 +23,13 @@ from tarantool.error import ( # type: ignore
# A constant represents invalid id of raft.
# pub const INVALID_ID: u64 = 0;
INVALID_RAFT_ID = 0
RE_XDIST_WORKER_ID = re.compile(r"^gw(\d+)$")
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
@pytest.fixture(scope="session")
def xdist_worker_number(worker_id: str) -> int:
"""
Identify xdist worker by an integer instead of a string.
......@@ -40,9 +40,8 @@ def xdist_worker_number(worker_id: str) -> int:
if worker_id == "master":
return 0
match = RE_XDIST_WORKER_ID.match(worker_id)
if not match:
raise ValueError(worker_id)
match = re.fullmatch(r"gw(\d+)", worker_id)
assert match, f"unexpected worker id: {worker_id}"
return int(match.group(1))
......@@ -403,8 +402,8 @@ def binary_path(compile) -> str:
@pytest.fixture
def cluster(binary_path, tmpdir, worker_id) -> Generator[Cluster, None, None]:
n = xdist_worker_number(worker_id)
def cluster(binary_path, tmpdir, xdist_worker_number) -> Generator[Cluster, None, None]:
n = xdist_worker_number
assert isinstance(n, int)
assert n >= 0
......
......@@ -5,7 +5,6 @@ import pytest
import signal
from conftest import (
xdist_worker_number,
Instance,
TarantoolError,
ReturnError,
......@@ -13,23 +12,6 @@ from conftest import (
)
def test_xdist_worker_number():
assert xdist_worker_number("master") == 0
assert xdist_worker_number("gw0") == 0
assert xdist_worker_number("gw1") == 1
assert xdist_worker_number("gw007") == 7
assert xdist_worker_number("gw1024") == 1024
with pytest.raises(ValueError, match=r"gw"):
assert xdist_worker_number("gw")
with pytest.raises(ValueError, match=r"xgw8x"):
assert xdist_worker_number("xgw8x")
with pytest.raises(ValueError, match=r"wtf"):
assert xdist_worker_number("wtf")
def test_call_normalization(instance: Instance):
assert instance.call("tostring", 1) == "1"
assert instance.call("dostring", "return") is None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment