Exemplo n.º 1
0
def test_surveyor_respondent():
    with pynng.Surveyor0(listen=addr, recv_timeout=1000) as surveyor, \
            pynng.Respondent0(dial=addr, recv_timeout=1000) as resp1, \
            pynng.Respondent0(dial=addr, recv_timeout=2000) as resp2:
        query = b"hey how's it going buddy?"
        # wait for sockets to connect
        time.sleep(0.03)
        surveyor.send(query)
        assert resp1.recv() == query
        assert resp2.recv() == query
        resp1.send(b'not too bad I suppose')

        msg2 = b'''
            Thanks for asking.  It's been a while since I've had
            human contact; times have been difficult for me.  I woke up this
            morning and again could not find a pair of matching socks.  I know that
            a lot of people think it's worth it to just throw all your old socks
            out and buy like 12 pairs of identical socks, but that just seems so
            mundane.  Life is about more than socks, you know?  So anyway, since I
            couldn't find any socks, I went ahead and put banana peels on my
            feet.  They don't match *perfectly* but it's close enough.  Anyway
            thanks for asking, I guess I'm doing pretty good.
        '''
        resp2.send(msg2)
        resp = [surveyor.recv() for _ in range(2)]
        assert b'not too bad I suppose' in resp
        # if they're not the same
        assert msg2 in resp

        with pytest.raises(pynng.BadState):
            resp2.send(b'oadsfji')
Exemplo n.º 2
0
async def main():
    with pynng.Surveyor0() as surveyor:
        n0 = await server(surveyor)
        
        async with curio.TaskGroup(wait=all) as g:
            await g.spawn(client, "client0", 3)
            await g.spawn(client, "client1", 3)
            await g.spawn(client, "client2", 4))

        await n0.join()