Exemplo n.º 1
0
def get_metrics_list(project):
    unique_names = set()

    testruns = TestRun.objects.filter(
        environment__project=project).values('id').order_by('id')
    test_runs_ids = [tr['id'] for tr in testruns]
    for chunk in split_list(test_runs_ids, chunk_size=100):
        metric_set = Metric.objects.filter(test_run_id__in=chunk).values(
            'suite__slug', 'name')
        for m in metric_set:
            unique_names.add(join_name(m['suite__slug'], m['name']))

    metric_names = [{"name": name} for name in sorted(unique_names)]

    metrics = [{
        "name": ":summary:",
        "label": _("Summary of all metrics per build")
    }]
    metrics += [{
        "name": ":dynamic_summary:",
        "label": _("Summary of selected metrics"),
        "dynamic": "yes"
    }]
    metrics += [{
        "name": ":tests:",
        "label": _("Test pass %"),
        "max": 100,
        "min": 0
    }]
    metrics += metric_names
    return metrics
Exemplo n.º 2
0
    def test_split_list(self):
        _list = [1, 2, 3, 4, 5, 6, 7]

        chunks = split_list(_list)

        self.assertEqual(7, len(chunks))
        self.assertEqual([1], chunks[0])
        self.assertEqual([7], chunks[6])

        _list = [1, 2, 3, 4, 5, 6, 7]
        chunks = split_list(_list, chunk_size=2)

        self.assertEqual(4, len(chunks))
        self.assertEqual([1, 2], chunks[0])
        self.assertEqual([3, 4], chunks[1])
        self.assertEqual([5, 6], chunks[2])
        self.assertEqual([7], chunks[3])
Exemplo n.º 3
0
    def __get_tests__(self, builds, metadata):
        test_runs = []
        for build in builds:
            for test_run in build.test_runs.all():
                test_runs.append(test_run)

        tests = []
        for test_runs_batch in split_list(test_runs, chunk_size=100):
            prefetch_related_objects(test_runs_batch, Prefetch('tests', queryset=Test.objects.filter(metadata=metadata).prefetch_related('metadata').order_by()))
            for test_run in test_runs_batch:
                tests += test_run.tests.all()
        return tests
Exemplo n.º 4
0
    def __get_all_tests__(self, build, search):

        test_runs = TestRun.objects.filter(build=build).values('id')
        test_runs_ids = [test_run['id'] for test_run in test_runs]
        for chunk in split_list(test_runs_ids, chunk_size=100):
            query_set = Test.objects.filter(test_run_id__in=chunk)
            if search:
                query_set = query_set.filter(metadata__name__icontains=search)

            tests = query_set.only('result', 'has_known_issues', 'suite_id',
                                   'metadata_id').order_by()
            self.all_tests += tests
Exemplo n.º 5
0
    def run(self):
        count = len(self.suitemetadata_ids)
        logger.info('[thread-%s] processing %d suitemetadata' %
                    (self.thread_id, count))
        orphan_metadata = []
        for offset in range(0, count, STEP):
            ids = self.suitemetadata_ids[offset:offset + STEP]
            for metadata in SuiteMetadata.objects.filter(id__in=ids).annotate(
                    **annotations).all():
                # It means there's no SuiteMetadata with fixed suite, so it's safe to change it in place
                if metadata.correct_metadata_id is None:
                    if metadata.correct_suite_slug is None:
                        orphan_metadata.append(metadata.id)
                    else:
                        try:
                            metadata.suite = metadata.correct_suite_slug
                            metadata.save()
                        except IntegrityError:
                            logger.error(
                                'There appears to have a fixed suite metadata already'
                            )
                            logger.error(
                                'This was not supposed to happen though, check these cases carefuly'
                            )
                            logger.error(
                                'SuiteMetadata (id: %d, kind=test, suite="%s", name="%s")'
                                % (metadata.id, metadata.suite, metadata.name))
                            return
                # It means there's a correct one, so just update tests
                else:
                    Test.objects.order_by().filter(metadata=metadata).update(
                        metadata_id=metadata.correct_metadata_id)
                    # It's safe to delete buggy metadata now
                    orphan_metadata.append(metadata.id)

            if self.show_progress:
                print('.', end='', flush=True)

        if len(orphan_metadata) > 0:
            logger.info('Deleting %d orphan metadata objects' %
                        len(orphan_metadata))
            chunks = split_list(orphan_metadata, chunk_size=10000)
            for chunk in chunks:
                SuiteMetadata.objects.filter(id__in=chunk).delete()

        logger.info('[thread-%s] done updating' % self.thread_id)
    def handle(self, *args, **options):
        show_progress = options['show_progress']
        num_threads = options['num_threads']

        logger.info('Discovering number of tests that need work...')
        count = Test.objects.filter(build__isnull=True,
                                    environment__isnull=True).count()

        if count == 0:
            logger.info('Nothing to do!')
            return

        logger.info('Working on %d tests' % count)
        testrun_ids = TestRun.objects.order_by('-id').values_list('id',
                                                                  flat=True)

        chunk_size = math.floor(len(testrun_ids) / num_threads) + 1
        chunks = split_list(testrun_ids, chunk_size=chunk_size)

        threads = []
        for chunk in chunks:
            thread_id = len(threads)
            total_updates[thread_id] = 0
            thread = DataFillerThread(thread_id,
                                      chunk,
                                      show_progress=show_progress)
            thread.start()
            threads.append(thread)

        for thread in threads:
            thread.join()

        logger.info('Done updating %d tests' % sum(total_updates.values()))

        # Check that everything worked as expected
        count = Test.objects.filter(build__isnull=True,
                                    environment__isnull=True).count()
        if count > 0:
            logger.error(
                'Something went wrong! %d tests still do not have build and environment filled out'
                % count)
            return

        logger.info('Done!')
Exemplo n.º 7
0
    def __init__(self, build, environment=None):
        self.tests_pass = 0
        self.tests_fail = 0
        self.tests_xfail = 0
        self.tests_skip = 0

        query_set = build.test_runs
        if environment:
            query_set = query_set.filter(environment=environment)

        query_set = query_set.values('id').order_by('id')

        test_runs_ids = [test_run['id'] for test_run in query_set]
        for chunk in split_list(test_runs_ids, chunk_size=100):
            status = Status.objects.filter(suite=None, test_run_id__in=chunk)
            for s in status:
                self.tests_pass += s.tests_pass
                self.tests_fail += s.tests_fail
                self.tests_xfail += s.tests_xfail
                self.tests_skip += s.tests_skip
Exemplo n.º 8
0
    def handle(self, *args, **options):
        show_progress = options['show_progress']
        num_threads = options['num_threads']

        logger.info('Discovering number of metadata that need work...')
        count = int(SuiteMetadata.objects.filter(buggy_ones).count())

        if count == 0:
            logger.info('Nothing to do!')
            return

        logger.info('Working on %d metadatas' % count)
        metadata_ids = SuiteMetadata.objects.filter(buggy_ones).order_by(
            '-id').values_list('id', flat=True)

        chunk_size = math.floor(len(metadata_ids) / num_threads) + 1
        chunks = split_list(metadata_ids, chunk_size=chunk_size)

        threads = []
        for chunk in chunks:
            thread_id = len(threads)
            thread = SuiteMetadataFixThread(thread_id,
                                            chunk,
                                            show_progress=show_progress)
            thread.start()
            threads.append(thread)

        for thread in threads:
            thread.join()

        logger.info('Done updating')

        # Check that everything worked as expected
        count = int(SuiteMetadata.objects.filter(buggy_ones).count())
        if count > 0:
            logger.error('Something went wrong! %d metadata are still buggy' %
                         count)
            return

        logger.info('Done!')