Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Heartbeat._bind_socket to return on the first successful bind. #431

Merged
merged 2 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ipykernel/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def _bind_socket(self):
self.pick_port()
else:
raise
else:
return

def run(self):
self.socket = self.context.socket(zmq.ROUTER)
Expand Down
8 changes: 8 additions & 0 deletions ipykernel/tests/test_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def test_port_bind_failure_raises():
assert mock_try_bind.call_count == 1


def test_port_bind_failure_succeeds():
Copy link
Contributor Author

@mdickinson mdickinson Sep 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aargh; that's a bad test name. I'll fix to remove the "failure" text.

heart = Heartbeat(None)
with patch.object(heart, '_try_bind_socket') as mock_try_bind:
mock_try_bind.side_effect = lambda: None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could probably just be removed.

heart._bind_socket()
assert mock_try_bind.call_count == 1


def test_port_bind_failure_recovery():
try:
errno.WSAEADDRINUSE
Expand Down