Skip to content

Commit

Permalink
test check_delay > 0 and call callback immediately
Browse files Browse the repository at this point in the history
 - add test for positive check_delay

in production environment check_delay often set to a positive value, the
tornado API is changed so the PeriodicCallback no longer recieve event
loop as parameter.

 - use concurrent.future_add_done_callback which invoke callback immediately

When the future is already finished, we expect that the callback will be
executed immediately, but concurrent.add_done_callback did not make this
check and only add it to the event loop, while future_add_done_callback did this check.
  • Loading branch information
unkcpz committed Jun 13, 2020
1 parent 96f4391 commit 2b9cd7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions circus/tests/test_arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,21 @@ def callback(*args):

self.assertEqual(callee.call_count, 1)

def test_start_with_callback_delay(self):
controller = "tcp://127.0.0.1:%d" % get_available_port()
sub = "tcp://127.0.0.1:%d" % get_available_port()
arbiter = Arbiter([], controller, sub, check_delay=1)

callee = mock.MagicMock()

def callback(*args):
callee()
arbiter.stop()

arbiter.start(cb=callback)

self.assertEqual(callee.call_count, 1)

@tornado.testing.gen_test
def test_start_with_callback_and_given_loop(self):
controller = "tcp://127.0.0.1:%d" % get_available_port()
Expand Down
2 changes: 1 addition & 1 deletion circus/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def wrapper(self, *args, **kwargs):
finally:
if isinstance(resp, concurrent.Future):
cb = functools.partial(_synchronized_cb, arbiter)
resp.add_done_callback(cb)
concurrent.future_add_done_callback(resp, cb)
else:
if arbiter is not None:
arbiter._exclusive_running_command = None
Expand Down

0 comments on commit 2b9cd7f

Please sign in to comment.