diff --git a/greenswitch/esl.py b/greenswitch/esl.py index ef9a397..6c25f29 100644 --- a/greenswitch/esl.py +++ b/greenswitch/esl.py @@ -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: diff --git a/tests/test_outbound_session.py b/tests/test_outbound_session.py index ed4086c..69205b3 100644 --- a/tests/test_outbound_session.py +++ b/tests/test_outbound_session.py @@ -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