Skip to content

Commit

Permalink
Update test_xdr.py
Browse files Browse the repository at this point in the history
adjusting file lock checking pytest
  • Loading branch information
talagayev authored Jan 8, 2025
1 parent 47bfb7c commit c271f6b
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,32 +1031,12 @@ def test_offset_lock_created(self):
lock_file_path = XDR.offsets_filename(self.filename, ending='lock')
lock = FileLock(lock_file_path)

# Start a count to release lock after 5 seconds
def release_lock_after_delay():
time.sleep(5)
lock.release()

# Acquire the lock
lock.acquire()
try:
# Start count
release_lock_after_delay()

# Start timing to ensure the reader waits for the lock
start_time = time.time()

with pytest.warns(UserWarning):
self._reader(self.filename)

elapsed_time = time.time() - start_time

# Ensure the function waited for the lock
assert elapsed_time >= 5, "read_offsets did not wait for the lock to be released."

finally:
# Ensure the lock is released to avoid hanging
if lock.is_locked:
lock.release()
time.sleep(5) # wait 5 seconds before checking if the file is locked
assert lock.is_locked # check if file is locked
lock.release()
assert not lock.is_locked # check if file is unlocked


class TestXTCReader_offsets(_GromacsReader_offsets):
Expand Down

0 comments on commit c271f6b

Please sign in to comment.