mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #1414 from benoitc/fix/1091-pidfile-eperm
Fix/1091 pidfile eperm
This commit is contained in:
commit
bd19be1b61
@ -75,6 +75,8 @@ class Pidfile(object):
|
|||||||
os.kill(wpid, 0)
|
os.kill(wpid, 0)
|
||||||
return wpid
|
return wpid
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
if e.args[0] == errno.EPERM:
|
||||||
|
return wpid
|
||||||
if e.args[0] == errno.ESRCH:
|
if e.args[0] == errno.ESRCH:
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
|
|||||||
59
tests/test_pidfile.py
Normal file
59
tests/test_pidfile.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# -*- coding: utf-8 -
|
||||||
|
#
|
||||||
|
# This file is part of gunicorn released under the MIT license.
|
||||||
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
|
import errno
|
||||||
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
import unittest.mock as mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
import gunicorn.pidfile
|
||||||
|
|
||||||
|
|
||||||
|
def builtin(name):
|
||||||
|
if sys.version_info >= (3, 0):
|
||||||
|
module = 'builtins'
|
||||||
|
else:
|
||||||
|
module = '__builtin__'
|
||||||
|
|
||||||
|
return '{0}.{1}'.format(module, name)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch(builtin('open'), new_callable=mock.mock_open)
|
||||||
|
def test_validate_no_file(_open):
|
||||||
|
pidfile = gunicorn.pidfile.Pidfile('test.pid')
|
||||||
|
_open.side_effect = IOError(errno.ENOENT)
|
||||||
|
assert pidfile.validate() is None
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch(builtin('open'), new_callable=mock.mock_open, read_data='1')
|
||||||
|
@mock.patch('os.kill')
|
||||||
|
def test_validate_file_pid_exists(kill, _open):
|
||||||
|
pidfile = gunicorn.pidfile.Pidfile('test.pid')
|
||||||
|
assert pidfile.validate() == 1
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch(builtin('open'), new_callable=mock.mock_open, read_data='a')
|
||||||
|
def test_validate_file_pid_malformed(_open):
|
||||||
|
pidfile = gunicorn.pidfile.Pidfile('test.pid')
|
||||||
|
assert pidfile.validate() is None
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch(builtin('open'), new_callable=mock.mock_open, read_data='1')
|
||||||
|
@mock.patch('os.kill')
|
||||||
|
def test_validate_file_pid_exists_kill_exception(kill, _open):
|
||||||
|
pidfile = gunicorn.pidfile.Pidfile('test.pid')
|
||||||
|
kill.side_effect = OSError(errno.EPERM)
|
||||||
|
assert pidfile.validate() == 1
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch(builtin('open'), new_callable=mock.mock_open, read_data='1')
|
||||||
|
@mock.patch('os.kill')
|
||||||
|
def test_validate_file_pid_does_not_exist(kill, _open):
|
||||||
|
pidfile = gunicorn.pidfile.Pidfile('test.pid')
|
||||||
|
kill.side_effect = OSError(errno.ESRCH)
|
||||||
|
assert pidfile.validate() is None
|
||||||
Loading…
x
Reference in New Issue
Block a user