How to use call_until_true method in tempest

Best Python code snippet using tempest_python

test_test_utils.py

Source:test_test_utils.py Github

copy

Full Screen

...68class TestCallUntilTrue(base.TestCase):69 def test_call_until_true_when_true_at_first_call(self):70 """func returns True at first call71 """72 self._test_call_until_true(return_values=[True],73 duration=30.,74 time_sequence=[10., 60.])75 def test_call_until_true_when_true_before_timeout(self):76 """func returns false at first call, then True before timeout77 """78 self._test_call_until_true(return_values=[False, True],79 duration=30.,80 time_sequence=[10., 39., 41.])81 def test_call_until_true_when_never_true_before_timeout(self):82 """func returns false, then false, just before timeout83 """84 self._test_call_until_true(return_values=[False, False],85 duration=30.,86 time_sequence=[10., 39., 41.])87 def test_call_until_true_with_params(self):88 """func is called using given parameters89 """90 self._test_call_until_true(return_values=[False, True],91 duration=30.,92 time_sequence=[10., 30., 60.],93 args=(1, 2),94 kwargs=dict(foo='bar', bar='foo'))95 def _test_call_until_true(self, return_values, duration, time_sequence,96 args=None, kwargs=None):97 """Test call_until_true function98 :param return_values: list of booleans values to be returned99 each time given function is called. If any of these values100 is not consumed by calling the function the test fails.101 The list must contain a sequence of False items terminated102 by a single True or False103 :param duration: parameter passed to call_until_true function104 (a floating point value).105 :param time_sequence: sequence of time values returned by106 mocked time.time function used to trigger call_until_true107 behavior when handling timeout condition. The sequence must108 contain the exact number of values expected to be consumed by109 each time call_until_true calls time.time function.110 :param args: sequence of positional arguments to be passed111 to call_until_true function.112 :param kwargs: sequence of named arguments to be passed113 to call_until_true function.114 """115 # all values except the last are False116 self.assertEqual([False] * len(return_values[:-1]), return_values[:-1])117 # last value can be True or False118 self.assertIn(return_values[-1], [True, False])119 # GIVEN120 func = mock.Mock(side_effect=return_values)121 sleep = 10. # this value has no effect as time.sleep is being mocked122 sleep_func = self.patch('time.sleep')123 time_func = self._patch_time(time_sequence)124 args = args or tuple()125 kwargs = kwargs or dict()126 # WHEN127 result = test_utils.call_until_true(func, duration, sleep,128 *args, **kwargs)129 # THEN130 # It must return last returned value131 self.assertIs(return_values[-1], result)132 self._test_func_calls(func, return_values, *args, **kwargs)133 self._test_sleep_calls(sleep_func, return_values, sleep)134 # The number of times time.time is called is not relevant as a135 # requirement of call_until_true. What is instead relevant is that136 # call_until_true use a mocked function to make the test reliable137 # and the test actually provide the right sequence of numbers to138 # reproduce the behavior has to be tested139 self._assert_called_n_times(time_func, len(time_sequence))140 def _patch_time(self, time_sequence):141 # Iterator over time sequence...

Full Screen

Full Screen

wait-for-controller.py

Source:wait-for-controller.py Github

copy

Full Screen

...9 timeout=bash_timout_sec10 ).strip()11 print(f'Response from broker: {output}')12 return 'OK' in output13healthy = call_until_true(14 name=service_name,15 sleep_time_sec=sleep_time_sec,16 max_calls=max_calls,17 func=func,18)19exit_wait_for_healthy(20 service_name=service_name,21 healthy=healthy,...

Full Screen

Full Screen

wait-for-broker.py

Source:wait-for-broker.py Github

copy

Full Screen

...9 timeout=bash_timout_sec10 ).strip()11 print(f'Response from broker: {output}')12 return 'OK' in output13healthy = call_until_true(14 name=service_name,15 sleep_time_sec=sleep_time_sec,16 max_calls=max_calls,17 func=func,18)19exit_wait_for_healthy(20 service_name=service_name,21 healthy=healthy,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful