Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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
# 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, {
# 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 == []