Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ d[0-9][0-9][0-9][0-9][0-9][0-9][0-9]

# 五语言对齐 reference 材料(本地查阅用,不入库)
stdlib/kvlang/reference/

# tutorial shm 测试产物(相对路径 DSN)
kvtut*
15 changes: 8 additions & 7 deletions tutorial/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def _needs_skip(f: Path) -> bool:
return False


def _flush_redis() -> None:
def _flush_backend() -> None:
try:
subprocess.run(
["redis-cli", "-p", "6379", "FLUSHALL"],
capture_output=True, timeout=5,
["kvspace", "clear"],
capture_output=True, timeout=10,
env={**os.environ, "KVSPACE": _C_DSN},
)
except FileNotFoundError:
pass
Expand Down Expand Up @@ -141,7 +142,7 @@ def _benchmark_file(f: Path, expects: list[str]) -> tuple[dict[str, str], str]:
return invalid, "C compilation failed"

try:
_flush_redis()
_flush_backend()
kv_result, kv_ms = _timed_run([KV, rel], env=_KV_ENV)
py_result, py_ms = _timed_run([sys.executable, str(f.with_suffix(".py"))])
c_result, c_ms = _timed_run([str(executable)])
Expand Down Expand Up @@ -202,15 +203,15 @@ def _run_test_file(f: Path, expects: list[str], env: dict) -> tuple[bool, str]:
elif _C_DSN.startswith("fs://"):
shutil.rmtree(_C_DSN[len("fs://"):], ignore_errors=True)
else:
_flush_redis()
_flush_backend()
layout = subprocess.run([LAYOUT_BIN, rel, _C_DSN], capture_output=True, text=True,
timeout=60, cwd=str(ROOT), env=env)
if layout.returncode != 0:
return False, f"layout failed: {layout.stderr.strip()[:100]}"
entry = "test" # 约定入口:每个 tutorial 顶层 rwfunc test()(pkg 空、裸名)
try:
crun = subprocess.run([TERM_BIN, entry], capture_output=True, text=True,
timeout=120, cwd=str(ROOT), env={**env, "KVSPACE": _C_DSN})
timeout=int(os.environ.get("KV_CASE_TIMEOUT", "120")), cwd=str(ROOT), env={**env, "KVSPACE": _C_DSN})
except subprocess.TimeoutExpired:
return False, "timeout"
if crun.returncode != 0:
Expand Down Expand Up @@ -322,7 +323,7 @@ def setUp(self):
mock.patch.object(MODULE, "KV", str(self.kvlang)),
mock.patch.object(MODULE, "FAIL_CSV", self.tutorial / "test_failures.csv"),
mock.patch.object(MODULE, "BENCH_CSV", self.tutorial / "benchmark.csv"),
mock.patch.object(MODULE, "_flush_redis"),
mock.patch.object(MODULE, "_flush_backend"),
mock.patch("builtins.print"),
]
for patcher in self.patchers:
Expand Down
Loading