mirror of
https://github.com/unclebob/mutator.git
synced 2026-11-26 18:58:50 +00:00
Retry worker cleanup when Gradle writes after the client exits.
Why: delete_tree walked the worker tree and called rmdir once. Gradle can still be flushing a test report then, so a directory that looked empty raises OSError [Errno 39] Directory not empty (or a file vanishes before unlink) and the whole mutation run aborts. What: delete_tree retries the walk, with injectable sleep and attempt count so tests do not wait. A vanished file is unlinked with missing_ok. Symlinks are still unlinked, never followed into the real project. Proof: six new tests (late file, vanished file, missing path, regular file, symlink left alone, exhausted retries re-raise). 78 tests were green before; 84 pass now. crapper: delete_tree 5.0, _delete_once 5.0, every function in workers.py under 10. dryer: no candidates. mutator on the nine changed sites: 9 killed, 0 survived, 0 uncovered.
This commit is contained in:
+25
-5
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
@@ -93,20 +94,39 @@ def symlink(link: Path, target: Path) -> None:
|
||||
link.symlink_to(target.resolve())
|
||||
|
||||
|
||||
def delete_tree(path: Path) -> None:
|
||||
"""Remove a worker tree without following a link into the real project."""
|
||||
def delete_tree(path: Path, attempts: int = 20, sleep=time.sleep) -> None:
|
||||
"""Remove a worker tree without following a link into the real project.
|
||||
|
||||
Gradle can still be flushing a test report when the client exits, so a
|
||||
directory that looked empty can gain a file before ``rmdir``. Retry the
|
||||
walk instead of aborting the file's mutation run.
|
||||
"""
|
||||
|
||||
last: OSError | None = None
|
||||
for attempt in range(attempts):
|
||||
try:
|
||||
_delete_once(path)
|
||||
return
|
||||
except OSError as error:
|
||||
last = error
|
||||
if attempt + 1 < attempts:
|
||||
sleep(0.25 * (attempt + 1))
|
||||
if last is not None:
|
||||
raise last
|
||||
|
||||
|
||||
def _delete_once(path: Path) -> None:
|
||||
if path.is_symlink():
|
||||
path.unlink()
|
||||
path.unlink(missing_ok=True)
|
||||
return
|
||||
if not path.exists():
|
||||
return
|
||||
if path.is_dir():
|
||||
for child in list(path.iterdir()):
|
||||
delete_tree(child)
|
||||
_delete_once(child)
|
||||
path.rmdir()
|
||||
return
|
||||
path.unlink()
|
||||
path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def _copy_configs(worker: Path, root: Path, relative: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user