mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
tests: journal_lock: Works 100% on Linux, remove 'plan' docstring text
This commit is contained in:
parent
480b0712dd
commit
5a0e31436b
@ -1,33 +1,4 @@
|
|||||||
"""
|
"""Tests for journal_lock.py code."""
|
||||||
Tests for journal_lock.py code.
|
|
||||||
|
|
||||||
Tests:
|
|
||||||
- Is file actually locked after obtain_lock(). Problem: We opened the
|
|
||||||
file in a manner which means nothing else can open it. Also I assume
|
|
||||||
that the same process will either be allowed to lock it 'again' or
|
|
||||||
overwrite the lock.
|
|
||||||
|
|
||||||
Expected failures if:
|
|
||||||
|
|
||||||
1. Lock already held (elsewhere).
|
|
||||||
2. Can't open lock file 'w+'.
|
|
||||||
3. Path to lock file doesn't exist.
|
|
||||||
4. journaldir is None (default on Linux).
|
|
||||||
|
|
||||||
- Does release_lock() work? Easier to test, if it's worked....
|
|
||||||
1. return True if not locked.
|
|
||||||
2. return True if locked, but successful unlock.
|
|
||||||
3. return False otherwise.
|
|
||||||
|
|
||||||
- JournalLock.set_path_from_journaldir
|
|
||||||
1. When journaldir is None.
|
|
||||||
2. Succeeds otherwise?
|
|
||||||
|
|
||||||
- Can any string to pathlib.Path result in an invalid path for other
|
|
||||||
operations?
|
|
||||||
|
|
||||||
- Not sure about testing JournalAlreadyLocked class.
|
|
||||||
"""
|
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
@ -327,11 +298,13 @@ class TestJournalLock:
|
|||||||
# Now attempt to lock with to-test code
|
# Now attempt to lock with to-test code
|
||||||
jlock = JournalLock()
|
jlock = JournalLock()
|
||||||
second_attempt = jlock.obtain_lock()
|
second_attempt = jlock.obtain_lock()
|
||||||
# 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
|
assert second_attempt == JournalLockResult.ALREADY_LOCKED
|
||||||
# And need to release any handles on the lockfile
|
|
||||||
|
# Need to release any handles on the lockfile else the sub-process
|
||||||
|
# might not be able to clean up properly, and that will impact
|
||||||
|
# on later tests.
|
||||||
jlock.journal_dir_lockfile.close()
|
jlock.journal_dir_lockfile.close()
|
||||||
|
|
||||||
print('Telling sub-process to quit...')
|
print('Telling sub-process to quit...')
|
||||||
exit_q.put('quit')
|
exit_q.put('quit')
|
||||||
print('Waiting for sub-process...')
|
print('Waiting for sub-process...')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user