浏览代码

Implemented stopasgroup with unit test

Roger Hoover 13 年之前
父节点
当前提交
0678782958
共有 2 个文件被更改,包括 27 次插入1 次删除
  1. 6 1
      supervisor/process.py
  2. 21 0
      supervisor/tests/test_process.py

+ 6 - 1
supervisor/process.py

@@ -351,7 +351,12 @@ class Subprocess:
             options.logger.debug(msg)
             return msg
 
-        killasgroup = self.config.killasgroup and sig == signal.SIGKILL
+        #If we're in the stopping state, then we've already sent the stop
+        #signal and this is the kill signal
+        if self.state == ProcessStates.STOPPING:
+            killasgroup = self.config.killasgroup
+        else:
+            killasgroup = self.config.stopasgroup
 
         as_group = ""
         if killasgroup:

+ 21 - 0
supervisor/tests/test_process.py

@@ -732,6 +732,27 @@ class SubprocessTests(unittest.TestCase):
         self.assertEqual(options.kills[-11], signal.SIGKILL)
         self.assertEqual(L, []) # no event because we didn't change state
 
+    def test_stopasgroup(self):
+        options = DummyOptions()
+        config = DummyPConfig(options, 'test', '/test', stopasgroup=True)
+        instance = self._makeOne(config)
+        instance.pid = 11
+        L = []
+        from supervisor.states import ProcessStates
+        from supervisor import events
+        events.subscribe(events.Event,lambda x: L.append(x))
+        instance.state = ProcessStates.RUNNING
+        instance.kill(signal.SIGTERM)
+        self.assertEqual(options.logger.data[0], 'killing test (pid 11) '
+                         'process group with signal SIGTERM')
+        self.assertEqual(instance.killing, 1)
+        self.assertEqual(options.kills[-11], signal.SIGTERM)
+        self.assertEqual(len(L), 1)
+        event = L[0]
+        self.assertEqual(event.__class__, events.ProcessStateStoppingEvent)
+        self.assertEqual(event.extra_values, [('pid', 11)])
+        self.assertEqual(event.from_state, ProcessStates.RUNNING)
+
     def test_finish(self):
         options = DummyOptions()
         config = DummyPConfig(options, 'notthere', '/notthere',