Skip to content

Commit 089b4c3

Browse files
committed
Add test and changelog entry for Supervisor#1175, Supervisor#1176
1 parent 34b852d commit 089b4c3

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

CHANGES.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@
3838
same time. Specifying a log filename of ``syslog`` is still supported
3939
but deprecated. Patch by Jason R. Coombs.
4040

41-
- A more descriptive error message is now emitted if a name in the config
42-
file contains a disallowed character. Patch by Rick van Hattem.
41+
- Fixed a race condition where ``supervisord`` would cancel a shutdown
42+
already in progress if it received ``SIGHUP``. Now, ``supervisord`` will
43+
ignore ``SIGHUP`` if shutdown is already in progress. Patch by Livanh.
4344

4445
- Fixed a bug where searching for a relative command ignored changes to
4546
``PATH`` made in ``environment=``. Based on a patch by dongweiming.
4647

4748
- ``childutils.ProcessCommunicationsProtocol`` now does an explicit
4849
``flush()`` after writing to ``stdout``.
4950

51+
- A more descriptive error message is now emitted if a name in the config
52+
file contains a disallowed character. Patch by Rick van Hattem.
53+
5054
3.3.4 (2018-02-15)
5155
------------------
5256

supervisor/tests/test_supervisord.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import tempfile
77
import shutil
88

9+
from supervisor.states import ProcessStates
10+
from supervisor.states import SupervisorStates
11+
912
from supervisor.tests.base import DummyOptions
1013
from supervisor.tests.base import DummyPConfig
1114
from supervisor.tests.base import DummyPGroupConfig
@@ -188,7 +191,8 @@ def test_handle_sigterm(self):
188191
options._signal = signal.SIGTERM
189192
supervisord = self._makeOne(options)
190193
supervisord.handle_signal()
191-
self.assertEqual(supervisord.options.mood, -1)
194+
self.assertEqual(supervisord.options.mood,
195+
SupervisorStates.SHUTDOWN)
192196
self.assertEqual(options.logger.data[0],
193197
'received SIGTERM indicating exit request')
194198

@@ -197,7 +201,8 @@ def test_handle_sigint(self):
197201
options._signal = signal.SIGINT
198202
supervisord = self._makeOne(options)
199203
supervisord.handle_signal()
200-
self.assertEqual(supervisord.options.mood, -1)
204+
self.assertEqual(supervisord.options.mood,
205+
SupervisorStates.SHUTDOWN)
201206
self.assertEqual(options.logger.data[0],
202207
'received SIGINT indicating exit request')
203208

@@ -206,25 +211,44 @@ def test_handle_sigquit(self):
206211
options._signal = signal.SIGQUIT
207212
supervisord = self._makeOne(options)
208213
supervisord.handle_signal()
209-
self.assertEqual(supervisord.options.mood, -1)
214+
self.assertEqual(supervisord.options.mood,
215+
SupervisorStates.SHUTDOWN)
210216
self.assertEqual(options.logger.data[0],
211217
'received SIGQUIT indicating exit request')
212218

213-
def test_handle_sighup(self):
219+
def test_handle_sighup_in_running_state(self):
214220
options = DummyOptions()
215221
options._signal = signal.SIGHUP
216222
supervisord = self._makeOne(options)
223+
self.assertEqual(supervisord.options.mood,
224+
SupervisorStates.RUNNING)
217225
supervisord.handle_signal()
218-
self.assertEqual(supervisord.options.mood, 0)
226+
self.assertEqual(supervisord.options.mood,
227+
SupervisorStates.RESTARTING)
219228
self.assertEqual(options.logger.data[0],
220229
'received SIGHUP indicating restart request')
221230

231+
def test_handle_sighup_in_shutdown_state(self):
232+
options = DummyOptions()
233+
options._signal = signal.SIGHUP
234+
supervisord = self._makeOne(options)
235+
supervisord.options.mood = SupervisorStates.SHUTDOWN
236+
self.assertEqual(supervisord.options.mood,
237+
SupervisorStates.SHUTDOWN)
238+
supervisord.handle_signal()
239+
self.assertEqual(supervisord.options.mood,
240+
SupervisorStates.SHUTDOWN) # unchanged
241+
self.assertEqual(options.logger.data[0],
242+
'ignored SIGHUP indicating restart request '
243+
'(shutdown in progress)')
244+
222245
def test_handle_sigchld(self):
223246
options = DummyOptions()
224247
options._signal = signal.SIGCHLD
225248
supervisord = self._makeOne(options)
226249
supervisord.handle_signal()
227-
self.assertEqual(supervisord.options.mood, 1)
250+
self.assertEqual(supervisord.options.mood,
251+
SupervisorStates.RUNNING)
228252
# supervisor.options.signame(signal.SIGCHLD) may return "SIGCLD"
229253
# on linux or other systems where SIGCHLD = SIGCLD.
230254
msgs = ('received SIGCHLD indicating a child quit',
@@ -235,7 +259,6 @@ def test_handle_sigusr2(self):
235259
options = DummyOptions()
236260
options._signal = signal.SIGUSR2
237261
pconfig1 = DummyPConfig(options, 'process1', 'process1','/bin/process1')
238-
from supervisor.process import ProcessStates
239262
process1 = DummyProcess(pconfig1, state=ProcessStates.STOPPING)
240263
process1.delay = time.time() - 1
241264
supervisord = self._makeOne(options)
@@ -246,7 +269,8 @@ def test_handle_sigusr2(self):
246269
dummypgroup = DummyProcessGroup(options)
247270
supervisord.process_groups = {None:dummypgroup}
248271
supervisord.handle_signal()
249-
self.assertEqual(supervisord.options.mood, 1)
272+
self.assertEqual(supervisord.options.mood,
273+
SupervisorStates.RUNNING)
250274
self.assertEqual(options.logs_reopened, True)
251275
self.assertEqual(options.logger.data[0],
252276
'received SIGUSR2 indicating log reopen request')
@@ -257,12 +281,12 @@ def test_handle_unknown_signal(self):
257281
options._signal = signal.SIGUSR1
258282
supervisord = self._makeOne(options)
259283
supervisord.handle_signal()
260-
self.assertEqual(supervisord.options.mood, 1)
284+
self.assertEqual(supervisord.options.mood,
285+
SupervisorStates.RUNNING)
261286
self.assertEqual(options.logger.data[0],
262287
'received SIGUSR1 indicating nothing')
263288

264289
def test_get_state(self):
265-
from supervisor.states import SupervisorStates
266290
options = DummyOptions()
267291
supervisord = self._makeOne(options)
268292
self.assertEqual(supervisord.get_state(), SupervisorStates.RUNNING)
@@ -683,7 +707,7 @@ def test_runforever_stopping_emits_events(self):
683707
gconfig = DummyPGroupConfig(options)
684708
pgroup = DummyProcessGroup(gconfig)
685709
supervisord.process_groups = {'foo': pgroup}
686-
supervisord.options.mood = -1
710+
supervisord.options.mood = SupervisorStates.SHUTDOWN
687711
L = []
688712
def callback(event):
689713
L.append(event)
@@ -708,7 +732,7 @@ def test_exit(self):
708732
def callback():
709733
L.append(1)
710734
supervisord.process_groups = {'foo': pgroup}
711-
supervisord.options.mood = 0
735+
supervisord.options.mood = SupervisorStates.RESTARTING
712736
supervisord.options.test = True
713737
from supervisor.medusa import asyncore_25 as asyncore
714738
self.assertRaises(asyncore.ExitNow, supervisord.runforever)
@@ -726,14 +750,13 @@ def test_exit_delayed(self):
726750
def callback():
727751
L.append(1)
728752
supervisord.process_groups = {'foo': pgroup}
729-
supervisord.options.mood = 0
753+
supervisord.options.mood = SupervisorStates.RESTARTING
730754
supervisord.options.test = True
731755
supervisord.runforever()
732756
self.assertNotEqual(supervisord.lastshutdownreport, 0)
733757

734758
def test_getSupervisorStateDescription(self):
735759
from supervisor.states import getSupervisorStateDescription
736-
from supervisor.states import SupervisorStates
737760
result = getSupervisorStateDescription(SupervisorStates.RUNNING)
738761
self.assertEqual(result, 'RUNNING')
739762

0 commit comments

Comments
 (0)