mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Track the use of systemd socket activation and gunicorn socket inheritance in the arbiter. Unify the logic of creating gunicorn sockets from each of these sources to always use the socket name to determine the type rather than checking the configured addresses. The configured addresses are only used when there is no inheritance from systemd or a parent arbiter. Fix #1298
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# -*- coding: utf-8 -
|
|
#
|
|
# This file is part of gunicorn released under the MIT license.
|
|
# See the NOTICE for more information.
|
|
|
|
try:
|
|
import unittest.mock as mock
|
|
except ImportError:
|
|
import mock
|
|
|
|
from gunicorn import sock
|
|
|
|
|
|
def test_socket_close():
|
|
listener1 = mock.Mock()
|
|
listener1.getsockname.return_value = ('127.0.0.1', '80')
|
|
listener2 = mock.Mock()
|
|
listener2.getsockname.return_value = ('192.168.2.5', '80')
|
|
sock.close_sockets([listener1, listener2])
|
|
listener1.close.assert_called_with()
|
|
listener2.close.assert_called_with()
|
|
|
|
|
|
@mock.patch('os.unlink')
|
|
def test_unix_socket_close_unlink(unlink):
|
|
listener = mock.Mock()
|
|
listener.getsockname.return_value = '/var/run/test.sock'
|
|
sock.close_sockets([listener])
|
|
listener.close.assert_called_with()
|
|
unlink.assert_called_once_with('/var/run/test.sock')
|
|
|
|
|
|
@mock.patch('os.unlink')
|
|
def test_unix_socket_close_without_unlink(unlink):
|
|
listener = mock.Mock()
|
|
listener.getsockname.return_value = '/var/run/test.sock'
|
|
sock.close_sockets([listener], False)
|
|
listener.close.assert_called_with()
|
|
assert not unlink.called, 'unlink should not have been called'
|