Example #1
0
    def test_gather(self, conn):
        def collect_replies():
            yield 1
            yield 2
            yield 3

        ticket = uuid()
        actor = Actor(conn)
        actor._collect_replies = Mock(return_value=collect_replies())

        ares = AsyncResult(ticket, actor)
        ares.to_python = Mock()

        all = ares.gather()
        list(all)

        actor._collect_replies.assert_caleld_once_with(conn, ANY, ticket)
        self.assertEqual(ares.to_python.call_count,
                         len(list(collect_replies())))

        # test that the to_python is applied to all results
        actor._collect_replies.reset_mock()
        actor._collect_replies = Mock(return_value=collect_replies())
        prev_to_python = ares.to_python
        new_to_python = lambda x, propagate = True: 'called_%s' % x
        ares.to_python = new_to_python

        all = ares.gather()
        vals = list(all)

        expected_vals = [new_to_python(i) for i in collect_replies()]

        actor._collect_replies.assert_caleld_once_with(conn, ANY, ticket)
        self.assertEqual(vals, expected_vals)
        ares.to_python = prev_to_python
Example #2
0
    def test_gather_kwargs(self, conn, collect):
        actor = Actor(conn)
        ares = AsyncResult(uuid(), actor)
        prev_to_python = ares.to_python
        new_to_python = lambda x, propagate = True: x
        ares.to_python = new_to_python

        # Test default kwargs,
        # nothing is passed, the actor does not have agent assigned
        self.assert_gather_kwargs(
            ares, collect, {},
            timeout=actor.default_timeout, ignore_timeout=False)

        # limit - set the default agent limit if NONE is set
        # Test default kwargs, nothing is passed,
        # the actor does have default agent assigned
        actor.agent = dAgent(conn)
        self.assert_gather_kwargs(
            ares, collect, {},
            timeout=actor.default_timeout, limit=None, ignore_timeout=False)

        # limit - set the default agent limit if NONE is set
        # Test default kwargs, nothing is passed,
        # the actor does have agent with custom scatter limit assigned
        ag = Ag(conn)
        actor.agent = ag
        self.assert_gather_kwargs(
            ares, collect, {}, timeout=actor.default_timeout,
            limit=ag.get_default_scatter_limit())

        # pass all args
        actor.agent = Ag(conn)
        timeout, ignore_timeout, limit = 200.0, False, uuid()

        self.assert_gather_kwargs(
            ares, collect,
            {'timeout': timeout, 'ignore_timeout': ignore_timeout,
             'limit': limit},
            timeout=timeout, limit=limit, ignore_timeout=ignore_timeout)

        # ig ignore_tiemout is passed,
        # the custom logic for limit is not applies
        actor.agent = None
        timeout, ignore_timeout = 200.0, True
        self.assert_gather_kwargs(
            ares, collect,
            {'timeout': timeout, 'ignore_timeout': ignore_timeout},
            timeout=timeout, ignore_timeout=ignore_timeout)

        ares.to_python = prev_to_python