Skip to content

bpo-22367: Update test_fcntl.py for spawn process mode #17154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions Lib/test/test_fcntl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ def __init__(self, fn):
def fileno(self):
return self.fn

def try_lockf_on_other_process_fail(fname, cmd):
f = open(fname, 'wb+')
try:
fcntl.lockf(f, cmd)
except BlockingIOError:
pass
finally:
f.close()

def try_lockf_on_other_process(fname, cmd):
f = open(fname, 'wb+')
fcntl.lockf(f, cmd)
fcntl.lockf(f, fcntl.LOCK_UN)
f.close()

class TestFcntl(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -138,28 +153,23 @@ def test_flock(self):
self.assertRaises(ValueError, fcntl.flock, -1, fcntl.LOCK_SH)
self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH)

@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
def test_lockf_exclusive(self):
self.f = open(TESTFN, 'wb+')
cmd = fcntl.LOCK_EX | fcntl.LOCK_NB
def try_lockf_on_other_process():
self.assertRaises(BlockingIOError, fcntl.lockf, self.f, cmd)

fcntl.lockf(self.f, cmd)
p = Process(target=try_lockf_on_other_process)
p = Process(target=try_lockf_on_other_process_fail, args=(TESTFN, cmd))
p.start()
p.join()
fcntl.lockf(self.f, fcntl.LOCK_UN)
self.assertEqual(p.exitcode, 0)

@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
def test_lockf_share(self):
self.f = open(TESTFN, 'wb+')
cmd = fcntl.LOCK_SH | fcntl.LOCK_NB
def try_lockf_on_other_process():
fcntl.lockf(self.f, cmd)
fcntl.lockf(self.f, fcntl.LOCK_UN)

fcntl.lockf(self.f, cmd)
p = Process(target=try_lockf_on_other_process)
p = Process(target=try_lockf_on_other_process, args=(TESTFN, cmd))
p.start()
p.join()
fcntl.lockf(self.f, fcntl.LOCK_UN)
Expand Down