mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
This change add proper file locking to gunicorn. By default "gunicorn.lock" is created in the temporary directory when a unix socket is bound. In case someone want to fix the lock file path or use multiple gunicorn instance the "--lock-file" setting can be used to set the path of this file. fix #1259
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
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.close(False)
|
|
unlink.assert_called_with('test.sock')
|
|
|
|
|
|
@mock.patch('os.getpid')
|
|
@mock.patch('os.unlink')
|
|
@mock.patch('socket.fromfd')
|
|
def test_unix_socket_close_keep_if_no_exlock(fromfd, unlink, getpid):
|
|
gsock = sock.UnixSocket('test.sock', mock.Mock(), mock.Mock(), mock.Mock())
|
|
gsock.close(True)
|
|
unlink.assert_not_called()
|
|
|
|
|
|
@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.close(False)
|
|
unlink.assert_not_called()
|