Skip to content

Commit

Permalink
Merge pull request pyca#5 from pyca/pypy-fixes
Browse files Browse the repository at this point in the history
Some changes to make the test suite green on PyPy

This adds some missing initialization that is actually necessary to work on PyPy (whereas it is only necessary to work on CPython sometimes).  It also adjusts some garbage collector interactions in one test to satisfy PyPy's somewhat different garbage collection requirements.
  • Loading branch information
exarkun committed Jan 11, 2014
2 parents 73f9313 + d4033eb commit 9efd9c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2257,3 +2257,14 @@ def locking_function(mode, index, filename, line):
else:
_initialize_openssl_threads(get_ident, Lock)
del get_ident, Lock

# There are no direct unit tests for this initialization. It is tested
# indirectly since it is necessary for functions like dump_privatekey when
# using encryption.
#
# Thus OpenSSL.test.test_crypto.FunctionTests.test_dump_privatekey_passphrase
# and some other similar tests may fail without this (though they may not if
# the Python runtime has already done some initialization of the underlying
# OpenSSL library (and is linked against the same one that cryptography is
# using)).
_lib.OpenSSL_add_all_algorithms()
16 changes: 14 additions & 2 deletions OpenSSL/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Unit tests for :py:obj:`OpenSSL.SSL`.
"""

from gc import collect
from gc import collect, get_referrers
from errno import ECONNREFUSED, EINPROGRESS, EWOULDBLOCK, EPIPE
from sys import platform, version_info
from socket import SHUT_RDWR, error, socket
Expand Down Expand Up @@ -1139,6 +1139,7 @@ def test_wrong_args(self):
self.assertRaises(
TypeError, context.set_tlsext_servername_callback, 1, 2)


def test_old_callback_forgotten(self):
"""
If :py:obj:`Context.set_tlsext_servername_callback` is used to specify a new
Expand All @@ -1157,8 +1158,19 @@ def replacement(connection):
del callback

context.set_tlsext_servername_callback(replacement)

# One run of the garbage collector happens to work on CPython. PyPy
# doesn't collect the underlying object until a second run for whatever
# reason. That's fine, it still demonstrates our code has properly
# dropped the reference.
collect()
self.assertIdentical(None, tracker())
collect()

callback = tracker()
if callback is not None:
referrers = get_referrers(callback)
if len(referrers) > 1:
self.fail("Some references remain: %r" % (referrers,))


def test_no_servername(self):
Expand Down

0 comments on commit 9efd9c6

Please sign in to comment.