def save(self, test_list): if not test_list: return step = self.step job = step.job project = job.project # agg_groups_by_id = {} # create all test cases for test in test_list: testcase = TestCase( job=job, step=step, name_sha=test.name_sha, project=project, name=test.name, duration=test.duration, message=test.message, result=test.result, date_created=test.date_created, reruns=test.reruns ) db.session.add(testcase) if test.artifacts: for ta in test.artifacts: testartifact = TestArtifact( name=ta['name'], type=ta['type'], test=testcase,) testartifact.save_base64_content(ta['base64']) db.session.add(testartifact) try: db.session.commit() except IntegrityError: db.session.rollback() logger.exception('Duplicate test name; (step={})'.format(step.id.hex)) try_create(FailureReason, { 'step_id': step.id, 'job_id': step.job_id, 'build_id': step.job.build_id, 'project_id': step.project_id, 'reason': 'duplicate_test_name' }) db.session.commit() try: self._record_test_counts(test_list) self._record_test_failures(test_list) self._record_test_duration(test_list) self._record_test_rerun_counts(test_list) except Exception: logger.exception('Failed to record aggregate test statistics')
def save(self, test_list): if not test_list: return step = self.step job = step.job project = job.project # agg_groups_by_id = {} # create all test cases for test in test_list: testcase = TestCase( job=job, step=step, name_sha=test.name_sha, project=project, name=test.name, duration=test.duration, message=test.message, result=test.result, date_created=test.date_created, reruns=test.reruns ) db.session.add(testcase) if test.artifacts: for ta in test.artifacts: testartifact = TestArtifact( name=ta['name'], type=ta['type'], test=testcase,) testartifact.save_base64_content(ta['base64']) db.session.add(testartifact) db.session.commit() try: self._record_test_counts(test_list) self._record_test_failures(test_list) self._record_test_duration(test_list) self._record_test_rerun_counts(test_list) except Exception: logger.exception('Failed to record aggregate test statistics')
def save(self, test_list): if not test_list: return step = self.step job = step.job project = job.project # agg_groups_by_id = {} # create all test cases for test in test_list: testcase = TestCase(job=job, step=step, name_sha=test.name_sha, project=project, name=test.name, duration=test.duration, message=test.message, result=test.result, date_created=test.date_created, reruns=test.reruns) db.session.add(testcase) if test.artifacts: for ta in test.artifacts: testartifact = TestArtifact( name=ta['name'], type=ta['type'], test=testcase, ) testartifact.save_base64_content(ta['base64']) db.session.add(testartifact) db.session.commit() try: self._record_test_counts(test_list) self._record_test_failures(test_list) self._record_test_duration(test_list) self._record_test_rerun_counts(test_list) except Exception: logger.exception('Failed to record aggregate test statistics')
def save(self, test_list): if not test_list: return step = self.step job = step.job project = job.project # Create all test cases. testcase_list = [] # For tracking the name of any test we see with a bad # duration, typically the first one if we see multiple. bad_duration_test_name = None bad_duration_value = None for test in test_list: duration = test.duration # Maximum value for the Integer column type if duration is not None and (duration > 2147483647 or duration < 0): # If it is very large (>~25 days) or negative set it to 0 # since it is almost certainly wrong, and keeping it or truncating # to max will give misleading total values. if not bad_duration_test_name: bad_duration_test_name = test.name bad_duration_value = duration duration = 0 testcase = TestCase( job=job, step=step, name_sha=test.name_sha, project=project, name=test.name, duration=duration, message=test.message, result=test.result, date_created=test.date_created, reruns=test.reruns ) testcase_list.append(testcase) if bad_duration_test_name: # Include the project slug in the warning so project warnings aren't bucketed together. logger.warning("Got bad test duration for " + project.slug + "; %s: %s", bad_duration_test_name, bad_duration_value) # Try an optimistic commit of all cases at once. for testcase in testcase_list: db.session.add(testcase) try: db.session.commit() except IntegrityError: db.session.rollback() create_or_update(FailureReason, where={ 'step_id': step.id, 'reason': 'duplicate_test_name', }, values={ 'project_id': step.project_id, 'build_id': step.job.build_id, 'job_id': step.job_id, }) db.session.commit() # Slowly make separate commits, to uncover duplicate test cases: for i, testcase in enumerate(testcase_list): db.session.add(testcase) try: db.session.commit() except IntegrityError: db.session.rollback() original = _record_duplicate_testcase(testcase) db.session.commit() testcase_list[i] = original # so artifacts get stored _record_test_failures(original.step) # so count is right # Test artifacts do not operate under a unique constraint, so # they should insert cleanly without an integrity error. for test, testcase in zip(test_list, testcase_list): if test.artifacts: for ta in test.artifacts: testartifact = TestArtifact( name=ta['name'], type=ta['type'], test=testcase,) testartifact.save_base64_content(ta['base64']) db.session.add(testartifact) try: db.session.commit() except Exception: db.session.rollback() logger.exception('Failed to save artifacts' ' for step {}'.format(step.id.hex)) try: _record_test_counts(self.step) _record_test_failures(self.step) _record_test_duration(self.step) _record_test_rerun_counts(self.step) except Exception: db.session.rollback() logger.exception('Failed to record aggregate test statistics' ' for step {}'.format(step.id.hex))
def save(self, test_list): if not test_list: return step = self.step job = step.job project = job.project # Create all test cases. testcase_list = [] for test in test_list: testcase = TestCase( job=job, step=step, name_sha=test.name_sha, project=project, name=test.name, duration=test.duration, message=test.message, result=test.result, date_created=test.date_created, reruns=test.reruns ) testcase_list.append(testcase) # Try an optimistic commit of all cases at once. for testcase in testcase_list: db.session.add(testcase) try: db.session.commit() except IntegrityError: db.session.rollback() create_or_update(FailureReason, where={ 'step_id': step.id, 'reason': 'duplicate_test_name', }, values={ 'project_id': step.project_id, 'build_id': step.job.build_id, 'job_id': step.job_id, }) db.session.commit() # Slowly make separate commits, to uncover duplicate test cases: for i, testcase in enumerate(testcase_list): db.session.add(testcase) try: db.session.commit() except IntegrityError: db.session.rollback() original = _record_duplicate_testcase(testcase) db.session.commit() testcase_list[i] = original # so artifacts get stored _record_test_failures(original.step) # so count is right # Test artifacts do not operate under a unique constraint, so # they should insert cleanly without an integrity error. for test, testcase in zip(test_list, testcase_list): if test.artifacts: for ta in test.artifacts: testartifact = TestArtifact( name=ta['name'], type=ta['type'], test=testcase,) testartifact.save_base64_content(ta['base64']) db.session.add(testartifact) try: db.session.commit() except Exception: db.session.rollback() logger.exception('Failed to save artifacts' ' for step {}'.format(step.id.hex)) try: _record_test_counts(self.step) _record_test_failures(self.step) _record_test_duration(self.step) _record_test_rerun_counts(self.step) except Exception: db.session.rollback() logger.exception('Failed to record aggregate test statistics' ' for step {}'.format(step.id.hex))