MCPcopy
hub / github.com/Bogdanp/dramatiq / test_actors_can_define_failure_callbacks

Function test_actors_can_define_failure_callbacks

tests/test_callbacks.py:35–57  ·  view source on GitHub ↗
(stub_broker, stub_worker)

Source from the content-addressed store, hash-verified

33
34
35def 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
60def test_actor_callbacks_raise_type_error_when_given_a_normal_callable(stub_broker):

Callers

nothing calls this directly

Calls 2

send_with_optionsMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected