-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from City-of-Helsinki/develop
Release 20210118
- Loading branch information
Showing
8 changed files
with
489 additions
and
148 deletions.
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
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
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,57 @@ | ||
from multiprocessing import Event, Value | ||
|
||
import pytest | ||
from django.core import mail | ||
from django_q.brokers import get_broker | ||
from django_q.cluster import monitor, pusher, worker | ||
from django_q.queues import Queue | ||
from django_q.tasks import queue_size | ||
|
||
from leasing.report.lease.lease_statistic_report import LeaseStatisticReport | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def use_q_cluster_testing(settings): | ||
settings.Q_CLUSTER = { | ||
"name": "DjangORM", | ||
"cpu_affinity": 1, | ||
"testing": True, | ||
"log_level": "DEBUG", | ||
"orm": "default", | ||
} | ||
|
||
|
||
@pytest.mark.django_db(transaction=True) | ||
def test_simple_async_report_send(rf, admin_user): | ||
broker = get_broker() | ||
assert broker.queue_size() == 0 | ||
|
||
request = rf.get("/") | ||
request.query_params = {} | ||
request.user = admin_user | ||
|
||
report = LeaseStatisticReport() | ||
response = report.get_response(request) | ||
assert response.data | ||
assert broker.queue_size() == 1 | ||
|
||
# Run async task | ||
task_queue = Queue() | ||
result_queue = Queue() | ||
event = Event() | ||
event.set() | ||
pusher(task_queue, event, broker=broker) | ||
assert task_queue.qsize() == 1 | ||
assert queue_size(broker=broker) == 0 | ||
task_queue.put("STOP") | ||
worker(task_queue, result_queue, Value("f", -1)) | ||
assert task_queue.qsize() == 0 | ||
assert result_queue.qsize() == 1 | ||
result_queue.put("STOP") | ||
monitor(result_queue) | ||
assert result_queue.qsize() == 0 | ||
broker.delete_queue() | ||
|
||
# Test report file have been sent via email | ||
assert len(mail.outbox) == 1 | ||
assert len(mail.outbox[0].attachments) == 1 |
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,11 @@ | ||
Q_CLUSTER = { | ||
"name": "DjangORM", | ||
"timeout": 90, | ||
"retry": 60 * 60, # 1 hour | ||
"orm": "default", | ||
"error_reporter": { | ||
"sentry": { | ||
"dsn": "https://******@sentry.io/<project>" | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.