[Fix] Fix issues in verification.tempest.diff
Changes in rally.verification.tempest.diff._diff_values: * fix ZeroDivisionError * fix time threshold calculation This patch also adds unit test Change-Id: Ib52d89397ab491d2bc6c40197cb8222fc35cadd7
This commit is contained in:
parent
42f29a72e1
commit
02229ada85
@ -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",
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user