def test_lock_acquire_non_blocking_failed(self): def _lock(): with lockutils.lock('test', blocking=False): self.assertTrue(False) with lockutils.lock('test'): self.assertRaises(n_exc.AcquireDistributedLockFailed, _lock)
def test_lock_block_timeout(self): def _lock(): with lockutils.lock('test', blocking=3): self.assertTrue(False) with lockutils.lock('test'): self.assertTrue(True) self.assertRaises(n_exc.AcquireDistributedLockFailed, _lock)
def _worker(): with lockutils.lock('test'): cli = EtcdClient('localhost', 2379, 'http') count = cli.get(FT_COUNT_KEY) count = int(count['node']['value']) reply = cli.put(FT_COUNT_KEY, data={"value": count + 1}) self.assertEqual(count + 1, int(reply['node']['value'])) thread = threading.currentThread() six.print_('%s count: %d' % (thread.name, count + 1))
def test_lock_heartbeat(self): CONF.set_override('timeout', 2, 'dist_lock') origin_heartbeat = etcd.EtcdLock.heartbeat with lockutils.lock('test') as lock: with mock.patch.object(etcd.EtcdLock, 'heartbeat') as heart_beat: def side_effect(): six.print_('lock heartbeat: %s' % lock._node) return origin_heartbeat(lock) heart_beat.side_effect = side_effect time.sleep(5) self.assertEqual(2, heart_beat.call_count)
def _lock(): with lockutils.lock('test', blocking=3): self.assertTrue(False)
def test_lock(self): locked = False with lockutils.lock('test'): locked = True self.assertTrue(locked)