6
6
import tempfile
7
7
import shutil
8
8
9
+ from supervisor .states import ProcessStates
10
+ from supervisor .states import SupervisorStates
11
+
9
12
from supervisor .tests .base import DummyOptions
10
13
from supervisor .tests .base import DummyPConfig
11
14
from supervisor .tests .base import DummyPGroupConfig
@@ -188,7 +191,8 @@ def test_handle_sigterm(self):
188
191
options ._signal = signal .SIGTERM
189
192
supervisord = self ._makeOne (options )
190
193
supervisord .handle_signal ()
191
- self .assertEqual (supervisord .options .mood , - 1 )
194
+ self .assertEqual (supervisord .options .mood ,
195
+ SupervisorStates .SHUTDOWN )
192
196
self .assertEqual (options .logger .data [0 ],
193
197
'received SIGTERM indicating exit request' )
194
198
@@ -197,7 +201,8 @@ def test_handle_sigint(self):
197
201
options ._signal = signal .SIGINT
198
202
supervisord = self ._makeOne (options )
199
203
supervisord .handle_signal ()
200
- self .assertEqual (supervisord .options .mood , - 1 )
204
+ self .assertEqual (supervisord .options .mood ,
205
+ SupervisorStates .SHUTDOWN )
201
206
self .assertEqual (options .logger .data [0 ],
202
207
'received SIGINT indicating exit request' )
203
208
@@ -206,25 +211,44 @@ def test_handle_sigquit(self):
206
211
options ._signal = signal .SIGQUIT
207
212
supervisord = self ._makeOne (options )
208
213
supervisord .handle_signal ()
209
- self .assertEqual (supervisord .options .mood , - 1 )
214
+ self .assertEqual (supervisord .options .mood ,
215
+ SupervisorStates .SHUTDOWN )
210
216
self .assertEqual (options .logger .data [0 ],
211
217
'received SIGQUIT indicating exit request' )
212
218
213
- def test_handle_sighup (self ):
219
+ def test_handle_sighup_in_running_state (self ):
214
220
options = DummyOptions ()
215
221
options ._signal = signal .SIGHUP
216
222
supervisord = self ._makeOne (options )
223
+ self .assertEqual (supervisord .options .mood ,
224
+ SupervisorStates .RUNNING )
217
225
supervisord .handle_signal ()
218
- self .assertEqual (supervisord .options .mood , 0 )
226
+ self .assertEqual (supervisord .options .mood ,
227
+ SupervisorStates .RESTARTING )
219
228
self .assertEqual (options .logger .data [0 ],
220
229
'received SIGHUP indicating restart request' )
221
230
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
+
222
245
def test_handle_sigchld (self ):
223
246
options = DummyOptions ()
224
247
options ._signal = signal .SIGCHLD
225
248
supervisord = self ._makeOne (options )
226
249
supervisord .handle_signal ()
227
- self .assertEqual (supervisord .options .mood , 1 )
250
+ self .assertEqual (supervisord .options .mood ,
251
+ SupervisorStates .RUNNING )
228
252
# supervisor.options.signame(signal.SIGCHLD) may return "SIGCLD"
229
253
# on linux or other systems where SIGCHLD = SIGCLD.
230
254
msgs = ('received SIGCHLD indicating a child quit' ,
@@ -235,7 +259,6 @@ def test_handle_sigusr2(self):
235
259
options = DummyOptions ()
236
260
options ._signal = signal .SIGUSR2
237
261
pconfig1 = DummyPConfig (options , 'process1' , 'process1' ,'/bin/process1' )
238
- from supervisor .process import ProcessStates
239
262
process1 = DummyProcess (pconfig1 , state = ProcessStates .STOPPING )
240
263
process1 .delay = time .time () - 1
241
264
supervisord = self ._makeOne (options )
@@ -246,7 +269,8 @@ def test_handle_sigusr2(self):
246
269
dummypgroup = DummyProcessGroup (options )
247
270
supervisord .process_groups = {None :dummypgroup }
248
271
supervisord .handle_signal ()
249
- self .assertEqual (supervisord .options .mood , 1 )
272
+ self .assertEqual (supervisord .options .mood ,
273
+ SupervisorStates .RUNNING )
250
274
self .assertEqual (options .logs_reopened , True )
251
275
self .assertEqual (options .logger .data [0 ],
252
276
'received SIGUSR2 indicating log reopen request' )
@@ -257,12 +281,12 @@ def test_handle_unknown_signal(self):
257
281
options ._signal = signal .SIGUSR1
258
282
supervisord = self ._makeOne (options )
259
283
supervisord .handle_signal ()
260
- self .assertEqual (supervisord .options .mood , 1 )
284
+ self .assertEqual (supervisord .options .mood ,
285
+ SupervisorStates .RUNNING )
261
286
self .assertEqual (options .logger .data [0 ],
262
287
'received SIGUSR1 indicating nothing' )
263
288
264
289
def test_get_state (self ):
265
- from supervisor .states import SupervisorStates
266
290
options = DummyOptions ()
267
291
supervisord = self ._makeOne (options )
268
292
self .assertEqual (supervisord .get_state (), SupervisorStates .RUNNING )
@@ -683,7 +707,7 @@ def test_runforever_stopping_emits_events(self):
683
707
gconfig = DummyPGroupConfig (options )
684
708
pgroup = DummyProcessGroup (gconfig )
685
709
supervisord .process_groups = {'foo' : pgroup }
686
- supervisord .options .mood = - 1
710
+ supervisord .options .mood = SupervisorStates . SHUTDOWN
687
711
L = []
688
712
def callback (event ):
689
713
L .append (event )
@@ -708,7 +732,7 @@ def test_exit(self):
708
732
def callback ():
709
733
L .append (1 )
710
734
supervisord .process_groups = {'foo' : pgroup }
711
- supervisord .options .mood = 0
735
+ supervisord .options .mood = SupervisorStates . RESTARTING
712
736
supervisord .options .test = True
713
737
from supervisor .medusa import asyncore_25 as asyncore
714
738
self .assertRaises (asyncore .ExitNow , supervisord .runforever )
@@ -726,14 +750,13 @@ def test_exit_delayed(self):
726
750
def callback ():
727
751
L .append (1 )
728
752
supervisord .process_groups = {'foo' : pgroup }
729
- supervisord .options .mood = 0
753
+ supervisord .options .mood = SupervisorStates . RESTARTING
730
754
supervisord .options .test = True
731
755
supervisord .runforever ()
732
756
self .assertNotEqual (supervisord .lastshutdownreport , 0 )
733
757
734
758
def test_getSupervisorStateDescription (self ):
735
759
from supervisor .states import getSupervisorStateDescription
736
- from supervisor .states import SupervisorStates
737
760
result = getSupervisorStateDescription (SupervisorStates .RUNNING )
738
761
self .assertEqual (result , 'RUNNING' )
739
762
0 commit comments