Marc Koderer | ba6206d | 2013-10-11 08:04:10 +0200 | [diff] [blame] | 1 | # Copyright 2013 Deutsche Telekom AG |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | import tempest.stress.stressaction as stressaction |
| 17 | import tempest.test |
| 18 | |
| 19 | |
| 20 | class FakeStressAction(stressaction.StressAction): |
| 21 | def __init__(self, manager, max_runs=None, stop_on_error=False): |
| 22 | super(self.__class__, self).__init__(manager, max_runs, stop_on_error) |
| 23 | self._run_called = False |
| 24 | |
| 25 | def run(self): |
| 26 | self._run_called = True |
| 27 | |
| 28 | @property |
| 29 | def run_called(self): |
| 30 | return self._run_called |
| 31 | |
| 32 | |
| 33 | class FakeStressActionFailing(stressaction.StressAction): |
| 34 | def run(self): |
| 35 | raise Exception('FakeStressActionFailing raise exception') |
| 36 | |
| 37 | |
| 38 | class TestStressAction(tempest.test.BaseTestCase): |
| 39 | def _bulid_stats_dict(self, runs=0, fails=0): |
| 40 | return {'runs': runs, 'fails': fails} |
| 41 | |
| 42 | def testStressTestRun(self): |
| 43 | stressAction = FakeStressAction(manager=None, max_runs=1) |
| 44 | stats = self._bulid_stats_dict() |
| 45 | stressAction.execute(stats) |
| 46 | self.assertTrue(stressAction.run_called) |
| 47 | self.assertEqual(stats['runs'], 1) |
| 48 | self.assertEqual(stats['fails'], 0) |
| 49 | |
| 50 | def testStressMaxTestRuns(self): |
| 51 | stressAction = FakeStressAction(manager=None, max_runs=500) |
| 52 | stats = self._bulid_stats_dict(runs=499) |
| 53 | stressAction.execute(stats) |
| 54 | self.assertTrue(stressAction.run_called) |
| 55 | self.assertEqual(stats['runs'], 500) |
| 56 | self.assertEqual(stats['fails'], 0) |
| 57 | |
| 58 | def testStressTestRunWithException(self): |
| 59 | stressAction = FakeStressActionFailing(manager=None, max_runs=1) |
| 60 | stats = self._bulid_stats_dict() |
| 61 | stressAction.execute(stats) |
| 62 | self.assertEqual(stats['runs'], 1) |
| 63 | self.assertEqual(stats['fails'], 1) |