Files
scylladb/test/pylib_test/test_util.py
Alex 73f1a65203 test/pylib: introduce scale_timeout fixture helper
Introduce scale_timeout(mode) to centralize test timeout scaling logic based on build mode, the function will return a callable that will handle the timeout by mode.
This ensures consistent timeout behavior across test helpers and eliminates ad-hoc per-test scaling adjustments.
Centralizing the logic improves maintainability and makes timeout behavior easier to reason about.
This becomes increasingly important as we run tests on heterogeneous hardware configurations.
Different build modes (especially debug) can significantly affect execution time, and having a single scaling mechanism helps keep test stability predictable across environments.

No functional change beyond unifying existing timeout scaling behavior.
2026-03-05 13:07:09 +02:00

45 lines
1.6 KiB
Python

import os
import tempfile
import pathlib
import pytest
from test.pylib.util import read_last_line, scale_timeout_by_mode
def test_read_last_line():
test_cases = [
(b"This is the first line.\nThis is the second line.\nThis is the third line.", 'This is the third line.'),
(b"This is another file.\nIt has a few lines.\nThe last line is what we're interested in.", 'The last line is what we\'re interested in.'),
(b"This file has only one line.", 'This file has only one line.'),
(b"\n", ""),
(b"\n\n\n", ""),
(b"", ""),
(b"abc\n", 'abc'),
(b"abc", '...bc', 2),
(b"lalala\nbububu", "bububu"),
(b"line1\nline2\nline3\n", "...line3", 6),
(b"line1\nline2\nline3", "line3", 6),
(b"line1\nline2\nline3\n", "line3", 7),
(b"\xbe\xbe\xbe\xbebububu\n", "bububu")
]
for test_case in test_cases:
with tempfile.NamedTemporaryFile(dir=os.getenv('TMPDIR', '/tmp')) as f:
f.write(test_case[0])
f.flush()
file_path = pathlib.Path(f.name)
actual = read_last_line(file_path, test_case[2]) if len(test_case) == 3 else read_last_line(file_path)
assert(actual == test_case[1])
@pytest.mark.parametrize(
"mode,base_timeout,expected",
[
("debug", 10, 30),
("sanitize", 10, 30),
("release", 10, 10),
("dev", 10, 20),
("coverage", 10, 10),
("custom_exe", 10, 10),
],
)
def test_scale_timeout_by_mode(mode, base_timeout, expected):
assert scale_timeout_by_mode(mode, base_timeout) == expected