예제 #1
0
async def test_on_partitions_revoked(revoked, assignment, *, app):
    if assignment is None:
        assignment = revoked
    app.topics = MagicMock(
        name='app.topics',
        autospec=Conductor,
        on_partitions_revoked=AsyncMock(),
    )
    app.tables = Mock(
        name='app.tables',
        autospec=TableManager,
        on_partitions_revoked=AsyncMock(),
        _stop_standbys=AsyncMock(),  # XXX should not use internal method
    )
    app._fetcher = Mock(
        name='app._fetcher',
        autospec=Fetcher,
        stop=AsyncMock(),
    )
    app.consumer = Mock(
        name='app.consumer',
        autospec=Consumer,
        pause_partitions=AsyncMock(),
        wait_empty=AsyncMock(),
    )
    app.flow_control = Mock(
        name='app.flow_control',
        autospec=FlowControlEvent,
    )
    app.agents = Mock(
        name='app.agents',
        autospec=AgentManager,
    )
    signal = app.on_partitions_revoked.connect(AsyncMock(name='signal'))

    app.consumer.assignment.return_value = None
    app.conf.stream_wait_empty = False
    await app._on_partitions_revoked(revoked)

    app.topics.on_partitions_revoked.assert_called_once_with(revoked)
    app.tables.on_partitions_revoked.assert_called_once_with(revoked)
    app._fetcher.stop.assert_called_once_with()
    signal.assert_called_with(app, revoked, signal=app.on_partitions_revoked)

    assignment = app.consumer.assignment.return_value = revoked
    await app._on_partitions_revoked(revoked)

    if assignment:
        app.flow_control.suspend.assert_called_once_with()
        app.consumer.pause_partitions.assert_called_once_with(assignment)
        app.flow_control.clear.assert_called_once_with()

        with pytest.warns(AlreadyConfiguredWarning):
            app.conf.stream_wait_empty = True
        await app._on_partitions_revoked(revoked)
        app.consumer.wait_empty.assert_called_once_with()
예제 #2
0
 async def test__fetch_records(self, *, cthread, _consumer):
     _consumer._closed = False
     fetcher = _consumer._fetcher
     fetcher._closed = False
     fetcher._subscriptions.fetch_context = MagicMock()
     fetcher.fetched_records = AsyncMock()
     ret = await cthread._fetch_records(
         _consumer, {TP1}, timeout=312.3, max_records=1000)
     assert ret is fetcher.fetched_records.coro.return_value
     fetcher.fetched_records.assert_called_once_with(
         {TP1},
         timeout=312.3,
         max_records=1000,
     )
예제 #3
0
async def test_on_partitions_assigned(assigned, *, app):
    app.consumer = Mock(
        name='app.consumer',
        autospec=Consumer,
        pause_partitions=AsyncMock(),
    )
    app.agents = Mock(
        name='app.agents',
        autospec=AgentManager,
        on_partitions_assigned=AsyncMock(),
    )
    app.topics = MagicMock(
        name='app.topics',
        autospec=Conductor,
        on_partitions_assigned=AsyncMock(),
        wait_for_subscriptions=AsyncMock(),
    )
    app.tables = Mock(
        name='app.tables',
        autospec=TableManager,
        on_partitions_assigned=AsyncMock(),
    )
    app._fetcher = Mock(
        name='app._fetcher',
        autospec=Fetcher,
        restart=AsyncMock(),
        stop=AsyncMock(),
    )
    app.flow_control = Mock(
        name='app.flow_control',
        autospec=FlowControlEvent,
    )
    signal = app.on_partitions_assigned.connect(AsyncMock(name='signal'))

    await app._on_partitions_assigned(assigned)

    app.agents.on_partitions_assigned.assert_called_once_with(assigned)
    app.topics.wait_for_subscriptions.assert_called_once_with()
    app.consumer.pause_partitions.assert_called_once_with(assigned)
    app.topics.on_partitions_assigned.assert_called_once_with(assigned)
    app.tables.on_partitions_assigned.assert_called_once_with(assigned)
    app.flow_control.resume.assert_called_once_with()
    signal.assert_called_once_with(app,
                                   assigned,
                                   signal=app.on_partitions_assigned)

    app.log = Mock(name='log', autospec=CompositeLogger)
    await app._on_partitions_assigned(assigned)
예제 #4
0
 def test_add_context(self, *, proxy, service):
     context = MagicMock()
     ret = proxy.add_context(context)
     service.add_context.assert_called_once_with(context)
     assert ret is service.add_context()
예제 #5
0
 async def test_add_async_context(self, *, proxy, service):
     context = MagicMock()
     ret = await proxy.add_async_context(context)
     service.add_async_context.assert_called_once_with(context)
     assert ret is service.add_async_context.coro()
예제 #6
0
파일: test_locals.py 프로젝트: asksol/mode
    def test_await(self):
        x = MagicMock(__await__=Mock())
        s = CoroutineProxy(lambda: x)

        assert s.__await__() is x.__await__.return_value