-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with deletion of sessions during refresh() (#2055)
* Fix issue with deletion of sessions during refresh(). * Remove use of IsolatedAsyncioTestCase. It's not available in all versions of Python we support. Co-authored-by: Bryan Worrell <bworrell@mitre.org>
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
import socket | ||
from unittest import mock | ||
|
||
from app.contacts.contact_tcp import TcpSessionHandler | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TestTcpSessionHandler: | ||
|
||
def test_refresh_with_socket_errors(self, loop): | ||
handler = TcpSessionHandler(services=None, log=logger) | ||
|
||
session_with_socket_error = mock.Mock() | ||
session_with_socket_error.connection.send.side_effect = socket.error() | ||
|
||
handler.sessions = [ | ||
session_with_socket_error, | ||
session_with_socket_error, | ||
mock.Mock() | ||
] | ||
|
||
loop.run_until_complete(handler.refresh()) | ||
assert len(handler.sessions) == 1 | ||
assert all(x is not session_with_socket_error for x in handler.sessions) | ||
|
||
def test_refresh_without_socket_errors(self, loop): | ||
handler = TcpSessionHandler(services=None, log=logger) | ||
handler.sessions = [ | ||
mock.Mock(), | ||
mock.Mock(), | ||
mock.Mock() | ||
] | ||
|
||
loop.run_until_complete(handler.refresh()) | ||
assert len(handler.sessions) == 3 |