gunicorn/tests/test_sock.py
benoitc 062b48d8d2 lockfile improvements
- rename LockFile.lock  to acquire
- rename LockFile.unlock to release
- move the lockfile management in sepate functions inside the arbiter
- remove the "closed" argument from the socket.close method and add a new "destroy" function that will be called whent  the socket can be unlinked (cal release)
- fix tests
2016-05-15 02:30:08 +02:00

28 lines
764 B
Python

try:
import unittest.mock as mock
except ImportError:
import mock
from gunicorn import sock
@mock.patch('os.getpid')
@mock.patch('os.unlink')
@mock.patch('socket.fromfd')
def test_unix_socket_close_delete_if_exlock(fromfd, unlink, getpid):
gsock = sock.UnixSocket('test.sock', mock.Mock(), mock.Mock(), mock.Mock())
gsock.destroy()
unlink.assert_called_with('test.sock')
@mock.patch('os.getpid')
@mock.patch('os.unlink')
@mock.patch('socket.fromfd')
def test_unix_socket_not_deleted_by_worker(fromfd, unlink, getpid):
fd = mock.Mock()
gsock = sock.UnixSocket('test.sock', mock.Mock(), mock.Mock(), fd)
getpid.reset_mock()
getpid.return_value = "fake" # fake a pid change
gsock.destroy()
unlink.assert_not_called()