def identify_related_changes(ts, regressions, fc): """Can we find a home for this change in some existing regression? """ for regression in regressions: regression_indicators = get_ris(ts, regression) for change in regression_indicators: regression_change = change.field_change if is_overlaping(regression_change, fc): confidence = 0 relation = ["Revision"] if regression_change.machine == fc.machine: confidence += 1 relation.append("Machine") if regression_change.test == fc.test: confidence += 1 relation.append("Test") if regression_change.field == fc.field: confidence += 1 relation.append("Field") if confidence >= 2: # Matching note("Found a match:" + str(regression) + " On " + ', '.join(relation)) ri = ts.RegressionIndicator(regression, fc) ts.add(ri) # Update the default title if needed. rebuild_title(ts, regression) return (True, regression) note("Could not find a partner, creating new Regression for change") new_reg = new_regression(ts, [fc.id]) return (False, new_reg)
def identify_related_changes(ts, fc): """Can we find a home for this change in some existing regression? If a match is found add a regression indicator adding this change to that regression, otherwise create a new regression for this change. Regression matching looks for regressions that happen in overlapping order ranges. Then looks for changes that are similar. """ regressions = ts.query(ts.Regression.id) \ .filter(or_(ts.Regression.state == RegressionState.DETECTED, ts.Regression.state == RegressionState.DETECTED_FIXED)) \ .all() for regression_packed in regressions: regression_id = regression_packed[0] regression_indicators = get_ris(ts, regression_id) print "RIs:", regression_indicators for change in regression_indicators: regression_change = change.field_change if is_overlaping(regression_change, fc): confidence = 0.0 confidence += percent_similar(regression_change.machine.name, fc.machine.name) confidence += percent_similar(regression_change.test.name, fc.test.name) if regression_change.field == fc.field: confidence += 1.0 if confidence >= 2.0: # Matching MSG = "Found a match: {} with score {}." regression = ts.query(ts.Regression).get(regression_id) note(MSG.format(str(regression), confidence)) ri = ts.RegressionIndicator(regression, fc) ts.add(ri) # Update the default title if needed. rebuild_title(ts, regression) ts.commit() return True, regression note("Could not find a partner, creating new Regression for change") new_reg = new_regression(ts, [fc.id]) return False, new_reg
def identify_related_changes(session, ts, fc): """Can we find a home for this change in some existing regression? If a match is found add a regression indicator adding this change to that regression, otherwise create a new regression for this change. Regression matching looks for regressions that happen in overlapping order ranges. Then looks for changes that are similar. """ active_indicators = session.query(ts.RegressionIndicator) \ .join(ts.Regression) \ .filter(or_(ts.Regression.state == RegressionState.DETECTED, ts.Regression.state == RegressionState.DETECTED_FIXED)) \ .options(joinedload(ts.RegressionIndicator.field_change)) \ .all() for change in active_indicators: regression_change = change.field_change if is_overlaping(regression_change, fc): confidence = 0.0 confidence += percent_similar(regression_change.machine.name, fc.machine.name) confidence += percent_similar(regression_change.test.name, fc.test.name) if regression_change.field_id == fc.field_id: confidence += 1.0 if confidence >= 2.0: # Matching MSG = "Found a match: {} with score {}." regression = session.query(ts.Regression) \ .get(change.regression_id) logger.info(MSG.format(str(regression), confidence)) ri = ts.RegressionIndicator(regression, fc) session.add(ri) # Update the default title if needed. rebuild_title(session, ts, regression) session.commit() return True, regression logger.info("Could not find a partner, creating new Regression for change") new_reg = new_regression(session, ts, [fc.id]) return False, new_reg
def test_change_grouping_criteria(self): ts_db = self.ts_db # Check simple overlap checks work. self.assertTrue(is_overlaping(self.field_change, self.field_change2), "Should be overlapping") self.assertFalse(is_overlaping(self.field_change, self.field_change3), "Should not be overlapping") # Check non-overlapping changes are always False. ret, reg = identify_related_changes(ts_db, self.field_change3) self.assertFalse(ret, "Ranges don't overlap, should not match") self.regressions.append(reg) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, self.field_change) self.assertTrue(ret, "Should Match.") field_change7 = ts_db.FieldChange(self.order1234, self.order1235, self.machine2, self.test2, self.a_field) ts_db.add(field_change7) ret, reg = identify_related_changes(ts_db, field_change7) self.assertNotEquals(self.regression, reg) self.assertFalse(ret, "No match with different machine and tests.") self.regressions.append(reg) field_change4 = ts_db.FieldChange(self.order1234, self.order1235, self.machine2, self.test, self.a_field) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, field_change4) self.assertTrue(ret, "Should Match with different machine.") field_change5 = ts_db.FieldChange(self.order1234, self.order1235, self.machine, self.test2, self.a_field) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, field_change5) self.assertTrue(ret, "Should Match with different tests.") field_change6 = ts_db.FieldChange(self.order1234, self.order1235, self.machine, self.test, self.a_field2) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, field_change6) self.assertTrue(ret, "Should Match with different fields.") ts_db.commit() r2 = rebuild_title(ts_db, self.regression) EXPECTED_TITLE = "Regression of 6 benchmarks: foo, bar" self.assertEquals(r2.title, EXPECTED_TITLE)
def test_change_grouping_criteria(self): session = self.session ts_db = self.ts_db # Check simple overlap checks work. self.assertTrue(is_overlaping(self.field_change, self.field_change2), "Should be overlapping") self.assertFalse(is_overlaping(self.field_change, self.field_change3), "Should not be overlapping") active_indicators = session.query(ts_db.FieldChange) \ .join(ts_db.RegressionIndicator) \ .join(ts_db.Regression) \ .filter(or_(ts_db.Regression.state == RegressionState.DETECTED, ts_db.Regression.state == RegressionState.DETECTED_FIXED)) \ .options(joinedload(ts_db.FieldChange.start_order), joinedload(ts_db.FieldChange.end_order), joinedload(ts_db.FieldChange.test), joinedload(ts_db.FieldChange.machine)) \ .all() # Check non-overlapping changes are always False. ret, reg = identify_related_changes(session, ts_db, self.field_change3, active_indicators) self.assertFalse(ret, "Ranges don't overlap, should not match") self.regressions.append(reg) # Check a regression matches if all fields match. ret, _ = identify_related_changes(session, ts_db, self.field_change, active_indicators) self.assertTrue(ret, "Should Match.") field_change7 = ts_db.FieldChange(self.order1234, self.order1235, self.machine2, self.test2, self.a_field.id) session.add(field_change7) active_indicators = session.query(ts_db.FieldChange) \ .join(ts_db.RegressionIndicator) \ .join(ts_db.Regression) \ .filter(or_(ts_db.Regression.state == RegressionState.DETECTED, ts_db.Regression.state == RegressionState.DETECTED_FIXED)) \ .options(joinedload(ts_db.FieldChange.start_order), joinedload(ts_db.FieldChange.end_order), joinedload(ts_db.FieldChange.test), joinedload(ts_db.FieldChange.machine)) \ .all() ret, reg = identify_related_changes(session, ts_db, field_change7, active_indicators) self.assertNotEquals(self.regression, reg) self.assertFalse(ret, "No match with different machine and tests.") self.regressions.append(reg) field_change4 = ts_db.FieldChange(self.order1234, self.order1235, self.machine2, self.test, self.a_field.id) # Check a regression matches if all fields match. ret, _ = identify_related_changes(session, ts_db, field_change4, active_indicators) self.assertTrue(ret, "Should Match with different machine.") field_change5 = ts_db.FieldChange(self.order1234, self.order1235, self.machine, self.test2, self.a_field.id) # Check a regression matches if all fields match. ret, _ = identify_related_changes(session, ts_db, field_change5, active_indicators) self.assertTrue(ret, "Should Match with different tests.") field_change6 = ts_db.FieldChange(self.order1234, self.order1235, self.machine, self.test, self.a_field2.id) # Check a regression matches if all fields match. ret, _ = identify_related_changes(session, ts_db, field_change6, active_indicators) self.assertTrue(ret, "Should Match with different fields.") session.commit() r2 = rebuild_title(session, ts_db, self.regression) expected_title = "Regression of 6 benchmarks: foo, bar" self.assertEquals(r2.title, expected_title)
def test_change_grouping_criteria(self): ts_db = self.ts_db # Check simple overlap checks work. self.assertTrue(is_overlaping(self.field_change, self.field_change2), "Should be overlapping") self.assertFalse(is_overlaping(self.field_change, self.field_change3), "Should not be overlapping") # Check non-overlapping changes are always False. ret, reg = identify_related_changes(ts_db, self.regressions, self.field_change3) self.assertFalse(ret, "Ranges don't overlap, should not match") self.regressions.append(reg) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, self.regressions, self.field_change) self.assertTrue(ret, "Should Match.") field_change7 = ts_db.FieldChange(self.order1234, self.order1235, self.machine2, self.test2, self.a_field) ts_db.add(field_change7) ret, reg = identify_related_changes(ts_db, self.regressions, field_change7) self.assertNotEquals(self.regression, reg) self.assertFalse(ret, "Should not match with differnt machine and tests.") self.regressions.append(reg) field_change4 = ts_db.FieldChange(self.order1234, self.order1235, self.machine2, self.test, self.a_field) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, self.regressions, field_change4) self.assertTrue(ret, "Should Match with differnt machine.") field_change5 = ts_db.FieldChange(self.order1234, self.order1235, self.machine, self.test2, self.a_field) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, self.regressions, field_change5) self.assertTrue(ret, "Should Match with differnt tests.") field_change6 = ts_db.FieldChange(self.order1234, self.order1235, self.machine, self.test, self.a_field2) # Check a regression matches if all fields match. ret, _ = identify_related_changes(ts_db, self.regressions, field_change6) self.assertTrue(ret, "Should Match with differnt fields.") ts_db.commit() r2 = rebuild_title(ts_db, self.regression) EXPECTED_TITLE = "Regression of 6 benchmarks: test-a, test-b" self.assertEquals(r2.title, EXPECTED_TITLE)