60 lines
2.9 KiB
Python
60 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Test template replay against an isolated, bounded local Redis container."""
|
|
import argparse
|
|
import datetime
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import time
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
def run(args, **kwargs):
|
|
return subprocess.run(args, check=True, capture_output=True, text=True, **kwargs).stdout.strip()
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--report", type=Path, default=ROOT / "performance/errorParamsRedis.json")
|
|
args = parser.parse_args()
|
|
started = time.monotonic()
|
|
container = run(["docker", "run", "--pull=never", "--rm", "-d", "--cpus", "1", "--memory", "128m",
|
|
"--pids-limit", "64", "-p", "127.0.0.1::6379", "redis:7-alpine",
|
|
"redis-server", "--save", "", "--appendonly", "no", "--maxmemory", "64mb",
|
|
"--maxmemory-policy", "noeviction"])
|
|
print("Started isolated Redis (1 CPU, 128 MiB); loopback only", flush=True)
|
|
try:
|
|
image = run(["docker", "inspect", "--format", "{{.Image}}", container])
|
|
address = run(["docker", "port", container, "6379/tcp"])
|
|
for _ in range(30):
|
|
try:
|
|
if run(["docker", "exec", container, "redis-cli", "ping"]) == "PONG":
|
|
break
|
|
except subprocess.CalledProcessError:
|
|
pass
|
|
time.sleep(0.1)
|
|
else:
|
|
raise RuntimeError("Redis did not become ready")
|
|
env = dict(os.environ, GO_OMNI_REDIS_TEST_ADDR=address)
|
|
output = run(["go", "test", "-race", "-count=1", "-json", "-timeout=120s",
|
|
"./middleware/redis"], cwd=ROOT, env=env, timeout=150)
|
|
events = [json.loads(line) for line in output.splitlines() if line.startswith("{")]
|
|
passed = [e["Test"] for e in events if e.get("Action") == "pass" and "Test" in e]
|
|
skipped = [e["Test"] for e in events if e.get("Action") == "skip" and "Test" in e]
|
|
assert "TestTemplateErrorRedisReplay" in passed and not skipped, (passed, skipped)
|
|
args.report.write_text(json.dumps({
|
|
"passed": True, "image": image, "timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
"goVersion": run(["go", "version"]), "durationSeconds": round(time.monotonic() - started, 2),
|
|
"passedTests": passed, "skippedTests": skipped,
|
|
"checks": ["templateReplay", "int64CodePrecisionThroughLua", "catalogChangeKeepsSnapshot",
|
|
"noPersistedCauseOrParams", "http200Failure", "dataNull", "oneBusinessExecution"],
|
|
"cpuLimit": 1, "memoryMiB": 128, "loopbackOnly": True,
|
|
}, ensure_ascii=False, indent=2) + "\n")
|
|
print("PASS isolated Redis template replay and shared store regressions", flush=True)
|
|
finally:
|
|
run(["docker", "rm", "-f", container])
|
|
print("Temporary Redis container removed", flush=True)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|