Ejemplo n.º 1
0
 def capture_ids(self, ids, args, test_filters=None):
     params.append([self, ids, args, test_filters])
     result = Fixture()
     result.run_tests = lambda: []
     if list_result is not None:
         result.list_tests = lambda: list(list_result)
     return result
Ejemplo n.º 2
0
    def run(self, timeout, function, *args, **kwargs):
        """Run 'function' in a reactor.

        If 'function' returns a Deferred, the reactor will keep spinning until
        the Deferred fires and its chain completes or until the timeout is
        reached -- whichever comes first.

        :raise TimeoutError: If 'timeout' is reached before the Deferred
            returned by 'function' has completed its callback chain.
        :raise NoResultError: If the reactor is somehow interrupted before
            the Deferred returned by 'function' has completed its callback
            chain.
        :raise StaleJunkError: If there's junk in the spinner from a previous
            run.
        :return: Whatever is at the end of the function's callback chain.  If
            it's an error, then raise that.
        """
        if self._debug:
            debug_settings = DebugTwisted(True)
        else:
            debug_settings = Fixture()

        with debug_settings:
            junk = self.get_junk()
            if junk:
                raise StaleJunkError(junk)
            self._save_signals()
            self._timeout_call = self._reactor.callLater(
                timeout, self._timed_out, function, timeout)
            # Calling 'stop' on the reactor will make it impossible to
            # re-start the reactor.  Since the default signal handlers for
            # TERM, BREAK and INT all call reactor.stop(), we'll patch it over
            # with crash.  XXX: It might be a better idea to either install
            # custom signal handlers or to override the methods that are
            # Twisted's signal handlers.
            real_stop, self._reactor.stop = self._reactor.stop, self._fake_stop

            def run_function():
                d = defer.maybeDeferred(function, *args, **kwargs)
                d.addCallbacks(self._got_success, self._got_failure)
                d.addBoth(self._stop_reactor)

            try:
                self._reactor.callWhenRunning(run_function)
                self._spinning = True
                self._reactor.run()
            finally:
                self._reactor.stop = real_stop
                self._restore_signals()
            try:
                return self._get_result()
            finally:
                self._clean()
Ejemplo n.º 3
0
    def setUp(cls):
        # Fixture to hold other fixtures.
        cls._fixture = Fixture()
        cls._fixture.setUp()

        cls.pgbouncer_fixture = PGBouncerFixture()
        # Install the PGBouncer fixture so we shut it down to
        # create database outages.
        cls._fixture.useFixture(cls.pgbouncer_fixture)

        # Bring up the Librarian, which will be connecting via
        # pgbouncer.
        cls.librarian_fixture = LibrarianServerFixture(
            BaseLayer.config_fixture)
        cls._fixture.useFixture(cls.librarian_fixture)