Exemple #1
0
    def test_with_arguments(self):
        go('hello', world='world')
        Dummy().go('hello', world='world')

        metrics = self._query_backend()

        assert len([m for m in metrics if m.value['name'] == get_fqn(go)]) == 1
        assert len([m for m in metrics if m.value['name'] == get_fqn(Dummy().go)]) == 1
    def test_with_arguments(self):
        go('hello', world='world')
        Dummy().go('hello', world='world')

        metrics = list(self._query_backend(get_fqn(go)))
        self.assertEqual(len(metrics), 1)

        metrics = list(self._query_backend(get_fqn(Dummy().go)))
        self.assertEqual(len(metrics), 1)
    def test_with_arguments(self):
        go('hello', world='world')
        Dummy().go('hello', world='world')

        metrics = self._query_backend(go.fqn)
        self.assertEqual(metrics['hits']['total'], 1)

        metrics = self._query_backend(Dummy().go.fqn)
        self.assertEqual(metrics['hits']['total'], 1)
    def test_with_arguments(self):
        go("hello", world="world")
        Dummy().go("hello", world="world")

        metrics = self._query_backend(get_fqn(go))
        self.assertEqual(metrics["hits"]["total"], 1)

        metrics = self._query_backend(get_fqn(Dummy().go))
        self.assertEqual(metrics["hits"]["total"], 1)
Exemple #5
0
class TestExecutor:
    def test_initial_state(self, executor, volume_manager, machine_manager):
        assert executor.volume_manager == volume_manager
        assert executor.machine_manager == machine_manager
        assert executor.delay == 0

        assert executor._should_reset
        assert executor._volumes_to_process == []
        assert executor._watch_index is None

    @mark.parametrize('context', [{'timeout': 'a'}, {}])
    def test_initial_state_wrong_timeout(self, context, volume_manager,
                                         machine_manager, p_print):
        executor = Executor(volume_manager, machine_manager, context)

        assert executor.delay == 10
        assert p_print.called

    def test_timeout(self, executor, p_time_sleep):
        executor.timeout()

        p_time_sleep.assert_called_with(executor.delay)

    def test_reset(self, executor):
        executor._should_reset = False
        executor._watch_index = 1

        executor.reset()

        assert executor._should_reset
        assert executor._watch_index is None

    @mark.usefixtures('p_print')
    @mark.parametrize(
        'volume,next_state',
        [[
            Dummy(
                value={
                    'control': {
                        'parent_id': ''
                    },
                    'requested': {
                        'reserved_size': 1
                    },
                    'actual': {
                        'reserved_size': 1,
                        'random': 2
                    }
                }), 'error'
        ],
         [
             Dummy(
                 value={
                     'control': {
                         'parent_id': ''
                     },
                     'requested': {
                         'reserved_size': 1
                     },
                     'actual': {
                         'reserved_size': 1
                     }
                 }), 'ready'
         ],
         [
             Dummy(
                 value={
                     'control': {
                         'parent_id': ''
                     },
                     'requested': {
                         'reserved_size': 1
                     },
                     'actual': {
                         'reserved_size': 2
                     }
                 }), 'resizing'
         ], [Dummy(value={'control': {
             'parent_id': '1'
         }}), 'cloning']])
    def test_next_state(self, volume, next_state, executor):
        got_state = executor._next_state(volume)
        assert got_state == next_state

    def test_tick_with_reset(self, mocker, executor, p_executor_process,
                             p_volume_manager_all):
        directory = mocker.MagicMock(etcd_index=0)
        volume = mocker.MagicMock()
        p_volume_manager_all.return_value = (directory, [volume])

        executor.tick()

        p_executor_process.assert_called_with(volume)
        assert p_volume_manager_all.called
        assert executor._volumes_to_process == []
        assert executor._watch_index == 1

    def test_tick_with_reset_no_dir(self, mocker, executor, p_executor_process,
                                    p_volume_manager_all):
        volume = mocker.MagicMock()
        p_volume_manager_all.return_value = (None, [volume])

        executor.tick()

        p_executor_process.assert_called_with(volume)
        assert p_volume_manager_all.called
        assert executor._volumes_to_process == []
        assert executor._watch_index is None

    @mark.parametrize('initial_index', [None, 1])
    def test_tick_watch_initial_index(self, mocker, executor,
                                      p_executor_process, p_volume_manager_all,
                                      p_volume_manager_watch, initial_index):
        index = 2
        volume = mocker.MagicMock(modifiedIndex=2)
        p_volume_manager_all.return_value = (None, [])
        p_volume_manager_watch.return_value = volume

        executor._watch_index = initial_index
        executor.tick()

        p_executor_process.assert_called_with(volume)
        p_volume_manager_watch.assert_called_with(index=initial_index,
                                                  timeout=executor.delay)
        assert p_volume_manager_all.called
        assert executor._watch_index == index + 1

    def test_tick_watch_timeout(self, mocker, executor, p_executor_process,
                                p_volume_manager_all, p_volume_manager_watch):
        p_volume_manager_all.return_value = (None, [])
        p_volume_manager_watch.return_value = None
        executor.reset = mocker.MagicMock()

        executor.tick()

        p_volume_manager_watch.assert_called_with(index=None,
                                                  timeout=executor.delay)
        assert p_volume_manager_all.called
        assert executor.reset.called
        assert not p_executor_process.called

    @mark.parametrize('watch_action', ['expire', 'delete'])
    def test_tick_watch_deleting_expire_action(self, mocker, executor,
                                               p_executor_process,
                                               p_volume_manager_all,
                                               p_volume_manager_watch,
                                               watch_action):
        p_volume_manager_all.return_value = (None, [])
        p_volume_manager_watch.return_value = mocker.MagicMock(
            action=watch_action, modifiedIndex=1)

        executor.tick()

        p_volume_manager_watch.assert_called_with(index=None,
                                                  timeout=executor.delay)
        assert p_volume_manager_all.called
        assert not p_executor_process.called

    def test_process_not_in_state(self, mocker, executor):
        executor._process_NONE = mocker.MagicMock()

        executor._process(dummy_invalid_state_volume)

        assert not executor._process_NONE.called
 def test_fqn(self):
     self.assertEqual(fqn_test.fqn, 'tests.conftest.fqn_test')
     self.assertEqual(Dummy.fqn, 'tests.conftest.Dummy')
     self.assertEqual(Dummy().go.fqn, 'tests.conftest.Dummy.go')