def test_run_process_simple(self):
     """Test process successful termination causes a log message"""
     args = ['/bin/echo', 'hello']
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     process, = self.reactor.spawnedProcesses
     self.assertIsInstance(process.proto, schedulelib.ProcessProtocol)
     ## pylint: disable=protected-access
     self.assertIs(process._reactor, self.reactor)
     self.assertIs(process._executable, args[0])
     self.assertIs(process._args, args)
     self.assertIs(process._environment, os.environ)
     ## pylint: enable=protected-access
     terminate, kill = self.reactor.getDelayedCalls()
     self.assertTrue(terminate.active())
     self.assertEquals(terminate.getTime(), timeout)
     self.assertTrue(kill.active())
     self.assertEquals(kill.getTime(), timeout + grace)
     process.processEnded(0)
     self.assertFalse(terminate.active())
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = ('A process has ended without apparent errors: '
                'process finished with exit code 0.\n')
     self.assertEquals(output, message)
 def test_run_process_simple(self):
     """Test process successful termination causes a log message"""
     args = ["/bin/echo", "hello"]
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     process, = self.reactor.spawnedProcesses
     self.assertIsInstance(process.proto, schedulelib.ProcessProtocol)
     ## pylint: disable=protected-access
     self.assertIs(process._reactor, self.reactor)
     self.assertIs(process._executable, args[0])
     self.assertIs(process._args, args)
     self.assertIs(process._environment, os.environ)
     ## pylint: enable=protected-access
     terminate, kill = self.reactor.getDelayedCalls()
     self.assertTrue(terminate.active())
     self.assertEquals(terminate.getTime(), timeout)
     self.assertTrue(kill.active())
     self.assertEquals(kill.getTime(), timeout + grace)
     process.processEnded(0)
     self.assertFalse(terminate.active())
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = "A process has ended without apparent errors: " "process finished with exit code 0.\n"
     self.assertEquals(output, message)
 def test_run_process_pass_through_unexpected_fail(self):
     """Test that non-process-related failures fall through"""
     args = ['/bin/echo', 'hello']
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addErrback(results.append)
     deferred.errback(failure.Failure(ValueError("HAHA")))
     dummy, = results
 def test_run_process_pass_through_unexpected_fail(self):
     """Test that non-process-related failures fall through"""
     args = ["/bin/echo", "hello"]
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addErrback(results.append)
     deferred.errback(failure.Failure(ValueError("HAHA")))
     dummy, = results
 def test_run_process_failing(self):
     """Test process failure causes a log message"""
     args = ["/bin/echo", "hello"]
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     process, = self.reactor.spawnedProcesses
     terminate, kill = self.reactor.getDelayedCalls()
     process.processEnded(1)
     self.assertFalse(terminate.active())
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = "A process has ended with a probable error condition: " "process ended with exit code 1.\n"
     self.assertEquals(output, message)
 def test_run_process_failing(self):
     """Test process failure causes a log message"""
     args = ['/bin/echo', 'hello']
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     process, = self.reactor.spawnedProcesses
     terminate, kill = self.reactor.getDelayedCalls()
     process.processEnded(1)
     self.assertFalse(terminate.active())
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = ('A process has ended with a probable error condition: '
                'process ended with exit code 1.\n')
     self.assertEquals(output, message)
 def test_run_process_stuck_hard(self):
     """Test process gets KILL if TERM doesn't kill it"""
     args = ["/bin/echo", "hello"]
     timeout = 10
     grace = 0.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     dummy, = self.reactor.spawnedProcesses
     terminate, kill = self.reactor.getDelayedCalls()
     self.reactor.advance(10)
     self.assertFalse(terminate.active())
     self.assertTrue(kill.active())
     self.reactor.advance(0.7)
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = "A process has ended with a probable error condition: " "process ended with exit code 1.\n"
     self.assertEquals(output, message)
 def test_run_process_stuck(self):
     """Test process gets TERM if it does not end by itself"""
     args = ["/bin/echo", "hello"]
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     dummy, = self.reactor.spawnedProcesses
     terminate, kill = self.reactor.getDelayedCalls()
     self.reactor.advance(10)
     self.assertFalse(terminate.active())
     self.assertTrue(kill.active())
     self.reactor.advance(2)
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = "A process has ended without apparent errors: " "process finished with exit code 0.\n"
     self.assertEquals(output, message)
 def test_run_process_stuck_hard(self):
     """Test process gets KILL if TERM doesn't kill it"""
     args = ['/bin/echo', 'hello']
     timeout = 10
     grace = 0.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     dummy, = self.reactor.spawnedProcesses
     terminate, kill = self.reactor.getDelayedCalls()
     self.reactor.advance(10)
     self.assertFalse(terminate.active())
     self.assertTrue(kill.active())
     self.reactor.advance(0.7)
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = ('A process has ended with a probable error condition: '
                'process ended with exit code 1.\n')
     self.assertEquals(output, message)
 def test_run_process_stuck(self):
     """Test process gets TERM if it does not end by itself"""
     args = ['/bin/echo', 'hello']
     timeout = 10
     grace = 2.5
     results = []
     deferred = schedulelib.runProcess(args, timeout, grace, self.reactor)
     deferred.addCallback(results.append)
     dummy, = self.reactor.spawnedProcesses
     terminate, kill = self.reactor.getDelayedCalls()
     self.reactor.advance(10)
     self.assertFalse(terminate.active())
     self.assertTrue(kill.active())
     self.reactor.advance(2)
     self.assertFalse(kill.active())
     dummy, = results
     output = sys.stdout.getvalue()
     message = ('A process has ended without apparent errors: '
                'process finished with exit code 0.\n')
     self.assertEquals(output, message)