def test_retry_after_timeout(self):
        """
        If a timeout happens, one can retry to consume message from the queue
        later on.
        """
        yield self.manager.connected((self.client, self.channel))
        yield self.channel.queue_declare(queue=self.queue_prefix + "uuid1")

        reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d1 = self.manager.get_message("uuid1", "0")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d1, Timeout)

        # Let's wrap the queue again
        reply = yield self.client.queue(self.tag_prefix + "uuid1.1")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d2 = self.manager.get_message("uuid1", "1")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d2, Timeout)
    def test_retry_after_timeout(self):
        """
        If a timeout happens, one can retry to consume message from the queue
        later on.
        """
        yield self.manager.connected((self.client, self.channel))
        yield self.channel.queue_declare(
            queue=self.queue_prefix + "uuid1")

        reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d1 = self.manager.get_message("uuid1", "0")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d1, Timeout)

        # Let's wrap the queue again
        reply = yield self.client.queue(self.tag_prefix + "uuid1.1")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d2 = self.manager.get_message("uuid1", "1")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d2, Timeout)
Example #3
0
 def test_makeDirectoryError(self):
     # Errors in makeDirectory are translated into SFTPErrors.
     nonexistent = self.getPathSegment()
     nonexistent_child = '%s/%s' % (nonexistent, self.getPathSegment())
     deferred = self.sftp_server.makeDirectory(nonexistent_child,
                                               {'permissions': 0777})
     return assert_fails_with(deferred, filetransfer.SFTPError)
 def test_getWorkerArguments_arbitrary_fault_raises(self):
     # When getImportDataForJobID signals an arbitrary fault, it is not
     # handled in any special way by getWorkerArguments.
     worker_monitor = self.makeWorkerMonitorWithoutJob(
         exception=xmlrpc.Fault(1, ''))
     return assert_fails_with(
         worker_monitor.getWorkerArguments(), xmlrpc.Fault)
 def test_run_process_with_timeout_timeout(self):
     # On process timeout, the errback is fired with `TimeoutError`
     # failure.
     clock = task.Clock()
     d = run_process_with_timeout(('sleep', '2'), timeout=1, clock=clock)
     clock.advance(2)
     return assert_fails_with(d, error.TimeoutError)
 def test_getWorkerArguments_endpoint_failure_raises(self):
     # When getImportDataForJobID raises an arbitrary exception, it is not
     # handled in any special way by getWorkerArguments.
     worker_monitor = self.makeWorkerMonitorWithoutJob(
         exception=ZeroDivisionError())
     return assert_fails_with(
         worker_monitor.getWorkerArguments(), ZeroDivisionError)
Example #7
0
 def test_writeChunkOnDirectory(self):
     # Errors in writeChunk are translated to SFTPErrors.
     directory = self.getPathSegment()
     os.mkdir(directory)
     deferred = self.openFile(directory, filetransfer.FXF_WRITE, {})
     deferred.addCallback(lambda handle: handle.writeChunk(0, 'bar'))
     return assert_fails_with(deferred, filetransfer.SFTPError)
Example #8
0
 def test_getAttrsError(self):
     # Errors in getAttrs on TransportSFTPFile are translated into
     # SFTPErrors.
     filename = self.getPathSegment()
     deferred = self.openFile(filename, 0, {})
     deferred.addCallback(lambda handle: handle.getAttrs())
     return assert_fails_with(deferred, filetransfer.SFTPError)
Example #9
0
 def test_getAttrsError(self):
     # Errors in getAttrs on TransportSFTPFile are translated into
     # SFTPErrors.
     filename = self.getPathSegment()
     deferred = self.openFile(filename, 0, {})
     deferred.addCallback(lambda handle: handle.getAttrs())
     return assert_fails_with(deferred, filetransfer.SFTPError)
Example #10
0
 def test_writeChunkOnDirectory(self):
     # Errors in writeChunk are translated to SFTPErrors.
     directory = self.getPathSegment()
     os.mkdir(directory)
     deferred = self.openFile(directory, filetransfer.FXF_WRITE, {})
     deferred.addCallback(lambda handle: handle.writeChunk(0, 'bar'))
     return assert_fails_with(deferred, filetransfer.SFTPError)
    def test_get_message_during_error(self):
        """
        If an error occurs in C{get_message}, other C{get_message} calls don't
        fail, and are retried on reconnection instead.
        """
        self.factory.initialDelay = 0.1
        self.factory.resetDelay()
        self.amq_disconnected = self.manager.disconnected
        yield self.manager.connected((self.client, self.channel))
        yield self.channel.queue_declare(
            queue=self.queue_prefix + "uuid1")
        content = Content("some content")

        reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d1 = self.manager.get_message("uuid1", "0")
        yield event_queue.get()

        d2 = self.manager.get_message("uuid_unknown", "0")

        yield assert_fails_with(d2, NotFound)
        self.assertTrue(self.channel.closed)

        self.connected_deferred = Deferred()
        yield self.connected_deferred

        yield self.manager.connected((self.client, self.channel))
        yield self.channel.basic_publish(
            routing_key=self.queue_prefix + "uuid1",
            content=content)

        message = yield d1
        self.assertEquals(message[0], "some content")
Example #12
0
 def test_makeDirectoryError(self):
     # Errors in makeDirectory are translated into SFTPErrors.
     nonexistent = self.getPathSegment()
     nonexistent_child = '%s/%s' % (nonexistent, self.getPathSegment())
     deferred = self.sftp_server.makeDirectory(
         nonexistent_child, {'permissions': 0777})
     return assert_fails_with(deferred, filetransfer.SFTPError)
    def test_ack_message(self):
        """
        C{ack_message} confirms the removal of a message from the queue, making
        subsequent C{get_message} calls waiting for another message.
        """
        yield self.manager.connected((self.client, self.channel))
        yield self.channel.queue_declare(
            queue=self.queue_prefix + "uuid1")
        content = Content("some content")

        yield self.channel.basic_publish(
            routing_key=self.queue_prefix + "uuid1",
            content=content)
        message, tag = yield self.manager.get_message("uuid1", "0")
        yield self.manager.ack_message(tag)

        reply = yield self.client.queue(self.tag_prefix + "uuid1.1")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d = self.manager.get_message("uuid1", "1")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d, Timeout)
Example #14
0
 def test_getWorkerArguments_job_not_found_raises_exit_quietly(self):
     # When getImportDataForJobID signals a fault indicating that
     # getWorkerArguments didn't find the supplied job, getWorkerArguments
     # translates this to an 'ExitQuietly' exception.
     worker_monitor = self.makeWorkerMonitorWithoutJob()
     return assert_fails_with(worker_monitor.getWorkerArguments(),
                              ExitQuietly)
 def test_getWorkerArguments_job_not_found_raises_exit_quietly(self):
     # When getImportDataForJobID signals a fault indicating that
     # getWorkerArguments didn't find the supplied job, getWorkerArguments
     # translates this to an 'ExitQuietly' exception.
     worker_monitor = self.makeWorkerMonitorWithoutJob()
     return assert_fails_with(
         worker_monitor.getWorkerArguments(), ExitQuietly)
Example #16
0
 def test_getWorkerArguments_endpoint_failure_raises(self):
     # When getImportDataForJobID raises an arbitrary exception, it is not
     # handled in any special way by getWorkerArguments.
     worker_monitor = self.makeWorkerMonitorWithoutJob(
         exception=ZeroDivisionError())
     return assert_fails_with(worker_monitor.getWorkerArguments(),
                              ZeroDivisionError)
    def test_get_message_during_error(self):
        """
        If an error occurs in C{get_message}, other C{get_message} calls don't
        fail, and are retried on reconnection instead.
        """
        self.factory.initialDelay = 0.1
        self.factory.resetDelay()
        self.amq_disconnected = self.manager.disconnected
        yield self.manager.connected((self.client, self.channel))
        yield self.channel.queue_declare(queue=self.queue_prefix + "uuid1")
        content = Content("some content")

        reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d1 = self.manager.get_message("uuid1", "0")
        yield event_queue.get()

        d2 = self.manager.get_message("uuid_unknown", "0")

        yield assert_fails_with(d2, NotFound)
        self.assertTrue(self.channel.closed)

        self.connected_deferred = Deferred()
        yield self.connected_deferred

        yield self.manager.connected((self.client, self.channel))
        yield self.channel.basic_publish(routing_key=self.queue_prefix +
                                         "uuid1",
                                         content=content)

        message = yield d1
        self.assertEquals(message[0], "some content")
Example #18
0
 def test_getWorkerArguments_arbitrary_fault_raises(self):
     # When getImportDataForJobID signals an arbitrary fault, it is not
     # handled in any special way by getWorkerArguments.
     worker_monitor = self.makeWorkerMonitorWithoutJob(
         exception=xmlrpc.Fault(1, ''))
     return assert_fails_with(worker_monitor.getWorkerArguments(),
                              xmlrpc.Fault)
Example #19
0
 def test_getClientFor_errors_when_no_connections(self):
     service = RegionService(sentinel.ipcWorker)
     service.connections.clear()
     return assert_fails_with(
         service.getClientFor(factory.make_UUID(), timeout=0),
         exceptions.NoConnectionsAvailable,
     )
Example #20
0
 def test_resumeSlaveHost_command_failed(self):
     reset_fail_config = """
         [builddmaster]
         vm_resume_command: /bin/false"""
     config.push('reset fail', reset_fail_config)
     self.addCleanup(config.pop, 'reset fail')
     d = self.resumeSlaveHost(MockBuilder(virtualized=True, vm_host="pop"))
     return assert_fails_with(d, CannotResumeHost)
 def test_prematureFailureWithoutStderr(self):
     # If the worker dies without reporting failure and doesn't have any
     # output on standard error, then we report failure using the reason we
     # have for the worker's death.
     self.protocol.do_startMirroring()
     self.simulateProcessExit(clean=False)
     return assert_fails_with(self.termination_deferred,
                              error.ProcessTerminated)
 def test_prematureFailureWithoutStderr(self):
     # If the worker dies without reporting failure and doesn't have any
     # output on standard error, then we report failure using the reason we
     # have for the worker's death.
     self.protocol.do_startMirroring()
     self.simulateProcessExit(clean=False)
     return assert_fails_with(
         self.termination_deferred, error.ProcessTerminated)
Example #23
0
    def test__raises_exception_if_nodegroup_doesnt_exist(self):
        uuid = factory.make_UUID()

        d = call_responder(
            Region(), ListNodePowerParameters,
            {'uuid': uuid})

        return assert_fails_with(d, NoSuchCluster)
Example #24
0
    def assertFailure(self, deferred, exception):
        """
        ``twisted.trial.unittest.TestCase.assertFailure``-alike.

        This is not completely compatible.  ``assert_fails_with`` should be
        preferred for new code.
        """
        return assert_fails_with(deferred, exception)
 def test_unexpectedError(self):
     # unexpectedError() sends SIGINT to the child process but the
     # termination deferred is fired with originally passed-in failure.
     self.protocol.unexpectedError(
         makeFailure(RuntimeError, 'error message'))
     self.assertEqual([('signalProcess', 'INT')],
                      self.protocol.transport.calls)
     return assert_fails_with(self.termination_deferred, RuntimeError)
 def test_run_process_with_timeout_timeout(self):
     # On process timeout, the errback is fired with `TimeoutError`
     # failure.
     clock = task.Clock()
     d = run_process_with_timeout(
         ('sleep', '2'), timeout=1, clock=clock)
     clock.advance(2)
     return assert_fails_with(d, error.TimeoutError)
Example #27
0
    def assertFailure(self, deferred, exception):
        """
        ``twisted.trial.unittest.TestCase.assertFailure``-alike.

        This is not completely compatible.  ``assert_fails_with`` should be
        preferred for new code.
        """
        return assert_fails_with(deferred, exception)
 def test_pendingNotificationFails(self):
     # If the process exits cleanly while a notification is pending and the
     # notification subsequently fails, the notification's failure is
     # passed on to the termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda: deferred)
     self.simulateProcessExit()
     deferred.errback(makeFailure(RuntimeError))
     return assert_fails_with(self.termination_deferred, RuntimeError)
 def test_scan_of_broken_slave(self):
     builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
     self._resetBuilder(builder)
     self.patch(BuilderSlave, 'makeBuilderSlave', FakeMethod(BrokenSlave()))
     builder.failure_count = 0
     transaction.commit()
     scanner = self._getScanner(builder_name=builder.name)
     d = scanner.scan()
     return assert_fails_with(d, xmlrpclib.Fault)
Example #30
0
    def assertSFTPError(self, sftp_code, function, *args, **kwargs):
        """Assert that calling functions fails with `sftp_code`."""
        deferred = defer.maybeDeferred(function, *args, **kwargs)
        deferred = assert_fails_with(deferred, filetransfer.SFTPError)

        def check_sftp_code(exception):
            self.assertEqual(sftp_code, exception.code)
            return exception

        return deferred.addCallback(check_sftp_code)
 def test_pendingNotificationFails(self):
     # If the process exits cleanly while a notification is pending and the
     # notification subsequently fails, the notification's failure is
     # passed on to the termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda : deferred)
     self.simulateProcessExit()
     deferred.errback(makeFailure(RuntimeError))
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
 def test_unexpectedError(self):
     # unexpectedError() sends SIGINT to the child process but the
     # termination deferred is fired with originally passed-in failure.
     self.protocol.unexpectedError(
         makeFailure(RuntimeError, 'error message'))
     self.assertEqual(
         [('signalProcess', 'INT')],
         self.protocol.transport.calls)
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
Example #33
0
    def assertSFTPError(self, sftp_code, function, *args, **kwargs):
        """Assert that calling functions fails with `sftp_code`."""
        deferred = defer.maybeDeferred(function, *args, **kwargs)
        deferred = assert_fails_with(deferred, filetransfer.SFTPError)

        def check_sftp_code(exception):
            self.assertEqual(sftp_code, exception.code)
            return exception

        return deferred.addCallback(check_sftp_code)
 def test_scan_of_broken_slave(self):
     builder = getUtility(IBuilderSet)[BOB_THE_BUILDER_NAME]
     self._resetBuilder(builder)
     self.patch(
         BuilderSlave, 'makeBuilderSlave', FakeMethod(BrokenSlave()))
     builder.failure_count = 0
     transaction.commit()
     scanner = self._getScanner(builder_name=builder.name)
     d = scanner.scan()
     return assert_fails_with(d, xmlrpclib.Fault)
    def test_runNotificationFailure(self):
        # If a notification function fails, the child process is killed and
        # the manner of failure reported.
        def fail():
            raise RuntimeError

        self.protocol.runNotification(fail)
        self.assertEqual([('signalProcess', 'INT')],
                         self.protocol.transport.calls)
        return assert_fails_with(self.termination_deferred, RuntimeError)
 def test_get_message_after_error(self):
     """
     If an error occurs in C{get_message}, the transport is closed so that
     we can query messages again.
     """
     yield self.manager.connected((self.client, self.channel))
     d = self.manager.get_message("uuid_unknown", "0")
     yield assert_fails_with(d, NotFound)
     self.assertTrue(self.channel.closed)
     yield deferLater(reactor, 0.1, lambda: None)
     self.assertTrue(self.client.transport.disconnected)
 def test_errorBeforeStatusReport(self):
     # If the subprocess exits before reporting success or failure, the
     # puller master should record failure.
     self.protocol.do_startMirroring()
     self.protocol.errReceived('traceback')
     self.simulateProcessExit(clean=False)
     self.assertEqual(
         self.listener.calls,
         ['startMirroring', ('mirrorFailed', 'traceback', None)])
     return assert_fails_with(self.termination_deferred,
                              error.ProcessTerminated)
 def test_errorBeforeStatusReport(self):
     # If the subprocess exits before reporting success or failure, the
     # puller master should record failure.
     self.protocol.do_startMirroring()
     self.protocol.errReceived('traceback')
     self.simulateProcessExit(clean=False)
     self.assertEqual(
         self.listener.calls,
         ['startMirroring', ('mirrorFailed', 'traceback', None)])
     return assert_fails_with(
         self.termination_deferred, error.ProcessTerminated)
    def test_mirrorFailedDoesNotResetTimeout(self):
        """Receiving 'mirrorFailed' doesn't reset the timeout.

        mirrorFailed doesn't reset the timeout for the same reasons as
        mirrorSucceeded.
        """
        self.protocol.do_startMirroring()
        self.clock.advance(config.supermirror.worker_timeout - 1)
        self.protocol.do_mirrorFailed('error message', 'OOPS')
        self.clock.advance(2)
        return assert_fails_with(self.termination_deferred, error.TimeoutError)
Example #40
0
 def test_dispatchBuildToSlave_nochroot(self):
     # dispatchBuildToSlave will fail when there is not chroot tarball
     # available for the distroseries to build for.
     job = self.makeJob()
     #test_publisher = SoyuzTestPublisher()
     builder = MockBuilder("bob-de-bouwer")
     builder.processor = getUtility(IProcessorSet).getByName('386')
     job.setBuilder(builder, OkSlave())
     logger = BufferLogger()
     d = defer.maybeDeferred(job.dispatchBuildToSlave, "someid", logger)
     return assert_fails_with(d, CannotBuild)
 def test_get_message_after_error(self):
     """
     If an error occurs in C{get_message}, the transport is closed so that
     we can query messages again.
     """
     yield self.manager.connected((self.client, self.channel))
     d = self.manager.get_message("uuid_unknown", "0")
     yield assert_fails_with(d, NotFound)
     self.assertTrue(self.channel.closed)
     yield deferLater(reactor, 0.1, lambda: None)
     self.assertTrue(self.client.transport.disconnected)
 def test_runNotificationFailure(self):
     # If a notification function fails, the child process is killed and
     # the manner of failure reported.
     def fail():
         raise RuntimeError
     self.protocol.runNotification(fail)
     self.assertEqual(
         [('signalProcess', 'INT')],
         self.protocol.transport.calls)
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
    def assertFiresFailure(self, exception, function, *args, **kwargs):
        """Assert that calling `function` will cause `exception` to be fired.

        In the synchronous tests, this means that `function` raises
        `exception`. In the asynchronous tests, `function` returns a Deferred
        that fires `exception` as a Failure.

        :return: A `Deferred`. You must return this from your test.
        """
        return assert_fails_with(
            self._ensureDeferred(function, *args, **kwargs), exception)
 def test_dispatchBuildToSlave_nochroot(self):
     # dispatchBuildToSlave will fail when there is not chroot tarball
     # available for the distroseries to build for.
     job = self.makeJob()
     # test_publisher = SoyuzTestPublisher()
     builder = MockBuilder("bob-de-bouwer")
     builder.processor = getUtility(IProcessorSet).getByName("386")
     job.setBuilder(builder, OkSlave())
     logger = BufferLogger()
     d = defer.maybeDeferred(job.dispatchBuildToSlave, "someid", logger)
     return assert_fails_with(d, CannotBuild)
    def assertFiresFailure(self, exception, function, *args, **kwargs):
        """Assert that calling `function` will cause `exception` to be fired.

        In the synchronous tests, this means that `function` raises
        `exception`. In the asynchronous tests, `function` returns a Deferred
        that fires `exception` as a Failure.

        :return: A `Deferred`. You must return this from your test.
        """
        return assert_fails_with(
            self._ensureDeferred(function, *args, **kwargs), exception)
Example #46
0
 def test_resetOrFail_resume_failure(self):
     reset_fail_config = """
         [builddmaster]
         vm_resume_command: /bin/false"""
     config.push('reset fail', reset_fail_config)
     self.addCleanup(config.pop, 'reset fail')
     builder = MockBuilder(virtualized=True, vm_host="pop", builderok=True)
     vitals = extract_vitals_from_db(builder)
     d = BuilderInteractor.resetOrFail(
         vitals, BuilderInteractor.makeSlaveFromVitals(vitals), builder,
         DevNullLogger(), Exception())
     return assert_fails_with(d, CannotResumeHost)
 def test_unexpectedErrorAndNotificationFailure(self):
     # If unexpectedError is called while a notification is pending and the
     # notification subsequently fails, the first failure "wins" and is
     # passed on to the termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda: deferred)
     self.protocol.unexpectedError(makeFailure(TypeError))
     runtime_error_failure = makeFailure(RuntimeError)
     deferred.errback(runtime_error_failure)
     self.assertEqual(flush_logged_errors(RuntimeError),
                      [runtime_error_failure])
     return assert_fails_with(self.termination_deferred, TypeError)
    def test_mirrorFailedDoesNotResetTimeout(self):
        """Receiving 'mirrorFailed' doesn't reset the timeout.

        mirrorFailed doesn't reset the timeout for the same reasons as
        mirrorSucceeded.
        """
        self.protocol.do_startMirroring()
        self.clock.advance(config.supermirror.worker_timeout - 1)
        self.protocol.do_mirrorFailed('error message', 'OOPS')
        self.clock.advance(2)
        return assert_fails_with(
            self.termination_deferred, error.TimeoutError)
Example #49
0
 def test_invalid_signature(self):
     # The checker requests attempts to authenticate if the requests have
     # an invalid signature.
     creds = self.makeCredentials(
         self.authserver.valid_user, self.authserver.valid_key)
     creds.signature = 'a'
     checker = self.makeChecker(True)
     d = checker.requestAvatarId(creds)
     def flush_errback(f):
         flush_logged_errors(BadKeyError)
         return f
     d.addErrback(flush_errback)
     return assert_fails_with(d, UnauthorizedLogin)
 def test_unexpectedErrorAndNotificationFailure(self):
     # If unexpectedError is called while a notification is pending and the
     # notification subsequently fails, the first failure "wins" and is
     # passed on to the termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda : deferred)
     self.protocol.unexpectedError(makeFailure(TypeError))
     runtime_error_failure = makeFailure(RuntimeError)
     deferred.errback(runtime_error_failure)
     self.assertEqual(
         flush_logged_errors(RuntimeError), [runtime_error_failure])
     return assert_fails_with(
         self.termination_deferred, TypeError)
    def test_createBranch_error_translation(self):
        # createBranch raises PermissionDenied if we try to create a branch
        # for, say, a product that doesn't exist.
        branch_url = '/~%s/no-such-product/new-branch' % (self.requester.name)
        deferred = self.server.createBranch(branch_url)
        deferred = assert_fails_with(deferred, errors.PermissionDenied)

        def check_exception(exception):
            self.assertEqual(branch_url, exception.path)
            self.assertEqual(": Project 'no-such-product' does not exist.",
                             exception.extra)

        return deferred.addCallback(check_exception)
 def test_failingNotificationCancelsPendingNotifications(self):
     # A failed notification prevents any further notifications from being
     # run.  Specifically, if a notification returns a deferred which
     # subsequently errbacks, any notifications which have been requested
     # in the mean time are not run.
     deferred = defer.Deferred()
     calls = []
     self.protocol.runNotification(lambda: deferred)
     self.protocol.runNotification(calls.append, 'called')
     self.assertEqual(calls, [])
     deferred.errback(makeFailure(RuntimeError))
     self.assertEqual(calls, [])
     return assert_fails_with(self.termination_deferred, RuntimeError)
    def test_createBranch_error_translation(self):
        # createBranch raises PermissionDenied if we try to create a branch
        # for, say, a product that doesn't exist.
        branch_url = '/~%s/no-such-product/new-branch' % (self.requester.name)
        deferred = self.server.createBranch(branch_url)
        deferred = assert_fails_with(deferred, errors.PermissionDenied)

        def check_exception(exception):
            self.assertEqual(branch_url, exception.path)
            self.assertEqual(
                ": Project 'no-such-product' does not exist.",
                exception.extra)
        return deferred.addCallback(check_exception)
    def test_branchChangedDoesNotResetTimeout(self):
        """Receiving 'branchChanged' doesn't reset the timeout.

        It's possible that in pathological cases, the worker process might
        hang around even after it has said that it's finished. When that
        happens, we want to kill it quickly so that we can continue mirroring
        other branches.
        """
        self.protocol.do_startMirroring()
        self.clock.advance(config.supermirror.worker_timeout - 1)
        self.protocol.do_branchChanged('', '', '', '', '', '')
        self.clock.advance(2)
        return assert_fails_with(self.termination_deferred, error.TimeoutError)
 def test_failingNotificationCancelsPendingNotifications(self):
     # A failed notification prevents any further notifications from being
     # run.  Specifically, if a notification returns a deferred which
     # subsequently errbacks, any notifications which have been requested
     # in the mean time are not run.
     deferred = defer.Deferred()
     calls = []
     self.protocol.runNotification(lambda : deferred)
     self.protocol.runNotification(calls.append, 'called')
     self.assertEqual(calls, [])
     deferred.errback(makeFailure(RuntimeError))
     self.assertEqual(calls, [])
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
Example #56
0
    def test_getConnectionFor_cancels_waiter_when_it_times_out(self):
        service = RegionService(sentinel.ipcWorker)
        uuid = factory.make_UUID()

        d = service._getConnectionFor(uuid, 1)
        # A waiter is added for the connection we're interested in.
        self.assertEqual({uuid: {d}}, service.waiters)
        d = assert_fails_with(d, CancelledError)

        def check(_):
            # The waiter has been unregistered.
            self.assertEqual({uuid: set()}, service.waiters)

        return d.addCallback(check)
 def test_uncleanExitAndPendingNotificationFails(self):
     # If the process exits with a non-zero exit code while a
     # notification is pending and the notification subsequently
     # fails, the ProcessTerminated is still passed on to the
     # termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda : deferred)
     self.simulateProcessExit(clean=False)
     runtime_error_failure = makeFailure(RuntimeError)
     deferred.errback(runtime_error_failure)
     self.assertEqual(
         flush_logged_errors(RuntimeError), [runtime_error_failure])
     return assert_fails_with(
         self.termination_deferred, error.ProcessTerminated)
    def test_branchChangedDoesNotResetTimeout(self):
        """Receiving 'branchChanged' doesn't reset the timeout.

        It's possible that in pathological cases, the worker process might
        hang around even after it has said that it's finished. When that
        happens, we want to kill it quickly so that we can continue mirroring
        other branches.
        """
        self.protocol.do_startMirroring()
        self.clock.advance(config.supermirror.worker_timeout - 1)
        self.protocol.do_branchChanged('', '', '', '', '', '')
        self.clock.advance(2)
        return assert_fails_with(
            self.termination_deferred, error.TimeoutError)