mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-25 17:54:58 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 665c14ad61 |
@@ -1,6 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -48,6 +51,52 @@ class WarpRawQualityTest(unittest.TestCase):
|
||||
self.assertEqual(result["host_counts"], {"a": 4, "b": 4})
|
||||
self.assertAlmostEqual(result["reqps"], 1.0)
|
||||
|
||||
def run_cli(self, source: Path, *flags: str) -> tuple[int, dict]:
|
||||
output = source.with_name("quality.json")
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(MODULE_PATH), "--input", str(source), "--output", str(output), *flags],
|
||||
check=False,
|
||||
)
|
||||
return result.returncode, json.loads(output.read_text())
|
||||
|
||||
def test_steady_rate_uses_exact_completions_and_accepts_the_minimum(self) -> None:
|
||||
source = self.fixture()
|
||||
status, result = self.run_cli(source, "--steady-after-seconds", "1", "--min-steady-rps", "1")
|
||||
self.assertEqual(status, 0)
|
||||
self.assertEqual(result["status"], "pass")
|
||||
self.assertEqual(result["steady"]["completed_objects"], 2)
|
||||
self.assertEqual(result["steady"]["start_ns"], result["measure_start_ns"] + 1_000_000_000)
|
||||
self.assertEqual(result["steady"]["duration_secs"], 2)
|
||||
self.assertEqual(result["steady"]["completed_objects_per_second"], 1)
|
||||
|
||||
def test_steady_shortfall_fails_even_when_whole_window_rate_meets_threshold(self) -> None:
|
||||
source = self.fixture()
|
||||
intervals = ((0, 1), (1, 2), (2, 3), (3, 4), (4, 9), (9, 10))
|
||||
source.write_text(HEADER + "".join(row(0, "a", start, end) for start, end in intervals))
|
||||
status, old_result = self.run_cli(source)
|
||||
self.assertEqual(status, 0)
|
||||
self.assertGreaterEqual(old_result["reqps"], 0.5)
|
||||
self.assertNotIn("steady", old_result)
|
||||
status, result = self.run_cli(source, "--steady-after-seconds", "4", "--min-steady-rps", "0.5")
|
||||
self.assertEqual(status, 1)
|
||||
self.assertEqual(result["reason"], "steady completion rate below minimum")
|
||||
self.assertEqual(result["steady"]["completed_objects"], 0)
|
||||
self.assertEqual(result["reqps"], old_result["reqps"])
|
||||
|
||||
def test_invalid_steady_gate_rejects_missing_empty_and_nonfinite_options(self) -> None:
|
||||
source = self.fixture()
|
||||
cases = (
|
||||
("--steady-after-seconds", "1"),
|
||||
("--steady-after-seconds", "3", "--min-steady-rps", "1"),
|
||||
("--steady-after-seconds", "-1", "--min-steady-rps", "1"),
|
||||
("--steady-after-seconds", "1", "--min-steady-rps", "nan"),
|
||||
)
|
||||
for args in cases:
|
||||
with self.subTest(args=args):
|
||||
status, result = self.run_cli(source, *args)
|
||||
self.assertEqual(status, 1)
|
||||
self.assertEqual(result["status"], "fail")
|
||||
|
||||
def test_any_raw_error_fails_closed(self) -> None:
|
||||
with self.assertRaisesRegex(ValueError, "contains request errors"):
|
||||
MODULE.parse(self.fixture(error=True), {"a", "b"})
|
||||
|
||||
@@ -8,6 +8,7 @@ import csv
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -45,7 +46,9 @@ def open_text(path: Path):
|
||||
return io.TextIOWrapper(process.stdout, newline=""), process
|
||||
|
||||
|
||||
def parse(path: Path, expected_hosts: set[str] | None) -> dict:
|
||||
def parse(path: Path, expected_hosts: set[str] | None, *, steady_after_seconds: int | None = None) -> dict:
|
||||
if steady_after_seconds is not None and steady_after_seconds < 0:
|
||||
raise ValueError("steady cutoff must be nonnegative")
|
||||
opened = open_text(path)
|
||||
process = None
|
||||
if isinstance(opened, tuple):
|
||||
@@ -102,7 +105,7 @@ def parse(path: Path, expected_hosts: set[str] | None) -> dict:
|
||||
overlap = max(0, min(end, window_end) - max(start, window_start))
|
||||
fractional_objects += objects * overlap / (end - start)
|
||||
duration_secs = (window_end - window_start) / 1_000_000_000
|
||||
return {
|
||||
result = {
|
||||
"schema_version": 1,
|
||||
"source": str(path),
|
||||
"source_sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
|
||||
@@ -121,6 +124,20 @@ def parse(path: Path, expected_hosts: set[str] | None) -> dict:
|
||||
"reqps": fractional_objects / duration_secs,
|
||||
"window_status": "warp_v1.8.2_common_active_window",
|
||||
}
|
||||
if steady_after_seconds is not None:
|
||||
steady_start = window_start + steady_after_seconds * 1_000_000_000
|
||||
if steady_start >= window_end:
|
||||
raise ValueError("steady cutoff leaves no common active window")
|
||||
steady_duration = (window_end - steady_start) / 1_000_000_000
|
||||
steady_objects = sum(objects for _, end, objects, error in rows if not error and steady_start <= end < window_end)
|
||||
result["steady"] = {
|
||||
"start_ns": steady_start,
|
||||
"end_exclusive_ns": window_end,
|
||||
"duration_secs": steady_duration,
|
||||
"completed_objects": steady_objects,
|
||||
"completed_objects_per_second": steady_objects / steady_duration,
|
||||
}
|
||||
return result
|
||||
finally:
|
||||
stream.close()
|
||||
if process is not None:
|
||||
@@ -134,15 +151,30 @@ def main() -> int:
|
||||
parser.add_argument("--input", required=True)
|
||||
parser.add_argument("--output", required=True)
|
||||
parser.add_argument("--expected-host", action="append")
|
||||
parser.add_argument("--steady-after-seconds", type=int, help="Seconds to exclude from the start of the common active window")
|
||||
parser.add_argument("--min-steady-rps", type=float, help="Minimum successful object completions per second in the steady window")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
result = parse(Path(args.input), set(args.expected_host) if args.expected_host else None)
|
||||
if (args.steady_after_seconds is None) != (args.min_steady_rps is None):
|
||||
raise ValueError("--steady-after-seconds and --min-steady-rps must be used together")
|
||||
if args.min_steady_rps is not None and (not math.isfinite(args.min_steady_rps) or args.min_steady_rps <= 0):
|
||||
raise ValueError("minimum steady rate must be finite and positive")
|
||||
result = parse(
|
||||
Path(args.input),
|
||||
set(args.expected_host) if args.expected_host else None,
|
||||
steady_after_seconds=args.steady_after_seconds,
|
||||
)
|
||||
except (OSError, RuntimeError, ValueError, csv.Error) as error:
|
||||
Path(args.output).write_text(json.dumps({"schema_version": 1, "status": "fail", "reason": str(error)}, indent=2) + "\n")
|
||||
return 1
|
||||
result["status"] = "pass"
|
||||
if args.min_steady_rps is not None:
|
||||
steady = result["steady"]
|
||||
steady["min_completed_objects_per_second"] = args.min_steady_rps
|
||||
if steady["completed_objects_per_second"] < args.min_steady_rps:
|
||||
result.update(status="fail", reason="steady completion rate below minimum")
|
||||
Path(args.output).write_text(json.dumps(result, indent=2, sort_keys=True) + "\n")
|
||||
return 0
|
||||
return int(result["status"] == "fail")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user