Exemplo n.º 1
0
def test_total_emails_sent(test_perf_signature, try_repository,
                           total_signatures, mock_tc_prod_credentials):
    tc_model = MagicMock()
    timer = MaxRuntime()
    timer.start_timer()
    total_rows = 2
    total_emails = 4
    signatures_remover = PublicSignatureRemover(
        timer=timer,
        taskcluster_model=tc_model,
        max_rows_allowed=total_rows,
        max_emails_allowed=total_emails,
    )

    for n in range(0, total_signatures):
        PerformanceSignature.objects.create(
            repository=test_perf_signature.repository,
            signature_hash=(20 * ('t%s' % n)),
            framework=test_perf_signature.framework,
            platform=test_perf_signature.platform,
            option_collection=test_perf_signature.option_collection,
            suite='mysuite%s' % n,
            test='mytest%s' % n,
            application='firefox',
            has_subtests=test_perf_signature.has_subtests,
            extra_options=test_perf_signature.extra_options,
            last_updated=datetime.now(),
        )

    for n in range(0, 10):
        PerformanceSignature.objects.create(
            repository=try_repository,
            signature_hash=(20 * ('e%s' % n)),
            framework=test_perf_signature.framework,
            platform=test_perf_signature.platform,
            option_collection=test_perf_signature.option_collection,
            suite='mysuite%s' % n,
            test='mytest%s' % n,
            application='firefox',
            has_subtests=test_perf_signature.has_subtests,
            extra_options=test_perf_signature.extra_options,
            last_updated=datetime.now(),
        )

    total_signatures += 1  # is incremented because of test_perf_signature
    total_of_possible_emails = math.ceil(total_signatures / total_rows)
    expected_call_count = (total_of_possible_emails
                           if total_of_possible_emails <= total_emails else
                           total_emails)

    signatures = PerformanceSignature.objects.filter(
        last_updated__lte=datetime.now())
    signatures_remover.remove_in_chunks(signatures)

    assert tc_model.notify.email.call_count == expected_call_count
    assert not PerformanceSignature.objects.filter(
        repository__name='try').exists()
Exemplo n.º 2
0
def test_remove_try_signatures_without_data(test_perf_signature,
                                            test_perf_data, try_repository,
                                            mock_tc_prod_credentials):
    tc_model = MagicMock()
    timer = MaxRuntime()
    timer.start_timer()
    total_rows = 2
    total_emails = 2
    signatures_remover = PublicSignatureRemover(
        timer=timer,
        taskcluster_model=tc_model,
        max_rows_allowed=total_rows,
        max_emails_allowed=total_emails,
    )
    signature_with_perf_data = PerformanceSignature.objects.create(
        repository=try_repository,
        signature_hash=(20 * 'e1'),
        framework=test_perf_signature.framework,
        platform=test_perf_signature.platform,
        option_collection=test_perf_signature.option_collection,
        suite='mysuite',
        test='mytest',
        application='firefox',
        has_subtests=test_perf_signature.has_subtests,
        extra_options=test_perf_signature.extra_options,
        last_updated=datetime.now(),
    )
    push = Push.objects.first()
    PerformanceDatum.objects.create(
        repository=signature_with_perf_data.repository,
        push=push,
        job=None,
        signature=signature_with_perf_data,
        push_timestamp=datetime.now(),
        value=1.0,
    )

    signatures = PerformanceSignature.objects.filter(
        last_updated__lte=datetime.now())
    signatures_remover.remove_in_chunks(signatures)

    assert PerformanceSignature.objects.filter(
        id=signature_with_perf_data.id).exists()
Exemplo n.º 3
0
def test_performance_cycler_quit_indicator(mock_taskcluster_notify):
    ten_minutes_ago = datetime.now() - timedelta(minutes=10)
    one_second = timedelta(seconds=1)

    two_seconds_ago = datetime.now() - timedelta(seconds=2)
    five_minutes = timedelta(minutes=5)

    with pytest.raises(MaxRuntimeExceeded):
        PerfherderCycler(chunk_size=100, sleep_time=0)

        max_runtime = MaxRuntime(max_runtime=one_second)
        max_runtime.started_at = ten_minutes_ago
        max_runtime.quit_on_timeout()
    try:
        PerfherderCycler(chunk_size=100, sleep_time=0)

        max_runtime = MaxRuntime(max_runtime=five_minutes)
        max_runtime.started_at = two_seconds_ago
        max_runtime.quit_on_timeout()
    except MaxRuntimeExceeded:
        pytest.fail('Performance cycling shouldn\'t have timed out')
Exemplo n.º 4
0
class Command(BaseCommand):
    help = "Remove all vcs data ingested by Perfherder"

    # max runtime
    PER_DELETE_SPRINT = timedelta(minutes=5)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__timer = MaxRuntime(self.PER_DELETE_SPRINT)
        self.__timer.start_timer()

    def handle(self, *args, **options):
        vcs_signatures = PerformanceSignature.objects.filter(
            framework__name='vcs')
        for signature in vcs_signatures:
            signature.delete()  # intentionally cascades to data points also
            self._maybe_take_small_break(
            )  # so database won't cripple; blocking call

    def _maybe_take_small_break(self):
        if self.__enough_work():
            time.sleep(10)

    def __enough_work(self) -> bool:
        try:
            self.__timer.quit_on_timeout()  # check timer
        except MaxRuntimeExceeded:
            self.__timer.start_timer()  # reset & restart it
            return True
        return False
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.__timer = MaxRuntime(self.PER_DELETE_SPRINT)
     self.__timer.start_timer()