|
1 | 1 | #!/usr/bin/env python
|
2 |
| - |
3 |
| -import pathlib |
4 | 2 | import asyncio
|
5 |
| -import time |
6 |
| -from pprint import pformat |
7 |
| -#from concurrent.futures import TimeoutError |
8 |
| - |
9 |
| -import pytest |
10 |
| -from kombu import Queue |
11 |
| - |
12 |
| - |
13 |
| -from celery_pool_asyncio import TaskPool |
| 3 | +import pathlib |
14 | 4 |
|
15 | 5 | root = pathlib.Path()
|
16 | 6 | brocker = root / 'brocker'
|
|
25 | 15 | dir_processed = brocker / 'processed'
|
26 | 16 | dir_processed.mkdir(exist_ok=True)
|
27 | 17 |
|
| 18 | + |
28 | 19 | async def tack_function(input_data):
|
29 | 20 | await asyncio.sleep(1)
|
30 | 21 | return input_data.upper()
|
31 | 22 |
|
32 | 23 |
|
33 |
| -@pytest.fixture(scope='session') |
34 |
| -def celery_config(): |
35 |
| - return { |
| 24 | +def test_create_task(celery_app, celery_worker): |
| 25 | + from celery.contrib.testing.app import TestApp |
| 26 | + app = TestApp(config={ |
36 | 27 | 'broker_url': 'filesystem:// %s' % dir_messages,
|
37 | 28 | 'broker_transport_options': {
|
38 | 29 | 'data_folder_in': '%s' % dir_out,
|
39 | 30 | 'data_folder_out': '%s' % dir_out,
|
40 | 31 | 'data_folder_processed': '%s' % dir_processed,
|
41 | 32 | },
|
42 | 33 | 'result_persistent': True,
|
43 |
| - } |
44 |
| - |
45 |
| - |
46 |
| -@pytest.fixture(scope='session') |
47 |
| -def celery_includes(): |
48 |
| - return [ |
49 |
| - 'test_celery_pool_asyncio', |
50 |
| - ] |
51 |
| - |
52 |
| - |
53 |
| -@pytest.fixture(scope='session') |
54 |
| -def celery_worker_pool(): |
55 |
| - return 'celery_pool_asyncio:TaskPool' |
56 |
| - |
57 |
| - |
58 |
| -def test_create_task(celery_app, celery_worker): |
59 |
| - @celery_app.task |
60 |
| - async def tack_function(input_data): |
61 |
| - await asyncio.sleep(1) |
62 |
| - print('tack_function', input_data) |
63 |
| - return input_data.upper() |
64 |
| - |
65 |
| - task = tack_function.delay('hello, world!') |
66 |
| - print('task', task) |
67 |
| - result = task.get(timeout=10) |
68 |
| - print('result', result) |
69 |
| - |
| 34 | + 'worker_pool': 'celery_pool_asyncio:TaskPool', |
| 35 | + }) |
| 36 | + wrapped = app.task(tack_function) |
| 37 | + app.register_task(wrapped) |
| 38 | + msg = 'hello, world!' |
| 39 | + task = wrapped.delay(msg) |
| 40 | + reply = task.get(timeout=10) |
| 41 | + assert reply == msg.upper() |
0 commit comments