Skip to content

Commit

Permalink
Adds test_sigterm and updates tests to reflect new parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
markberger committed Aug 24, 2013
1 parent c8162e8 commit 1c28dab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion master/buildbot/test/fake/remotecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class FakeRemoteShellCommand(FakeRemoteCommand):

def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1,
timeout=20*60, maxTime=None, logfiles={},
timeout=20*60, maxTime=None, sigtermTime=None, logfiles={},
usePTY="slave-config", logEnviron=True, collectStdout=False,
collectStderr=False,
interruptSignal=None, initialStdin=None, decodeRC={0:SUCCESS}):
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/test/interfaces/test_remotecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, remote_command, args, ignore_updates=False,
def test_signature_RemoteShellCommand_constructor(self):
@self.assertArgSpecMatches(self.remoteShellCommandClass.__init__)
def __init__(self, workdir, command, env=None, want_stdout=1,
want_stderr=1, timeout=20*60, maxTime=None, logfiles={},
want_stderr=1, timeout=20*60, maxTime=None, sigtermTime=None, logfiles={},
usePTY="slave-config", logEnviron=True, collectStdout=False,
collectStderr=False, interruptSignal=None, initialStdin=None,
decodeRC={0:SUCCESS}):
Expand Down
43 changes: 42 additions & 1 deletion slave/buildslave/test/unit/test_runprocess.py
Original file line number Diff line number Diff line change
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 @@ -511,7 +512,7 @@ def test_simple(self, interruptSignal=None):
scriptCommand('write_pidfile_and_sleep', pidfile),
self.basedir)
if interruptSignal is not None:
s.interruptSignal = interruptSignal
s.interruptSignals = [interruptSignal]
runproc_d = s.start()

pidfile_d = self.waitForPidfile(pidfile)
Expand All @@ -529,6 +530,46 @@ def check_dead(_):
runproc_d.addCallback(check_dead)
return defer.gatherResults([pidfile_d, runproc_d])

def test_sigterm(self, interruptSignal=None):

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

def check_alive(pid):
# Create a mock process that will check if we recieve SIGTERM
mock_process = Mock(wraps=s.process)
mock_process.pgid = None # Skips over group SIGTERM
mock_process.pid = pid
process = s.process
def _mock_signalProcess(sig):
if sig == "TERM":
self.receivedSIGTERM = True
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(self.receivedSIGTERM, True)
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 1c28dab

Please sign in to comment.