mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Add a test for a conflicting lock.
On slow machines, maybe the time intervals (2 sec, 0.5 sec) will be too tight. I'll see how the buildbots like it.
This commit is contained in:
		
							parent
							
								
									557325930c
								
							
						
					
					
						commit
						9afbacef27
					
				
					 1 changed files with 22 additions and 0 deletions
				
			
		| 
						 | 
					@ -720,6 +720,28 @@ def test_add_and_close(self):
 | 
				
			||||||
        self.assert_(contents == open(self._path, 'rb').read())
 | 
					        self.assert_(contents == open(self._path, 'rb').read())
 | 
				
			||||||
        self._box = self._factory(self._path)
 | 
					        self._box = self._factory(self._path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_lock_conflict(self):
 | 
				
			||||||
 | 
					        # Fork off a subprocess that will lock the file for 2 seconds,
 | 
				
			||||||
 | 
					        # unlock it, and then exit.
 | 
				
			||||||
 | 
					        pid = os.fork()
 | 
				
			||||||
 | 
					        if pid == 0:
 | 
				
			||||||
 | 
					            # In the child, lock the mailbox.
 | 
				
			||||||
 | 
					            self._box.lock()
 | 
				
			||||||
 | 
					            time.sleep(2)
 | 
				
			||||||
 | 
					            self._box.unlock()
 | 
				
			||||||
 | 
					            os._exit(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # In the parent, sleep a bit to give the child time to acquire
 | 
				
			||||||
 | 
					        # the lock.
 | 
				
			||||||
 | 
					        time.sleep(0.5)
 | 
				
			||||||
 | 
					        self.assertRaises(mailbox.ExternalClashError,
 | 
				
			||||||
 | 
					                          self._box.lock)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        # Wait for child to exit.  Locking should now succeed.
 | 
				
			||||||
 | 
					        pid, status = os.wait()
 | 
				
			||||||
 | 
					        self._box.lock()
 | 
				
			||||||
 | 
					        self._box.unlock()
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestMbox(_TestMboxMMDF):
 | 
					class TestMbox(_TestMboxMMDF):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue