Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e322024

Browse files
committed
Merged revisions 80434 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r80434 | antoine.pitrou | 2010-04-24 12:43:57 +0200 (sam., 24 avril 2010) | 5 lines Make test_makefile_close a networked test (can't read() from a non-connected socket under OS X), and skip it under Windows (where sockets can't be read() from using their fds). ........
1 parent cfcd8ad commit e322024

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,6 @@ def test_refcycle(self):
151151
del ss
152152
self.assertEqual(wr(), None)
153153

154-
def test_makefile_close(self):
155-
# Issue #5238: creating a file-like object with makefile() shouldn't
156-
# leak the underlying file descriptor.
157-
ss = ssl.wrap_socket(socket.socket(socket.AF_INET))
158-
fd = ss.fileno()
159-
f = ss.makefile()
160-
f.close()
161-
# The fd is still open
162-
os.read(fd, 0)
163-
# Closing the SSL socket should close the fd too
164-
ss.close()
165-
gc.collect()
166-
with self.assertRaises(OSError) as e:
167-
os.read(fd, 0)
168-
self.assertEqual(e.exception.errno, errno.EBADF)
169-
170154

171155
class NetworkedTests(unittest.TestCase):
172156

@@ -200,6 +184,25 @@ def testConnect(self):
200184
finally:
201185
s.close()
202186

187+
@unittest.skipIf(os.name == "nt", "Can't use a socket as a file under Windows")
188+
def test_makefile_close(self):
189+
# Issue #5238: creating a file-like object with makefile() shouldn't
190+
# delay closing the underlying "real socket" (here tested with its
191+
# file descriptor, hence skipping the test under Windows).
192+
ss = ssl.wrap_socket(socket.socket(socket.AF_INET))
193+
ss.connect(("svn.python.org", 443))
194+
fd = ss.fileno()
195+
f = ss.makefile()
196+
f.close()
197+
# The fd is still open
198+
os.read(fd, 0)
199+
# Closing the SSL socket should close the fd too
200+
ss.close()
201+
gc.collect()
202+
with self.assertRaises(OSError) as e:
203+
os.read(fd, 0)
204+
self.assertEqual(e.exception.errno, errno.EBADF)
205+
203206
def testNonBlockingHandshake(self):
204207
s = socket.socket(socket.AF_INET)
205208
s.connect(("svn.python.org", 443))

0 commit comments

Comments
 (0)