示例#1
0
    def test_release_logs(self, uuid1):
        """
        When lock is released, it logs with time the lock was held
        """
        lock_uuid = 'lock_uuid'
        log = mock.MagicMock(spec=['msg'])
        clock = task.Clock()
        lock = BasicLock(self.client,
                         self.table_name,
                         lock_uuid,
                         max_retry=1,
                         retry_wait=3,
                         reactor=clock,
                         log=log)
        self.responses = [
            None,  # _write_lock
            [{
                'lockId': lock._lock_id,
                'claimId': lock._claim_id
            }],  # _read_lock
            None  # delete for release lock
        ]

        lock.acquire()
        clock.advance(34)
        lock.release()

        log.msg.assert_called_with('Released lock. Was held for 34.0 seconds',
                                   lock_held_time=34.0,
                                   lock_id=lock_uuid,
                                   claim_id='claim_uuid',
                                   result=None)
示例#2
0
    def test_release(self):
        lock_uuid = uuid.uuid1()

        lock = BasicLock(self.client, self.table_name, lock_uuid)
        expected = [
            'DELETE FROM lock WHERE "lockId"=:lockId AND "claimId"=:claimId;',
            {'lockId': lock_uuid, 'claimId': lock._claim_id}, 2]

        d = lock.release()

        self.assertFired(d)
        self.client.execute.assert_called_once_with(*expected)
示例#3
0
    def test_release_logs(self, uuid1):
        """
        When lock is released, it logs with time the lock was held
        """
        lock_uuid = 'lock_uuid'
        log = mock.MagicMock(spec=['msg'])
        clock = task.Clock()
        lock = BasicLock(self.client, self.table_name, lock_uuid, max_retry=1,
                         retry_wait=3, reactor=clock, log=log)
        self.responses = [
            None,   # _write_lock
            [{'lockId': lock._lock_id, 'claimId': lock._claim_id}],  # _read_lock
            None   # delete for release lock
        ]

        lock.acquire()
        clock.advance(34)
        lock.release()

        log.msg.assert_called_with('Released lock. Was held for 34.0 seconds',
                                   lock_held_time=34.0, lock_id=lock_uuid,
                                   claim_id='claim_uuid', result=None)
示例#4
0
    def test_release(self):
        lock_uuid = uuid.uuid1()

        lock = BasicLock(self.client, self.table_name, lock_uuid)
        expected = [
            'DELETE FROM lock WHERE "lockId"=:lockId AND "claimId"=:claimId;',
            {
                'lockId': lock_uuid,
                'claimId': lock._claim_id
            }, 2
        ]

        d = lock.release()

        self.assertFired(d)
        self.client.execute.assert_called_once_with(*expected)