| 1 |
from celery.contrib.abortable import AbortableAsyncResult, AbortableTask |
| 2 |
|
| 3 |
|
| 4 |
class test_AbortableTask: |
| 5 |
|
| 6 |
def setup_method(self): |
| 7 |
@self.app.task(base=AbortableTask, shared=False) |
| 8 |
def abortable(): |
| 9 |
return True |
| 10 |
self.abortable = abortable |
| 11 |
|
| 12 |
def test_async_result_is_abortable(self): |
| 13 |
result = self.abortable.apply_async() |
| 14 |
tid = result.id |
| 15 |
assert isinstance( |
| 16 |
self.abortable.AsyncResult(tid), AbortableAsyncResult) |
| 17 |
|
| 18 |
def test_is_not_aborted(self): |
| 19 |
self.abortable.push_request() |
| 20 |
try: |
| 21 |
result = self.abortable.apply_async() |
| 22 |
tid = result.id |
| 23 |
assert not self.abortable.is_aborted(task_id=tid) |
| 24 |
finally: |
| 25 |
self.abortable.pop_request() |
| 26 |
|
| 27 |
def test_is_aborted_not_abort_result(self): |
| 28 |
self.abortable.AsyncResult = self.app.AsyncResult |
| 29 |
self.abortable.push_request() |
| 30 |
try: |
| 31 |
self.abortable.request.id = 'foo' |
| 32 |
assert not self.abortable.is_aborted() |
| 33 |
finally: |
| 34 |
self.abortable.pop_request() |
| 35 |
|
| 36 |
def test_abort_yields_aborted(self): |
| 37 |
self.abortable.push_request() |
| 38 |
try: |
| 39 |
result = self.abortable.apply_async() |
| 40 |
result.abort() |
| 41 |
tid = result.id |
| 42 |
assert self.abortable.is_aborted(task_id=tid) |
| 43 |
finally: |
| 44 |
self.abortable.pop_request() |