How to use the socketshark.session.Session.send_message function in socketshark

To help you get started, we’ve selected a few socketshark examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github closeio / socketshark / tests / test_basic.py View on Github external
# First message was delivered immediately.
        assert client.log == [{
            'event': 'message',
            'subscription': subscription,
            'data': {'foo': 'one'},
        }]
        client.log = []

        # Slow down sending of the second message.
        original = Session.send_message

        async def dummy_send(*args):
            await asyncio.sleep(wait)
            await original(*args)

        Session.send_message = dummy_send

        # Wait long enough that we're sending the second message, but aren't
        # done sending yet.
        await asyncio.sleep(throttle)

        # No longer slow down sending subsequent messages.
        Session.send_message = original

        # Send a third message.
        await redis.publish_json(redis_topic, {
            'subscription': subscription,
            'options': {'throttle': throttle},
            'data': {'foo': 'three'},
        })

        # Wait for Redis to propagate the messages
github closeio / socketshark / tests / test_basic.py View on Github external
# Wait for Redis to propagate the messages
        await asyncio.sleep(0.1)

        has_messages = await shark.run_service_receiver(once=True)
        assert has_messages

        # First message was delivered immediately.
        assert client.log == [{
            'event': 'message',
            'subscription': subscription,
            'data': {'foo': 'one'},
        }]
        client.log = []

        # Slow down sending of the second message.
        original = Session.send_message

        async def dummy_send(*args):
            await asyncio.sleep(wait)
            await original(*args)

        Session.send_message = dummy_send

        # Wait long enough that we're sending the second message, but aren't
        # done sending yet.
        await asyncio.sleep(throttle)

        # No longer slow down sending subsequent messages.
        Session.send_message = original

        # Send a third message.
        await redis.publish_json(redis_topic, {
github closeio / socketshark / tests / test_basic.py View on Github external
# Slow down sending of the second message.
        original = Session.send_message

        async def dummy_send(*args):
            await asyncio.sleep(wait)
            await original(*args)

        Session.send_message = dummy_send

        # Wait long enough that we're sending the second message, but aren't
        # done sending yet.
        await asyncio.sleep(throttle)

        # No longer slow down sending subsequent messages.
        Session.send_message = original

        # Send a third message.
        await redis.publish_json(redis_topic, {
            'subscription': subscription,
            'options': {'throttle': throttle},
            'data': {'foo': 'three'},
        })

        # Wait for Redis to propagate the messages
        await asyncio.sleep(0.1)

        has_messages = await shark.run_service_receiver(once=True)
        assert has_messages

        # We're still sending the second message
        assert client.log == []