(stub_broker, stub_worker)
| 33 | |
| 34 | |
| 35 | def test_actors_can_define_failure_callbacks(stub_broker, stub_worker): |
| 36 | # Given an actor that fails with an exception |
| 37 | @dramatiq.actor(max_retries=0) |
| 38 | def do_work(): |
| 39 | raise Exception() |
| 40 | |
| 41 | # And an actor that reports on exceptions |
| 42 | exceptions = Counter() |
| 43 | |
| 44 | @dramatiq.actor |
| 45 | def report_exceptions(message_data, exception_data): |
| 46 | exceptions.update({message_data["actor_name"]}) |
| 47 | |
| 48 | # When I send the first actor a message and tell it to call the |
| 49 | # second actor on failure |
| 50 | do_work.send_with_options(on_failure="report_exceptions") |
| 51 | |
| 52 | # And join on the broker and worker |
| 53 | stub_broker.join(do_work.queue_name, fail_fast=False) |
| 54 | stub_worker.join() |
| 55 | |
| 56 | # Then my db should contain the result |
| 57 | assert exceptions[do_work.actor_name] == 1 |
| 58 | |
| 59 | |
| 60 | def test_actor_callbacks_raise_type_error_when_given_a_normal_callable(stub_broker): |
nothing calls this directly
no test coverage detected