ensure timestamps are different in tests

This commit is contained in:
Gregory 2023-04-04 17:57:50 -07:00
parent c20a4d6ad1
commit f1c831cf6e
2 changed files with 7 additions and 1 deletions

View File

@ -8,6 +8,7 @@
import os
import shutil
import sys
import time
from argparse import Namespace
import pytest
@ -3368,7 +3369,9 @@ def test_view_update_unnecessary(update_method, tmpdir, install_mockery, mock_fe
install("libdwarf")
# Create a "previous" view
# Wait after each view regeneration to ensure timestamps are different
view.regenerate([libelf])
time.sleep(1)
# monkeypatch so that any attempt to actually regenerate the view fails
def raises(*args, **kwargs):
@ -3380,12 +3383,14 @@ def raises(*args, **kwargs):
# regenerating the view is a no-op, so doesn't raise
# will raise if the view isn't identical
view.regenerate([libelf])
time.sleep(1)
with pytest.raises(AssertionError):
view.regenerate([libelf, libdwarf])
# Create another view so there are multiple old views around
monkeypatch.setattr(view, "view", old_view)
view.regenerate([libelf, libdwarf])
time.sleep(1)
# Redo the monkeypatch
monkeypatch.setattr(view, "view", raises)
@ -3393,5 +3398,6 @@ def raises(*args, **kwargs):
# no raise for no-op regeneration
# raise when it's not a no-op
view.regenerate([libelf, libdwarf])
time.sleep(1)
with pytest.raises(AssertionError):
view.regenerate([libelf])

View File

@ -56,7 +56,7 @@ def atomic_update_renameat2(src, dest):
raise OSError(f"renameat2 failed to exchange {src} and {dest}")
except OSError:
if not dest_exists:
os.unlink(dest)
os.rmdir(dest)
raise