-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed test dependency on inotify-tools (inotifywait)
and related tweaks to improve test reliability across systems
- Loading branch information
Showing
5 changed files
with
115 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
import pytest | ||
|
||
from .fixture import SchedulerFixture | ||
from .fixture import ( | ||
LockingTaskFixture, | ||
SchedulerFixture, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def schedpatch(confpatch): | ||
return SchedulerFixture(confpatch.conf, confpatch.logger) | ||
|
||
|
||
@pytest.fixture | ||
def locking_task(tmp_path): | ||
lock = LockingTaskFixture(tmp_path) | ||
|
||
lock.acquire() | ||
|
||
try: | ||
yield lock | ||
finally: | ||
if lock.locked: | ||
lock.release() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .sched import SchedulerFixture # noqa: F401 | ||
from .task import LockingTaskFixture # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import fcntl | ||
import textwrap | ||
|
||
from descriptors import cachedproperty | ||
|
||
|
||
class LockingTaskFixture: | ||
|
||
def __init__(self, basedir, path='opt/done.lock', result='done\n'): | ||
self.lock_path = basedir / path | ||
self.result = result | ||
self.locked = False | ||
|
||
@property | ||
def conf(self): | ||
return { | ||
'shell': { | ||
'executable': 'python', | ||
'script': textwrap.dedent( | ||
'''\ | ||
import fcntl, json, sys | ||
param = json.load(sys.stdin) | ||
with open(param['lock_path'], 'w') as fd: | ||
fcntl.flock(fd, fcntl.LOCK_EX) | ||
print(param['result'], end='') | ||
fcntl.flock(fd, fcntl.LOCK_UN) | ||
''' | ||
), | ||
}, | ||
'param': { | ||
'lock_path': str(self.lock_path), | ||
'result': self.result, | ||
}, | ||
} | ||
|
||
@cachedproperty | ||
def lock_fd(self): | ||
self.lock_path.parent.mkdir() | ||
return self.lock_path.open('w') | ||
|
||
def acquire(self): | ||
fcntl.flock(self.lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) | ||
self.locked = True | ||
|
||
def release(self): | ||
fcntl.flock(self.lock_fd, fcntl.LOCK_UN) | ||
self.lock_fd.close() | ||
self.locked = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters