Skip to content

Commit

Permalink
Merge pull request #1 from boegel/runcmd_fix
Browse files Browse the repository at this point in the history
add unit test to check whether running commands that get killed are being handled correctly
  • Loading branch information
valtandor committed Nov 25, 2015
2 parents 2936b3b + a6f8170 commit 12f16c5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"""
import os
import re
import signal
from test.framework.utilities import EnhancedTestCase, init_config
from unittest import TestLoader, main
from vsc.utils.fancylogger import setLogLevelDebug, logToScreen
Expand All @@ -51,6 +52,29 @@ def test_run_cmd(self):
# no reason echo hello could fail
self.assertEqual(ec, 0)

def test_run_cmd_negative_exit_code(self):
"""Test run_cmd function with command that has negative exit code."""
# define signal handler to call in case run_cmd takes too long
def handler(signum, _):
raise RuntimeError("Signal handler called with signal %s" % signum)

# set the signal handler and a 3-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(3)

(_, ec) = run_cmd("kill -9 $$", log_ok=False)
self.assertEqual(ec, -9)

# reset the alarm
signal.alarm(0)
signal.alarm(3)

(_, ec) = run_cmd_qa("kill -9 $$", {}, log_ok=False)
self.assertEqual(ec, -9)

# disable the alarm
signal.alarm(0)

def test_run_cmd_bis(self):
"""More 'complex' test for run_cmd function."""
# a more 'complex' command to run, make sure all required output is there
Expand Down

0 comments on commit 12f16c5

Please sign in to comment.