gunicorn/tests/test_sock.py
Roy Williams b4c41481e2 Fix leak of duplicate file descriptor for bound sockets.
`socket.fromfd` does not close the original file descriptor, so we have to explicitly close it to avoid a leak.

See also:
http://bugs.python.org/issue10099
2016-10-18 00:15:40 +03:00

19 lines
452 B
Python

try:
import unittest.mock as mock
except ImportError:
import mock
from gunicorn import sock
@mock.patch('os.close')
@mock.patch('os.getpid')
@mock.patch('os.unlink')
@mock.patch('socket.fromfd')
def test_unix_socket_close_unlink(fromfd, unlink, getpid, close):
fd = 42
gsock = sock.UnixSocket('test.sock', mock.Mock(), mock.Mock(), fd=fd)
gsock.close()
unlink.assert_called_with("test.sock")
close.assert_called_with(fd)