Proper fix for test_run_scenario_exception_inside_test
We were getting non deterministic bugs in this method. But adding more time like here I1007436736bf9d42b98c8782a6141203c271aa75 is not a proper way. If we change order of check duration & running method we will be able to run it exactly one time, even if we set duration == 0. So it will raise exception => we will be able to check that is raised. Change-Id: I64964f8386a06f0a54e134d62a59e0955e3a8d75 Closes-bug: #1283372
This commit is contained in:
parent
e14240a969
commit
30b8b619b2
@ -79,10 +79,6 @@ class ContinuousScenarioRunner(runner.ScenarioRunner):
|
|||||||
results_queue = collections.deque([], maxlen=concurrent)
|
results_queue = collections.deque([], maxlen=concurrent)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if time.time() - start > duration * 60:
|
|
||||||
break
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = iter_result.next(timeout)
|
result = iter_result.next(timeout)
|
||||||
except multiprocessing.TimeoutError as e:
|
except multiprocessing.TimeoutError as e:
|
||||||
@ -90,6 +86,9 @@ class ContinuousScenarioRunner(runner.ScenarioRunner):
|
|||||||
"error": utils.format_exc(e)}
|
"error": utils.format_exc(e)}
|
||||||
results_queue.append(result)
|
results_queue.append(result)
|
||||||
|
|
||||||
|
if time.time() - start > duration * 60:
|
||||||
|
break
|
||||||
|
|
||||||
results = list(results_queue)
|
results = list(results_queue)
|
||||||
|
|
||||||
pool.terminate()
|
pool.terminate()
|
||||||
|
@ -116,17 +116,16 @@ class ScenarioRunnerTestCase(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch("rally.benchmark.runner.rutils")
|
@mock.patch("rally.benchmark.runner.rutils")
|
||||||
@mock.patch("rally.benchmark.utils.osclients")
|
@mock.patch("rally.benchmark.utils.osclients")
|
||||||
def test_run_scenario_exception_inside_test(self, mock_osclients,
|
def test_run_scenario_times_exception_inside_test(self, mock_osclients,
|
||||||
mock_utils):
|
mock_utils):
|
||||||
mock_osclients.Clients.return_value = fakes.FakeClients()
|
mock_osclients.Clients.return_value = fakes.FakeClients()
|
||||||
|
mock_utils.Timer = fakes.FakeTimer
|
||||||
srunner = continuous.ContinuousScenarioRunner(mock.MagicMock(),
|
srunner = continuous.ContinuousScenarioRunner(mock.MagicMock(),
|
||||||
self.fake_endpoints)
|
self.fake_endpoints)
|
||||||
srunner.users = _get_fake_users(5)
|
srunner.users = _get_fake_users(5)
|
||||||
times = 1
|
times = 1
|
||||||
duration = 1
|
|
||||||
active_users = 2
|
active_users = 2
|
||||||
|
|
||||||
mock_utils.Timer = fakes.FakeTimer
|
|
||||||
results = srunner._run_scenario(fakes.FakeScenario,
|
results = srunner._run_scenario(fakes.FakeScenario,
|
||||||
"something_went_wrong", {},
|
"something_went_wrong", {},
|
||||||
{"times": times, "timeout": 1,
|
{"times": times, "timeout": 1,
|
||||||
@ -137,12 +136,21 @@ class ScenarioRunnerTestCase(test.TestCase):
|
|||||||
self.assertEqual(r['error'][:2],
|
self.assertEqual(r['error'][:2],
|
||||||
[str(Exception), "Something went wrong"])
|
[str(Exception), "Something went wrong"])
|
||||||
|
|
||||||
|
@mock.patch("rally.benchmark.runner.rutils")
|
||||||
|
@mock.patch("rally.benchmark.utils.osclients")
|
||||||
|
def test_run_scenario_duration_exception_inside_test(self, mock_osclients,
|
||||||
|
mock_utils):
|
||||||
|
mock_osclients.Clients.return_value = fakes.FakeClients()
|
||||||
|
mock_utils.Timer = fakes.FakeTimer
|
||||||
|
srunner = continuous.ContinuousScenarioRunner(mock.MagicMock(),
|
||||||
|
self.fake_endpoints)
|
||||||
|
srunner.users = _get_fake_users(5)
|
||||||
|
active_users = 2
|
||||||
results = srunner._run_scenario(fakes.FakeScenario,
|
results = srunner._run_scenario(fakes.FakeScenario,
|
||||||
"something_went_wrong", {},
|
"something_went_wrong", {},
|
||||||
{"duration": duration,
|
{"duration": 0,
|
||||||
"timeout": 1,
|
"timeout": 1,
|
||||||
"active_users": active_users})
|
"active_users": active_users})
|
||||||
self.assertEqual(len(results), active_users)
|
|
||||||
for r in results:
|
for r in results:
|
||||||
self.assertEqual(r['time'], 10)
|
self.assertEqual(r['time'], 10)
|
||||||
self.assertEqual(r['error'][:2],
|
self.assertEqual(r['error'][:2],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user