Exemple #1
0
def test_ReplyPromise():
    r = ReplyPromise(reply_to='rt', correlation_id='id1')
    assert r.reply_to == 'rt'
    assert r.correlation_id == 'id1'
    assert not r.done()
    r.fulfill('id1', 'value')
    assert r.result() == 'value'

    with pytest.raises(ValueError):
        r._verify_correlation_id('')
    with pytest.raises(ValueError):
        r._verify_correlation_id(None)
Exemple #2
0
def test_ReplyPromise():
    r = ReplyPromise(reply_to="rt", correlation_id="id1")
    assert r.reply_to == "rt"
    assert r.correlation_id == "id1"
    assert not r.done()
    r.fulfill("id1", "value")
    assert r.result() == "value"

    with pytest.raises(ValueError):
        r._verify_correlation_id("")
    with pytest.raises(ValueError):
        r._verify_correlation_id(None)
Exemple #3
0
    async def test_add(self, *, c):
        assert not c._waiting
        c._start_fetcher = AsyncMock()
        p = ReplyPromise(reply_to='rt', correlation_id='id1')
        await c.add('id1', p)
        assert 'id1' in c._waiting
        assert p in list(c._waiting['id1'])

        p2 = ReplyPromise(reply_to='rt', correlation_id='id1')
        c._fetchers[p2.reply_to] = Mock()
        await c.add('id1', p2)
        assert p in list(c._waiting['id1'])
        assert p2 in list(c._waiting['id1'])

        c._start_fetcher.assert_called_once_with(p.reply_to)
Exemple #4
0
    async def test_add(self, *, c):
        assert not c._waiting
        c._start_fetcher = AsyncMock()
        p = ReplyPromise(reply_to="rt", correlation_id="id1")
        await c.add("id1", p)
        assert "id1" in c._waiting
        assert p in list(c._waiting["id1"])

        p2 = ReplyPromise(reply_to="rt", correlation_id="id1")
        c._fetchers[p2.reply_to] = Mock()
        await c.add("id1", p2)
        assert p in list(c._waiting["id1"])
        assert p2 in list(c._waiting["id1"])

        c._start_fetcher.assert_called_once_with(p.reply_to)
Exemple #5
0
 async def adder(self, p: BarrierState):
     for i in range(100):
         assert p.size == i
         r = ReplyPromise(reply_to=p.reply_to, correlation_id=str(i))
         p.add(r)
         assert len(p.pending) == i + 1
     await asyncio.sleep(0.5)
     assert p.size == i + 1
def test_ReplyPromise():
    r = ReplyPromise(reply_to='rt', correlation_id='id1')
    assert r.reply_to == 'rt'
    assert r.correlation_id == 'id1'
    assert not r.done()
    r.fulfill('id1', 'value')
    assert r.result() == 'value'