def test_nested_acquire(self): q = zmq._QueueLock() self.assertFalse(q) q.acquire() q.acquire() s = semaphore.Semaphore(0) results = [] def lock(x): with q: results.append(x) s.release() spawn(lock, 1) sleep() self.assertEquals(results, []) q.release() sleep() self.assertEquals(results, []) self.assertTrue(q) q.release() s.acquire() self.assertEquals(results, [1])
def test_queue_lock_order(self): q = zmq._QueueLock() s = semaphore.Semaphore(0) results = [] def lock(x): with q: results.append(x) s.release() q.acquire() spawn(lock, 1) sleep() spawn(lock, 2) sleep() spawn(lock, 3) sleep() self.assertEquals(results, []) q.release() s.acquire() s.acquire() s.acquire() self.assertEquals(results, [1, 2, 3])
def test_nested_acquire (self): q = zmq._QueueLock() self.assertFalse(q) q.acquire() q.acquire() s = semaphore.Semaphore(0) results = [] def lock (x): with q: results.append(x) s.release() spawn(lock, 1) sleep() self.assertEquals(results, []) q.release() sleep() self.assertEquals(results, []) self.assertTrue(q) q.release() s.acquire() self.assertEquals(results, [1])
def test_queue_lock_order (self): q = zmq._QueueLock() s = semaphore.Semaphore(0) results = [] def lock (x): with q: results.append(x) s.release() q.acquire() spawn(lock, 1) sleep() spawn(lock, 2) sleep() spawn(lock, 3) sleep() self.assertEquals(results, []) q.release() s.acquire() s.acquire() s.acquire() self.assertEquals(results, [1, 2, 3])
def test_errors(self): q = zmq._QueueLock() with self.assertRaises(Exception): q.release() q.acquire() q.release() with self.assertRaises(Exception): q.release()
def test_count(self): q = zmq._QueueLock() self.assertFalse(q) q.acquire() self.assertTrue(q) q.release() self.assertFalse(q) with q: self.assertTrue(q) self.assertFalse(q)
def test_errors (self): q = zmq._QueueLock() with self.assertRaises(Exception): q.release() q.acquire() q.release() with self.assertRaises(Exception): q.release()
def test_count (self): q = zmq._QueueLock() self.assertFalse(q) q.acquire() self.assertTrue(q) q.release() self.assertFalse(q) with q: self.assertTrue(q) self.assertFalse(q)