mirror of https://github.com/zulip/zulip.git
test_fixtures: Add logic for removing stale test directories.
Similarly to how stale database removal is handled, we add a check for stale test run directories at the end of the `test-backend` script.
This commit is contained in:
parent
f7f32df3ef
commit
0e3fddbc6e
|
@ -193,7 +193,8 @@ def main() -> None:
|
|||
os.environ["http_proxy"] = ""
|
||||
os.environ["https_proxy"] = ""
|
||||
|
||||
from zerver.lib.test_fixtures import update_test_databases_if_required
|
||||
from zerver.lib.test_fixtures import update_test_databases_if_required, \
|
||||
remove_test_run_directories
|
||||
|
||||
from tools.lib.test_script import (
|
||||
assert_provisioning_status_ok,
|
||||
|
@ -461,6 +462,10 @@ def main() -> None:
|
|||
#
|
||||
# destroy_leaked_test_databases()
|
||||
|
||||
removed = remove_test_run_directories()
|
||||
if removed:
|
||||
print("Removed %s stale test run directories!" % (removed,))
|
||||
|
||||
# We'll have printed whether tests passed or failed above
|
||||
sys.exit(bool(failures))
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from importlib import import_module
|
|||
from io import StringIO
|
||||
import glob
|
||||
import time
|
||||
import shutil
|
||||
|
||||
from django.db import connections, DEFAULT_DB_ALIAS, ProgrammingError, \
|
||||
connection
|
||||
|
@ -296,3 +297,15 @@ def destroy_leaked_test_databases(expiry_time: int = 60 * 60) -> int:
|
|||
if p.returncode != 0:
|
||||
raise RuntimeError("Error cleaning up test databases!")
|
||||
return len(databases_to_drop)
|
||||
|
||||
def remove_test_run_directories(expiry_time: int = 60 * 60) -> int:
|
||||
removed = 0
|
||||
directories = glob.glob(os.path.join(UUID_VAR_DIR, "test-backend", "run_*"))
|
||||
for test_run in directories:
|
||||
if round(time.time()) - os.path.getmtime(test_run) > expiry_time:
|
||||
try:
|
||||
shutil.rmtree(test_run)
|
||||
removed += 1
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return removed
|
||||
|
|
Loading…
Reference in New Issue