Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_timeout.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1 """Unit tests for socket timeout feature.""" |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 import unittest |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23831
diff
changeset
|
4 from test import test_support |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
28112
2c8c2c6b2ab7
Fix SF bugs #692951 and 692988, test_timeout.py needs 'network' resource
Neal Norwitz <nnorwitz@gmail.com>
parents:
28011
diff
changeset
|
6 # This requires the 'network' resource as given on the regrtest command line. |
|
2c8c2c6b2ab7
Fix SF bugs #692951 and 692988, test_timeout.py needs 'network' resource
Neal Norwitz <nnorwitz@gmail.com>
parents:
28011
diff
changeset
|
7 skip_expected = not test_support.is_resource_enabled('network') |
|
2c8c2c6b2ab7
Fix SF bugs #692951 and 692988, test_timeout.py needs 'network' resource
Neal Norwitz <nnorwitz@gmail.com>
parents:
28011
diff
changeset
|
8 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 import time |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 import socket |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
12 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
13 class CreationTestCase(unittest.TestCase): |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
14 """Test case for socket.gettimeout() and socket.settimeout()""" |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
15 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 def setUp(self): |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
17 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 def tearDown(self): |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
20 self.sock.close() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 def testObjectCreation(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
23 # Test Socket creation |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
24 self.assertEqual(self.sock.gettimeout(), None, |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
25 "timeout not disabled by default") |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 def testFloatReturnValue(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
28 # Test return value of gettimeout() |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
29 self.sock.settimeout(7.345) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
30 self.assertEqual(self.sock.gettimeout(), 7.345) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
32 self.sock.settimeout(3) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
33 self.assertEqual(self.sock.gettimeout(), 3) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
34 |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
35 self.sock.settimeout(None) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
36 self.assertEqual(self.sock.gettimeout(), None) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 def testReturnType(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
39 # Test return type of gettimeout() |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
40 self.sock.settimeout(1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
41 self.assertEqual(type(self.sock.gettimeout()), type(1.0)) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
43 self.sock.settimeout(3.9) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
44 self.assertEqual(type(self.sock.gettimeout()), type(1.0)) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
45 |
|
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
46 def testTypeCheck(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
47 # Test type checking by settimeout() |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
48 self.sock.settimeout(0) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
49 self.sock.settimeout(0L) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
50 self.sock.settimeout(0.0) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
51 self.sock.settimeout(None) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
52 self.assertRaises(TypeError, self.sock.settimeout, "") |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
53 self.assertRaises(TypeError, self.sock.settimeout, u"") |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
54 self.assertRaises(TypeError, self.sock.settimeout, ()) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
55 self.assertRaises(TypeError, self.sock.settimeout, []) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
56 self.assertRaises(TypeError, self.sock.settimeout, {}) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
57 self.assertRaises(TypeError, self.sock.settimeout, 0j) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
58 |
|
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
59 def testRangeCheck(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
60 # Test range checking by settimeout() |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
61 self.assertRaises(ValueError, self.sock.settimeout, -1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
62 self.assertRaises(ValueError, self.sock.settimeout, -1L) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
63 self.assertRaises(ValueError, self.sock.settimeout, -1.0) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
64 |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23793
diff
changeset
|
65 def testTimeoutThenBlocking(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
66 # Test settimeout() followed by setblocking() |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
67 self.sock.settimeout(10) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
68 self.sock.setblocking(1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
69 self.assertEqual(self.sock.gettimeout(), None) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
70 self.sock.setblocking(0) |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23793
diff
changeset
|
71 self.assertEqual(self.sock.gettimeout(), 0.0) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
72 |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
73 self.sock.settimeout(10) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
74 self.sock.setblocking(0) |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23793
diff
changeset
|
75 self.assertEqual(self.sock.gettimeout(), 0.0) |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
76 self.sock.setblocking(1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
77 self.assertEqual(self.sock.gettimeout(), None) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
78 |
|
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
79 def testBlockingThenTimeout(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
80 # Test setblocking() followed by settimeout() |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
81 self.sock.setblocking(0) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
82 self.sock.settimeout(1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
83 self.assertEqual(self.sock.gettimeout(), 1) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
84 |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
85 self.sock.setblocking(1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
86 self.sock.settimeout(1) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
87 self.assertEqual(self.sock.gettimeout(), 1) |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
88 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
90 class TimeoutTestCase(unittest.TestCase): |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
91 """Test case for socket.socket() timeout functions""" |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
92 |
|
28011
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
93 # There are a number of tests here trying to make sure that an operation |
|
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
94 # doesn't take too much longer than expected. But competing machine |
|
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
95 # activity makes it inevitable that such tests will fail at times. |
|
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
96 # When fuzz was at 1.0, I (tim) routinely saw bogus failures on Win2K |
|
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
97 # and Win98SE. Boosting it to 2.0 helped a lot, but isn't a real |
|
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
98 # solution. |
|
0eb948364990
Doubled TimeoutTestCase.fuzz, to slash the frequency of bogus failures
Tim Peters <tim.peters@gmail.com>
parents:
27912
diff
changeset
|
99 fuzz = 2.0 |
|
23791
cde6608739c4
Add some more basic tests to validate the argument checking of
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
100 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 def setUp(self): |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
102 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
38753
0acc52d3fbf1
Try to fix several networking tests. The problem is that if hosts have
Neal Norwitz <nnorwitz@gmail.com>
parents:
37768
diff
changeset
|
103 self.addr_remote = ('www.python.org.', 80) |
|
58739
13f695ab9111
Merged revisions 78014 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
46097
diff
changeset
|
104 self.localhost = '127.0.0.1' |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 def tearDown(self): |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
107 self.sock.close() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 def testConnectTimeout(self): |
|
46097
54b90d7eddb7
Try to get this test to be less flaky. It was failing sometimes because
Neal Norwitz <nnorwitz@gmail.com>
parents:
46019
diff
changeset
|
110 # Choose a private address that is unlikely to exist to prevent |
|
54b90d7eddb7
Try to get this test to be less flaky. It was failing sometimes because
Neal Norwitz <nnorwitz@gmail.com>
parents:
46019
diff
changeset
|
111 # failures due to the connect succeeding before the timeout. |
|
54b90d7eddb7
Try to get this test to be less flaky. It was failing sometimes because
Neal Norwitz <nnorwitz@gmail.com>
parents:
46019
diff
changeset
|
112 # Use a dotted IP address to avoid including the DNS lookup time |
|
46019
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
113 # with the connect time. This avoids failing the assertion that |
|
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
114 # the timeout occurred fast enough. |
|
46097
54b90d7eddb7
Try to get this test to be less flaky. It was failing sometimes because
Neal Norwitz <nnorwitz@gmail.com>
parents:
46019
diff
changeset
|
115 addr = ('10.0.0.0', 12345) |
|
46019
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
116 |
|
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
117 # Test connect() timeout |
|
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
118 _timeout = 0.001 |
|
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
119 self.sock.settimeout(_timeout) |
|
f4c50a51d24f
Try to make this test a little more robust and not fail with:
Neal Norwitz <nnorwitz@gmail.com>
parents:
38753
diff
changeset
|
120 |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 _t1 = time.time() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
46097
diff
changeset
|
122 self.assertRaises(socket.error, self.sock.connect, addr) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 _t2 = time.time() |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 _delta = abs(_t1 - _t2) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
46097
diff
changeset
|
126 self.assertTrue(_delta < _timeout + self.fuzz, |
|
32325
cf28f4a6e676
fix a poorly worded error message
Anthony Baxter <anthonybaxter@gmail.com>
parents:
28917
diff
changeset
|
127 "timeout (%g) is more than %g seconds more than expected (%g)" |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
128 %(_delta, self.fuzz, _timeout)) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 def testRecvTimeout(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
131 # Test recv() timeout |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 _timeout = 0.02 |
|
65720
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
133 |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
134 with test_support.transient_internet(self.addr_remote[0]): |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
135 self.sock.connect(self.addr_remote) |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
136 self.sock.settimeout(_timeout) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 |
|
65720
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
138 _t1 = time.time() |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
139 self.assertRaises(socket.timeout, self.sock.recv, 1024) |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
140 _t2 = time.time() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
65720
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
142 _delta = abs(_t1 - _t2) |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
143 self.assertTrue(_delta < _timeout + self.fuzz, |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
144 "timeout (%g) is %g seconds more than expected (%g)" |
|
f8d344849596
Merged revisions 85931 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58738
diff
changeset
|
145 %(_delta, self.fuzz, _timeout)) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 def testAcceptTimeout(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
148 # Test accept() timeout |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 _timeout = 2 |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
150 self.sock.settimeout(_timeout) |
|
58739
13f695ab9111
Merged revisions 78014 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
46097
diff
changeset
|
151 # Prevent "Address already in use" socket exceptions |
|
13f695ab9111
Merged revisions 78014 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
46097
diff
changeset
|
152 test_support.bind_port(self.sock, self.localhost) |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
153 self.sock.listen(5) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 _t1 = time.time() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
46097
diff
changeset
|
156 self.assertRaises(socket.error, self.sock.accept) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 _t2 = time.time() |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 _delta = abs(_t1 - _t2) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
46097
diff
changeset
|
160 self.assertTrue(_delta < _timeout + self.fuzz, |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
161 "timeout (%g) is %g seconds more than expected (%g)" |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
162 %(_delta, self.fuzz, _timeout)) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 def testRecvfromTimeout(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
165 # Test recvfrom() timeout |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 _timeout = 2 |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
167 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
168 self.sock.settimeout(_timeout) |
|
58739
13f695ab9111
Merged revisions 78014 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
46097
diff
changeset
|
169 # Prevent "Address already in use" socket exceptions |
|
13f695ab9111
Merged revisions 78014 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
46097
diff
changeset
|
170 test_support.bind_port(self.sock, self.localhost) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 _t1 = time.time() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
46097
diff
changeset
|
173 self.assertRaises(socket.error, self.sock.recvfrom, 8192) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 _t2 = time.time() |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 _delta = abs(_t1 - _t2) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
46097
diff
changeset
|
177 self.assertTrue(_delta < _timeout + self.fuzz, |
|
23793
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
178 "timeout (%g) is %g seconds more than expected (%g)" |
|
7cdc531e6a50
Docstring, layout and style tweaking. Increase fuzz to 1 second.
Guido van Rossum <guido@python.org>
parents:
23791
diff
changeset
|
179 %(_delta, self.fuzz, _timeout)) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 def testSend(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
182 # Test send() timeout |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 # couldn't figure out how to test it |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 pass |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 def testSendto(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
187 # Test sendto() timeout |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 # couldn't figure out how to test it |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 pass |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 def testSendall(self): |
|
24964
d90a6add7ca3
Standardize behavior: no docstrings in test functions.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
192 # Test sendall() timeout |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 # couldn't figure out how to test it |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 pass |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 |
|
27912
c5ebacbba0be
Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25106
diff
changeset
|
197 def test_main(): |
|
28112
2c8c2c6b2ab7
Fix SF bugs #692951 and 692988, test_timeout.py needs 'network' resource
Neal Norwitz <nnorwitz@gmail.com>
parents:
28011
diff
changeset
|
198 test_support.requires('network') |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28577
diff
changeset
|
199 test_support.run_unittest(CreationTestCase, TimeoutTestCase) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 |
|
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 if __name__ == "__main__": |
|
27912
c5ebacbba0be
Actually run these tests from regrtest.py.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25106
diff
changeset
|
202 test_main() |
