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:
Boris Pavlovic 2014-03-01 06:02:35 +04:00
parent e14240a969
commit 30b8b619b2
2 changed files with 17 additions and 10 deletions

View File

@ -79,10 +79,6 @@ class ContinuousScenarioRunner(runner.ScenarioRunner):
results_queue = collections.deque([], maxlen=concurrent)
while True:
if time.time() - start > duration * 60:
break
try:
result = iter_result.next(timeout)
except multiprocessing.TimeoutError as e:
@ -90,6 +86,9 @@ class ContinuousScenarioRunner(runner.ScenarioRunner):
"error": utils.format_exc(e)}
results_queue.append(result)
if time.time() - start > duration * 60:
break
results = list(results_queue)
pool.terminate()

View File

@ -116,17 +116,16 @@ class ScenarioRunnerTestCase(test.TestCase):
@mock.patch("rally.benchmark.runner.rutils")
@mock.patch("rally.benchmark.utils.osclients")
def test_run_scenario_exception_inside_test(self, mock_osclients,
mock_utils):
def test_run_scenario_times_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)
times = 1
duration = 1
active_users = 2
mock_utils.Timer = fakes.FakeTimer
results = srunner._run_scenario(fakes.FakeScenario,
"something_went_wrong", {},
{"times": times, "timeout": 1,
@ -137,12 +136,21 @@ class ScenarioRunnerTestCase(test.TestCase):
self.assertEqual(r['error'][:2],
[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,
"something_went_wrong", {},
{"duration": duration,
{"duration": 0,
"timeout": 1,
"active_users": active_users})
self.assertEqual(len(results), active_users)
for r in results:
self.assertEqual(r['time'], 10)
self.assertEqual(r['error'][:2],