Skip to content

Commit

Permalink
[Fix] Fix issues in verification.tempest.diff
Browse files Browse the repository at this point in the history
Changes in rally.verification.tempest.diff._diff_values:
 * fix ZeroDivisionError
 * fix time threshold calculation

This patch also adds unit test

Change-Id: Ib52d89397ab491d2bc6c40197cb8222fc35cadd7
  • Loading branch information
Alexander Maretskiy committed Jun 2, 2015
1 parent 42f29a7 commit 02229ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rally/verification/tempest/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ def _compare(self, tc1, tc2):
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",
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/verification/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -87,3 +88,20 @@ def test_main(self):
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))

0 comments on commit 02229ad

Please sign in to comment.