From 480b0712ddca4eb3e15871759269a5acb27510e0 Mon Sep 17 00:00:00 2001
From: Athanasius <github@miggy.org>
Date: Wed, 7 Sep 2022 12:21:57 +0100
Subject: [PATCH] tests: journal_lock: Close filehandle in
 `test_obtain_lock_already_locked()`

After the test completes as expected (ALREADY_LOCKED), ensure we close the
filehandle for that, else it seems to interfere with the sub-process
cleanup, which then leads to subsequent tests not being able to cleanup.

Tests as now working after 10s of runs of `pytest` in a loop.
---
 tests/journal_lock.py/test_journal_lock.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py
index 6d93d54a..7afa588c 100644
--- a/tests/journal_lock.py/test_journal_lock.py
+++ b/tests/journal_lock.py/test_journal_lock.py
@@ -70,6 +70,7 @@ def other_process_lock(continue_q: mp.Queue, exit_q: mp.Queue, lockfile: pathlib
         exit_q.get(block=True, timeout=None)
 
         # And clean up
+        _release_lock('sub-process', lf)
         os.unlink(lockfile / 'edmc-journal-lock.txt')
 
 
@@ -329,6 +330,8 @@ class TestJournalLock:
         # Fails on Linux, because flock(2) is per process, so we'd need to
         # use multiprocessing to test this.
         assert second_attempt == JournalLockResult.ALREADY_LOCKED
+        # And need to release any handles on the lockfile
+        jlock.journal_dir_lockfile.close()
         print('Telling sub-process to quit...')
         exit_q.put('quit')
         print('Waiting for sub-process...')