From 068dbbd790c059cd0b274bbb754239139baf1999 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 15 Nov 2019 02:17:40 +0900 Subject: [PATCH 1/2] bpo-22367: Update test_fcntl.py --- Lib/test/test_fcntl.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 9d1be28c6d3992..1ee69260806a58 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -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): @@ -141,11 +156,8 @@ def test_flock(self): 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) @@ -154,12 +166,8 @@ def try_lockf_on_other_process(): 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) From 4732ee51733356ce03df5ecf8bd6bdaa4ab70bf4 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 15 Nov 2019 23:22:26 +0900 Subject: [PATCH 2/2] bpo-22367: Skip if unittest is running on AIX --- Lib/test/test_fcntl.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 1ee69260806a58..9ab68c67241f46 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -153,6 +153,7 @@ 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 @@ -163,6 +164,7 @@ def test_lockf_exclusive(self): 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