Skip to content

Commit

Permalink
Adds test_kill to buildslave tests
Browse files Browse the repository at this point in the history
Adds a unit test which ensures the process will receive SIGKILL if
SIGTERM fails to end the process.
  • Loading branch information
markberger committed Aug 10, 2013
1 parent dbb4781 commit 98f3c9f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions slave/buildslave/test/unit/test_runprocess.py
Expand Up @@ -18,6 +18,7 @@
import os
import time
import signal
from mock import Mock

from twisted.trial import unittest
from twisted.internet import task, defer, reactor
Expand Down Expand Up @@ -553,6 +554,46 @@ def check_dead(_):
runproc_d.addCallback(check_dead)
return defer.gatherResults([pidfile_d, runproc_d])

def test_kill(self, interruptSignal=None):

# Tests that the process will receive SIGKILL if SIGTERM
# is ignored.
pidfile = self.newPidfile()
self.pid = None
b = FakeSlaveBuilder(False, self.basedir)
s = runprocess.RunProcess(b,
scriptCommand('write_pidfile_and_sleep', pidfile),
self.basedir)
runproc_d = s.start()
pidfile_d = self.waitForPidfile(pidfile)

def check_alive(pid):
# Create a mock process that will ignore SIGTERM and only
# forward on the signal when we recieve SIGKILL
mock_process = Mock(wraps=s.process)
mock_process.pgid = None # Skips over group SIGTERM
process = s.process
def _mock_signalProcess(sig):
if sig == "TERM":
raise OSError
else:
process.signalProcess(sig)
mock_process.signalProcess = _mock_signalProcess
s.process = mock_process

self.pid = pid # for use in check_dead
# test that the process is still alive
self.assertAlive(pid)
# and tell the RunProcess object to kill it
s.kill("diaf")
pidfile_d.addCallback(check_alive)

def check_dead(_):
self.failUnlessEqual(s.killedBy, "KILL")
self.assertDead(self.pid)
runproc_d.addCallback(check_dead)
return defer.gatherResults([pidfile_d, runproc_d])

def test_pgroup_usePTY(self):
return self.do_test_pgroup(usePTY=True)

Expand Down

0 comments on commit 98f3c9f

Please sign in to comment.