Skip to content

Commit

Permalink
unique working dir for python system_tests (#32601)
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman authored and chrisberkhout committed Jun 1, 2023
1 parent 9f5aa92 commit ceaaca2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import subprocess

import random
import unittest
import os
import shutil
Expand Down Expand Up @@ -396,7 +396,7 @@ def setUp(self):

# create working dir
self.working_dir = os.path.abspath(os.path.join(
self.build_path + "run", self.id()))
self.build_path, "run", self.id() + str(random.randrange(1000))))
if os.path.exists(self.working_dir):
shutil.rmtree(self.working_dir)
os.makedirs(self.working_dir)
Expand All @@ -411,13 +411,25 @@ def setUp(self):
# update the last_run link
if os.path.islink(self.build_path + "last_run"):
os.unlink(self.build_path + "last_run")
os.symlink(self.build_path + f"run/{self.id()}",
os.symlink(self.working_dir,
self.build_path + "last_run")
except BaseException:
# symlink is best effort and can fail when
# running tests in parallel
pass

# Keep last 5 runs
candidates = []
to_keep = 5
for dir_entry in os.listdir(os.path.join(self.build_path, "run")):
if re.search(self.id() + r"[0-9]+$", dir_entry):
candidates.append(dir_entry)
if len(candidates) > to_keep:
candidates.sort(reverse=True, key=lambda dirname: os.path.getmtime(
os.path.join(self.build_path, "run", dirname)))
for d in candidates[to_keep:]:
shutil.rmtree(os.path.join(self.build_path, "run", d))

def wait_until(self, cond, max_timeout=20, poll_interval=0.1, name="cond", err_msg=""):
"""
TODO: this can probably be a "wait_until_output_count", among other things, since that could actually use `self`, and this can become an internal function
Expand Down

0 comments on commit ceaaca2

Please sign in to comment.