Skip to content

Commit c3cd0de

Browse files
miss-islingtoncorona10
authored andcommitted
bpo-22367: Update test_fcntl.py for spawn process mode (GH-17154) (GH-17252)
(cherry picked from commit 9960230) Co-authored-by: Dong-hee Na <[email protected]>
1 parent 84c36c1 commit c3cd0de

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Lib/test/test_fcntl.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ def __init__(self, fn):
5151
def fileno(self):
5252
return self.fn
5353

54+
def try_lockf_on_other_process_fail(fname, cmd):
55+
f = open(fname, 'wb+')
56+
try:
57+
fcntl.lockf(f, cmd)
58+
except BlockingIOError:
59+
pass
60+
finally:
61+
f.close()
62+
63+
def try_lockf_on_other_process(fname, cmd):
64+
f = open(fname, 'wb+')
65+
fcntl.lockf(f, cmd)
66+
fcntl.lockf(f, fcntl.LOCK_UN)
67+
f.close()
68+
5469
class TestFcntl(unittest.TestCase):
5570

5671
def setUp(self):
@@ -138,28 +153,23 @@ def test_flock(self):
138153
self.assertRaises(ValueError, fcntl.flock, -1, fcntl.LOCK_SH)
139154
self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH)
140155

156+
@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
141157
def test_lockf_exclusive(self):
142158
self.f = open(TESTFN, 'wb+')
143159
cmd = fcntl.LOCK_EX | fcntl.LOCK_NB
144-
def try_lockf_on_other_process():
145-
self.assertRaises(BlockingIOError, fcntl.lockf, self.f, cmd)
146-
147160
fcntl.lockf(self.f, cmd)
148-
p = Process(target=try_lockf_on_other_process)
161+
p = Process(target=try_lockf_on_other_process_fail, args=(TESTFN, cmd))
149162
p.start()
150163
p.join()
151164
fcntl.lockf(self.f, fcntl.LOCK_UN)
152165
self.assertEqual(p.exitcode, 0)
153166

167+
@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
154168
def test_lockf_share(self):
155169
self.f = open(TESTFN, 'wb+')
156170
cmd = fcntl.LOCK_SH | fcntl.LOCK_NB
157-
def try_lockf_on_other_process():
158-
fcntl.lockf(self.f, cmd)
159-
fcntl.lockf(self.f, fcntl.LOCK_UN)
160-
161171
fcntl.lockf(self.f, cmd)
162-
p = Process(target=try_lockf_on_other_process)
172+
p = Process(target=try_lockf_on_other_process, args=(TESTFN, cmd))
163173
p.start()
164174
p.join()
165175
fcntl.lockf(self.f, fcntl.LOCK_UN)

0 commit comments

Comments
 (0)