Exemple #1
0
 def test_dummy_timed_atomic_actions(self, mock_interruptable_sleep,
                                     number_of_actions, sleep_factor):
     dummy.DummyRandomAction(test.get_test_context()).run(
         number_of_actions, sleep_factor)
     scenario = dummy.DummyTimedAtomicAction(test.get_test_context())
     scenario.run(number_of_actions, sleep_factor)
     for i in range(number_of_actions):
         self._test_atomic_action_timer(scenario.atomic_actions(),
                                        "action_%d" % i)
         mock_interruptable_sleep.assert_any_call(i * sleep_factor)
Exemple #2
0
    def test_dummy_random_action(self, mock_interruptable_sleep, mock_random,
                                 **kwargs):
        mock_random.uniform.side_effect = range(100)

        scenario = dummy.DummyRandomAction(test.get_test_context())
        scenario.run(**kwargs)
        actions_num = kwargs.get("actions_num", 5)
        calls = [mock.call(i) for i in range(actions_num)]
        self.assertEqual(calls, mock_interruptable_sleep.mock_calls)

        calls = [
            mock.call(kwargs.get("sleep_min", 0), kwargs.get("sleep_max", 2))
            for i in range(actions_num)
        ]
        self.assertEqual(calls, mock_random.uniform.mock_calls)
        for i in range(actions_num):
            self._test_atomic_action_timer(scenario.atomic_actions(),
                                           "action_%d" % i)