diff --git a/rally/verification/tempest/diff.py b/rally/verification/tempest/diff.py index da4d73f7e1..65c626d2de 100644 --- a/rally/verification/tempest/diff.py +++ b/rally/verification/tempest/diff.py @@ -69,15 +69,19 @@ class Diff(object): return diffs def _diff_values(self, name, result1, result2): - th = self.threshold fields = ["status", "time", "output"] diffs = [] for field in fields: val1 = result1[field] val2 = result2[field] - if val1 != val2 and not (field == "time" - and abs(((val2 - val1) / val1) * 100) - < th): + if val1 != val2: + if field == "time": + max_ = max(val1, val2) + min_ = min(val1, val2) + time_threshold = ((max_ - min_) / (min_ or 1)) * 100 + if time_threshold < self.threshold: + continue + diffs.append({ "field": field, "type": "value_changed", diff --git a/tests/unit/verification/test_diff.py b/tests/unit/verification/test_diff.py index 5ba20a3bbf..446018b78b 100644 --- a/tests/unit/verification/test_diff.py +++ b/tests/unit/verification/test_diff.py @@ -9,6 +9,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + from rally.verification.tempest import diff from tests.unit import test @@ -87,3 +88,20 @@ class DiffTestCase(test.TestCase): assert diff_.to_csv() != "" assert diff_.to_html() != "" assert diff_.to_json() != "" + + def test_zero_values(self): + results1 = {"test.one": {"name": "test.one", + "output": "test.one", + "status": "OK", + "time": 1}} + + results2 = {"test.one": {"name": "test.one", + "output": "test.one", + "status": "FAIL", + "time": 0}} + + # This must NOT raise ZeroDivisionError + diff_ = diff.Diff(results1, results2, 0) + self.assertEqual(2, len(diff_.diffs)) + diff_ = diff.Diff(results2, results1, 0) + self.assertEqual(2, len(diff_.diffs))