summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Shemyak <konstantin@shemyak.com>2018-07-24 12:48:38 +0300
committerKonstantin Shemyak <konstantin@shemyak.com>2018-07-24 14:58:36 +0300
commit173ec7473b67f8b4eead99ecaea401d4bb20a65a (patch)
treed00a272061c63ccedb99260de01bd411705b72ac
parent2fc491dd5047a0771e47973c468abf2edaff33e7 (diff)
downloadm2crypto-173ec7473b67f8b4eead99ecaea401d4bb20a65a.tar.gz
Taken a longer millisecond timeout to avoid handling rounding.
Linux rounds microseconds in the timeouts up to the HZ kernel parameter. To avoid checking for rounded values, pick the timeout long enough so that it is whole number of HZ for any reasonable HZ value. By doing this, we also do not need to handle separately Windows rounding microseconds down to milliseconds.
-rw-r--r--tests/test_ssl.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/tests/test_ssl.py b/tests/test_ssl.py
index cb2cac8..e3e1e67 100644
--- a/tests/test_ssl.py
+++ b/tests/test_ssl.py
@@ -33,6 +33,7 @@ import warnings
from M2Crypto import (Err, Rand, SSL, X509, ftpslib, httpslib, m2, m2urllib,
m2urllib2, m2xmlrpclib, py27plus, six)
+from M2Crypto.SSL.timeout import DEFAULT_TIMEOUT
from tests import unittest
from tests.fips import fips_mode
@@ -353,6 +354,14 @@ class MiscSSLClientTestCase(BaseSSLClientTestCase):
def test_server_simple_timeouts(self):
pid = self.start_server(self.args)
+ # Arbitrary value:
+ test_timeout_sec = 909
+ # Linux rounds microseconds in the timeouts up to the HZ kernel parameter.
+ # Windows rounds down to milliseconds.
+ # To avoid checking for rounded values, pick interval long enough
+ # so that it is a whole number of ms and HZ for any reasonable HZ value.
+ test_timeout_microsec = 500000
+
try:
with self.assertRaises(ValueError):
SSL.Context('tlsv5')
@@ -367,20 +376,13 @@ class MiscSSLClientTestCase(BaseSSLClientTestCase):
self.assertEqual(w.microsec, 0, w.microsec)
s.set_socket_read_timeout(SSL.timeout())
- s.set_socket_write_timeout(SSL.timeout(909, 9))
+ s.set_socket_write_timeout(SSL.timeout(test_timeout_sec, test_timeout_microsec))
r = s.get_socket_read_timeout()
w = s.get_socket_write_timeout()
- self.assertEqual(r.sec, 600, r.sec)
+ self.assertEqual(r.sec, DEFAULT_TIMEOUT, r.sec)
self.assertEqual(r.microsec, 0, r.microsec)
- self.assertEqual(w.sec, 909, w.sec)
- if sys.platform == 'win32':
- # On Windows, microseconds get rounded to milliseconds
- self.assertEqual(w.microsec, 0, w.microsec)
- else:
- # On some platforms (e.g. some Linux), microeconds get rounded
- # up to the next millisecond.
- # On some platforms (e.g. OS-X), microseconds are preserved.
- self.assertIn(w.microsec, (9, 1000), w.microsec)
+ self.assertEqual(w.sec, test_timeout_sec, w.sec)
+ self.assertEqual(w.microsec, test_timeout_microsec, w.microsec)
s.connect(self.srv_addr)
data = self.http_get(s)