Skip to content

Commit

Permalink
s3/test: nuke tempdir but keep $tempdir/log
Browse files Browse the repository at this point in the history
before this change, if the object_store test fails, the tempdir
will be preserved. and if our CI test pipeline is used to perform
the test, the test job would scan for the artifacts, and if the
test in question fails, it would take over 1 hour to scan the tempdir.

to alleviate the pain, let's just keep the scylla logging file
no matter the test fails or succeeds. so that jenkins can scan the
artifacts faster if the test fails.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes #14880
  • Loading branch information
tchaikov authored and xemul committed Aug 3, 2023
1 parent cb3b808 commit d4ee84e
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions test/object_store/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,29 @@ def ssl(request):
yield request.config.getoption('--ssl')


@contextmanager
def _maybe_remove_tempdir_on_complete(request, tempdir):
if pytest.version_tuple > (7, 3, 0):
yield
def _remove_all_but(tempdir, to_preserve):
orig_fn = os.path.join(tempdir, to_preserve)
# orig_fn does not exist
if not os.path.exists(orig_fn):
# it's fine if tempdir does not exist
shutil.rmtree(tempdir=True)
return
# tmp_path_retention_count was introduced in pytest 7.3.0, so we have
# to swing this by ourselves when using lower version of pytest. see
# https://docs.pytest.org/en/7.3.x/changelog.html#pytest-7-3-0-2023-04-08
tests_failed = request.session.testsfailed
yield
if tests_failed == request.session.testsfailed:
# not tests failed after this seesion, so remove the tempdir

with tempfile.TemporaryDirectory() as backup_tempdir:
backup_fn = os.path.join(backup_tempdir, to_preserve)
shutil.move(orig_fn, backup_fn)
shutil.rmtree(tempdir)
os.mkdir(tempdir)
shutil.move(backup_fn, orig_fn)


@pytest.fixture(scope="function")
def test_tempdir(request, tmpdir):
def test_tempdir(tmpdir):
tempdir = tmpdir.strpath
with _maybe_remove_tempdir_on_complete(request, tempdir):
try:
yield tempdir
with open(os.path.join(tempdir, 'log'), 'rb') as log:
shutil.copyfileobj(log, sys.stdout.buffer)
finally:
_remove_all_but(tempdir, 'log')


@pytest.fixture(scope="function")
Expand Down

0 comments on commit d4ee84e

Please sign in to comment.