This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cache SSLContexts created by ssl.wrap_socket
avoids unnecessary allocation of them which appears to stress pypy's GC (w/ their finalization needs) also fix some type signatures and kill some now unnecessary mock patches Closes: #1038
- Loading branch information
Showing
8 changed files
with
156 additions
and
13 deletions.
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
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
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
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,36 @@ | ||
import socket | ||
import ssl | ||
from twisted.trial import unittest | ||
|
||
from autopush.ssl import ( | ||
monkey_patch_ssl_wrap_socket, | ||
ssl_wrap_socket_cached, | ||
undo_monkey_patch_ssl_wrap_socket | ||
) | ||
|
||
|
||
class SSLContextCacheTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
# XXX: test_main doesn't cleanup after itself | ||
undo_monkey_patch_ssl_wrap_socket() | ||
|
||
def test_monkey_patch_ssl_wrap_socket(self): | ||
assert ssl.wrap_socket is not ssl_wrap_socket_cached | ||
orig = ssl.wrap_socket | ||
monkey_patch_ssl_wrap_socket() | ||
self.addCleanup(undo_monkey_patch_ssl_wrap_socket) | ||
|
||
assert ssl.wrap_socket is ssl_wrap_socket_cached | ||
undo_monkey_patch_ssl_wrap_socket() | ||
assert ssl.wrap_socket is orig | ||
|
||
def test_ssl_wrap_socket_cached(self): | ||
monkey_patch_ssl_wrap_socket() | ||
self.addCleanup(undo_monkey_patch_ssl_wrap_socket) | ||
|
||
s1 = socket.create_connection(('search.yahoo.com', 443)) | ||
s2 = socket.create_connection(('google.com', 443)) | ||
ssl1 = ssl.wrap_socket(s1, do_handshake_on_connect=False) | ||
ssl2 = ssl.wrap_socket(s2, do_handshake_on_connect=False) | ||
assert ssl1.context is ssl2.context |
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