def test_callFinishJobCallsFinishJobArbitraryFailure(self): # If the argument to callFinishJob indicates that there was some other # failure that had nothing to do with the subprocess, it records # failure. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob(makeFailure(RuntimeError)) self.assertEqual(calls, [CodeImportResultStatus.FAILURE]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobCallsFinishJobArbitraryFailure(self): # If the argument to callFinishJob indicates that there was some other # failure that had nothing to do with the subprocess, it records # failure. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob(makeFailure(RuntimeError)) self.assertEqual(calls, [CodeImportResultStatus.FAILURE]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobLogsTracebackOnFailure(self): # When callFinishJob is called with a failure, it dumps the traceback # of the failure into the log file. self.layer.force_dirty_database() worker_monitor = self.makeWorkerMonitorWithJob() ret = worker_monitor.callFinishJob(makeFailure(RuntimeError)) def check_log_file(ignored): worker_monitor._log_file.seek(0) log_text = worker_monitor._log_file.read() self.assertIn('Traceback (most recent call last)', log_text) self.assertIn('RuntimeError', log_text) return ret.addCallback(check_log_file)
def test_unexpectedError(self): """The puller master logs an OOPS when it receives an unexpected error. """ fail = makeFailure(RuntimeError, 'error message') self.eventHandler.unexpectedError(fail) oops = self.oopses[-1] self.assertEqual(fail.getTraceback(), oops['tb_text']) self.assertEqual('error message', oops['value']) self.assertEqual('RuntimeError', oops['type']) self.assertEqual( get_canonical_url_for_branch_name( self.eventHandler.unique_name), oops['url'])
def test_unexpectedError(self): """The puller master logs an OOPS when it receives an unexpected error. """ fail = makeFailure(RuntimeError, 'error message') self.eventHandler.unexpectedError(fail) oops = self.oopses[-1] self.assertEqual(fail.getTraceback(), oops['tb_text']) self.assertEqual('error message', oops['value']) self.assertEqual('RuntimeError', oops['type']) self.assertEqual( get_canonical_url_for_branch_name( self.eventHandler.unique_name), oops['url'])
def test_callFinishJobCallsFinishJobInvalid(self): # If the argument to callFinishJob indicates that the subprocess # exited with a code of CodeImportWorkerExitCode.FAILURE_INVALID, it # calls finishJob with a status of FAILURE_INVALID. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob( makeFailure(error.ProcessTerminated, exitCode=CodeImportWorkerExitCode.FAILURE_INVALID)) self.assertEqual(calls, [CodeImportResultStatus.FAILURE_INVALID]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobCallsFinishJobSuccessNoChange(self): # If the argument to callFinishJob indicates that the subprocess # exited with a code of CodeImportWorkerExitCode.SUCCESS_NOCHANGE, it # calls finishJob with a status of SUCCESS_NOCHANGE. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob( makeFailure(error.ProcessTerminated, exitCode=CodeImportWorkerExitCode.SUCCESS_NOCHANGE)) self.assertEqual(calls, [CodeImportResultStatus.SUCCESS_NOCHANGE]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobCallsFinishJobUnsupportedFeature(self): # If the argument to callFinishJob indicates that the subprocess # exited with a code of FAILURE_UNSUPPORTED_FEATURE, it # calls finishJob with a status of FAILURE_UNSUPPORTED_FEATURE. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob(makeFailure( error.ProcessTerminated, exitCode=CodeImportWorkerExitCode.FAILURE_UNSUPPORTED_FEATURE)) self.assertEqual( calls, [CodeImportResultStatus.FAILURE_UNSUPPORTED_FEATURE]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobCallsFinishJobPartial(self): # If the argument to callFinishJob indicates that the subprocess # exited with a code of CodeImportWorkerExitCode.SUCCESS_PARTIAL, it # calls finishJob with a status of SUCCESS_PARTIAL. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob( makeFailure( error.ProcessTerminated, exitCode=CodeImportWorkerExitCode.SUCCESS_PARTIAL)) self.assertEqual(calls, [CodeImportResultStatus.SUCCESS_PARTIAL]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobLogsTracebackOnFailure(self): # When callFinishJob is called with a failure, it dumps the traceback # of the failure into the log file. self.layer.force_dirty_database() worker_monitor = self.makeWorkerMonitorWithJob() ret = worker_monitor.callFinishJob(makeFailure(RuntimeError)) def check_log_file(ignored): worker_monitor._log_file.seek(0) log_text = worker_monitor._log_file.read() self.assertIn('Traceback (most recent call last)', log_text) self.assertIn('RuntimeError', log_text) return ret.addCallback(check_log_file)
def test_callFinishJobCallsFinishJobFailure(self): # callFinishJob calls finishJob with CodeImportResultStatus.FAILURE # and swallows the failure if its argument indicates that the # subprocess exited with an exit code of # CodeImportWorkerExitCode.FAILURE. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob( makeFailure(error.ProcessTerminated, exitCode=CodeImportWorkerExitCode.FAILURE)) self.assertEqual(calls, [CodeImportResultStatus.FAILURE]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_callFinishJobCallsFinishJobFailure(self): # callFinishJob calls finishJob with CodeImportResultStatus.FAILURE # and swallows the failure if its argument indicates that the # subprocess exited with an exit code of # CodeImportWorkerExitCode.FAILURE. worker_monitor = self.makeWorkerMonitorWithJob() calls = self.patchOutFinishJob(worker_monitor) ret = worker_monitor.callFinishJob( makeFailure( error.ProcessTerminated, exitCode=CodeImportWorkerExitCode.FAILURE)) self.assertEqual(calls, [CodeImportResultStatus.FAILURE]) # We return the deferred that callFinishJob returns -- if # callFinishJob did not swallow the error, this will fail the test. return ret
def test_errorBeforeStatusReportAndFailingMirrorFailed(self): # If the subprocess exits before reporting success or failure, *and* # the attempt to record failure fails, there's not much we can do but # we should still not hang. In keeping with the general policy, we # fire the termination deferred with the first thing to go wrong -- # the process termination in this case -- and log.err() the failed # attempt to call mirrorFailed(). runtime_error_failure = makeFailure(RuntimeError) class FailingMirrorFailedStubPullerListener(self.StubPullerListener): def mirrorFailed(self, message, oops): return runtime_error_failure self.protocol.listener = FailingMirrorFailedStubPullerListener() self.listener = self.protocol.listener self.protocol.errReceived('traceback') self.simulateProcessExit(clean=False) self.assertEqual( flush_logged_errors(RuntimeError), [runtime_error_failure]) return assert_fails_with( self.termination_deferred, error.ProcessTerminated)
def test_errorBeforeStatusReportAndFailingMirrorFailed(self): # If the subprocess exits before reporting success or failure, *and* # the attempt to record failure fails, there's not much we can do but # we should still not hang. In keeping with the general policy, we # fire the termination deferred with the first thing to go wrong -- # the process termination in this case -- and log.err() the failed # attempt to call mirrorFailed(). runtime_error_failure = makeFailure(RuntimeError) class FailingMirrorFailedStubPullerListener(self.StubPullerListener): def mirrorFailed(self, message, oops): return runtime_error_failure self.protocol.listener = FailingMirrorFailedStubPullerListener() self.listener = self.protocol.listener self.protocol.errReceived('traceback') self.simulateProcessExit(clean=False) self.assertEqual( flush_logged_errors(RuntimeError), [runtime_error_failure]) return assert_fails_with( self.termination_deferred, error.ProcessTerminated)