Skip to content

Commit

Permalink
fix(issue-82): handle OutboundSessionHasGoneAway
Browse files Browse the repository at this point in the history
  • Loading branch information
iuridiniz authored and italorossi committed May 15, 2023
1 parent eb210f3 commit 5ced374
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion greenswitch/esl.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def stop(self):
if self.connected:
try:
self.send('exit')
except (NotConnectedError, socket.error):
except (NotConnectedError, socket.error, OutboundSessionHasGoneAway):
pass
self._run = False
if self._receive_events_greenlet:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_outbound_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ def test_raise_value_error_while_the_call_is_active(self):
with self.assertRaises(ValueError):
with self.outbound_session.while_connected():
raise ValueError("http exception")

def test_raising_OutboundSessionHasGoneAway_in_session_stop_will_pass(self):
# make outbound_session.send raise OutboundSessionHasGoneAway
self.outbound_session.send = mock.MagicMock(side_effect=esl.OutboundSessionHasGoneAway)
# mock sock.close
self.outbound_session.sock.close = mock.MagicMock()

# stop and assert sock.close is called
self.outbound_session.stop()
assert self.outbound_session.sock.close.called

0 comments on commit 5ced374

Please sign in to comment.