Exemple #1
0
    def test_context_manager_slow(self, mock_pid, mock_acquire, mock_release,
                                  mock_sleep, mock_time, mock_add_event,
                                  mock_get_holder):
        al = etcd.ActualLock('instance', None, 'auuid', op='Test case')
        al.log_ctx = mock.MagicMock()

        with al:
            mock_acquire.assert_has_calls([
                mock.call(),
                mock.call(),
                mock.call(),
                mock.call(),
                mock.call(),
                mock.call()
            ])
            mock_sleep.assert_has_calls(
                [mock.call(1),
                 mock.call(1),
                 mock.call(1),
                 mock.call(1)])

            mock_add_event.assert_has_calls([
                mock.call('instance', 'auuid', 'lock', 'acquire', None,
                          'Waiting for lock more than threshold'),
                mock.call('instance', 'auuid', 'lock', 'acquired', None,
                          'Waited 12 seconds for lock')
            ])
            mock_get_holder.assert_called_with()

        mock_release.assert_called_with()
Exemple #2
0
    def test_context_manager(self, mock_pid, mock_acquire, mock_release):
        al = etcd.ActualLock('instance', None, 'auuid', op='Test case')

        self.assertEqual('/sflocks/sf/instance/auuid', al.key)
        self.assertEqual('instance', al.objecttype)
        self.assertEqual('auuid', al.objectname)
        self.assertEqual(1000000000, al.timeout)
        self.assertEqual('Test case', al.operation)
        self.assertEqual(
            json.dumps({
                'node': 'thisnode',
                'pid': 42,
                'operation': 'Test case'
            }, indent=4, sort_keys=True), al._uuid)

        with al:
            mock_acquire.assert_called_with()

        mock_release.assert_called_with()
Exemple #3
0
    def test_context_manager_timeout(
            self, mock_pid, mock_acquire, mock_release, mock_sleep,
            mock_time, mock_add_event, mock_get_holder):
        al = etcd.ActualLock('instance', None, 'auuid', op='Test case',
                             timeout=4)
        al.log_ctx = mock.MagicMock()

        self.assertRaises(exceptions.LockException, al.__enter__)

        mock_acquire.assert_has_calls([mock.call(), mock.call()])
        mock_sleep.assert_has_calls([mock.call(1), mock.call(1)])

        mock_add_event.assert_has_calls(
            [mock.call('instance', 'auuid', 'lock', 'acquire', None,
                       'Waiting for lock more than threshold'),
             mock.call('instance', 'auuid', 'lock', 'failed', None,
                       'Failed to acquire lock after 6.00 seconds')])
        mock_get_holder.assert_called_with()

        mock_release.assert_not_called()