MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_lock_conflict

Method test_lock_conflict

Lib/test/test_mailbox.py:1217–1250  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1215 @support.requires_fork()
1216 @unittest.skipUnless(hasattr(socket, 'socketpair'), "Test needs socketpair().")
1217 def test_lock_conflict(self):
1218 # Fork off a child process that will lock the mailbox temporarily,
1219 # unlock it and exit.
1220 c, p = socket.socketpair()
1221 self.addCleanup(c.close)
1222 self.addCleanup(p.close)
1223
1224 pid = os.fork()
1225 if pid == 0:
1226 # child
1227 try:
1228 # lock the mailbox, and signal the parent it can proceed
1229 self._box.lock()
1230 c.send(b'c')
1231
1232 # wait until the parent is done, and unlock the mailbox
1233 c.recv(1)
1234 self._box.unlock()
1235 finally:
1236 os._exit(0)
1237
1238 # In the parent, wait until the child signals it locked the mailbox.
1239 p.recv(1)
1240 try:
1241 self.assertRaises(mailbox.ExternalClashError,
1242 self._box.lock)
1243 finally:
1244 # Signal the child it can now release the lock and exit.
1245 p.send(b'p')
1246 # Wait for child to exit. Locking should now succeed.
1247 support.wait_process(pid, exitcode=0)
1248
1249 self._box.lock()
1250 self._box.unlock()
1251
1252 def test_relock(self):
1253 # Test case for bug #1575506: the mailbox class was locking the

Callers

nothing calls this directly

Calls 8

addCleanupMethod · 0.80
socketpairMethod · 0.45
lockMethod · 0.45
sendMethod · 0.45
recvMethod · 0.45
unlockMethod · 0.45
_exitMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected