forked from mozilla/treeherder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pytest | ||
from unittest.mock import patch, MagicMock, call | ||
from treeherder.workers.stats import publish_stats | ||
from treeherder.model.models import Push, Job | ||
from django.utils import timezone | ||
from datetime import timedelta | ||
|
||
|
||
@pytest.mark.django_db | ||
@patch('treeherder.workers.stats.get_stats_client') | ||
def test_publish_stats_nothing_to_do(get_worker_mock, django_assert_num_queries, caplog): | ||
statsd_client = MagicMock() | ||
get_worker_mock.return_value = statsd_client | ||
assert Push.objects.count() == 0 | ||
assert Job.objects.count() == 0 | ||
with django_assert_num_queries(2): | ||
publish_stats() | ||
assert [(level, message) for _, level, message in caplog.record_tuples] == [ | ||
(20, 'Publishing runtime statistics to statsd'), | ||
(20, 'Ingested 0 pushes'), | ||
(20, 'Ingested 0 jobs in total'), | ||
] | ||
assert statsd_client.call_args_list == [] | ||
|
||
|
||
@pytest.mark.django_db | ||
@patch('treeherder.workers.stats.get_stats_client') | ||
def test_publish_stats( | ||
get_worker_mock, eleven_jobs_stored_new_date, django_assert_num_queries, caplog, settings | ||
): | ||
"Test statsd statistics publication task" | ||
settings.CELERY_STATS_PUBLICATION_DELAY = 10 | ||
statsd_client = MagicMock() | ||
get_worker_mock.return_value = statsd_client | ||
assert Push.objects.count() == 10 | ||
assert Job.objects.count() == 11 | ||
Push.objects.update(time=timezone.now() - timedelta(minutes=10)) | ||
Job.objects.update(end_time=timezone.now() - timedelta(minutes=10)) | ||
|
||
with django_assert_num_queries(2): | ||
publish_stats() | ||
assert [(level, message) for _, level, message in caplog.record_tuples] == [ | ||
(20, 'Publishing runtime statistics to statsd'), | ||
(20, 'Ingested 10 pushes'), | ||
(20, 'Ingested 11 jobs in total'), | ||
] | ||
assert statsd_client.incr.call_args_list == [ | ||
call('push', 10), | ||
call('jobs', 11), | ||
call('jobs_repo.mozilla-central', 11), | ||
call('jobs_state.completed', 11), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters