Skip to content

Commit

Permalink
Test case for the locking stuff.
Browse files Browse the repository at this point in the history
Probably not particularly great at finding issues on all platforms.
Notably Windows doesn't seem to crash without it anyway.
  • Loading branch information
public committed Dec 26, 2013
1 parent a193164 commit afe1007
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/hazmat/backends/test_openssl.py
Expand Up @@ -11,6 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import threading

import pytest

from cryptography import utils
Expand Down Expand Up @@ -97,3 +99,28 @@ def test_handle_unknown_error(self):
backend.lib.EVP_F_EVP_DECRYPTFINAL_EX,
0
)

def test_threads(self):
b = Backend()

def randloop():
s = b.ffi.new("char[]", 16)
sb = b.ffi.buffer(s)
sb[:] = b"\0" * 16

for i in range(300000):
b.lib.RAND_seed(s, 16)

threads = []
for x in range(3):
t = threading.Thread(target=randloop)
t.daemon = True
t.start()

threads.append(t)

while threads:
for t in threads:
t.join(0.1)
if not t.isAlive():
threads.remove(t)

0 comments on commit afe1007

Please sign in to comment.