Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
        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))
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 def _lock():
     with lockutils.lock('test', blocking=3):
         self.assertTrue(False)
Exemplo n.º 6
0
    def test_lock(self):
        locked = False
        with lockutils.lock('test'):
            locked = True

        self.assertTrue(locked)