def notification_forever_stored(qty_stored=32, ttl=300, notif_delay=30, run_once=0, *args, **kwargs): """Connects, registers, disconnects and then repeats every delay interval: 1. send notifications x qty_stored (# of notifications to store) 2. connects 3. receive notifications x qty_stored Repeats forever. """ yield connect() response = yield hello(None) reg, endpoint = yield register(random_channel_id()) uaid = response["uaid"] yield disconnect() while True: message_ids = [] length, data = random_data(min_length=2048, max_length=4096) for i in range(qty_stored): response, content = yield send_notification( endpoint, data, headers={"TTL": str(ttl)}) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) yield wait(5) yield connect() response = yield hello(uaid) assert response["uaid"] == uaid while True: # Pull as many notifications as we can get notif = yield expect_notification(reg["channelID"], 2) if notif: yield counter("notification.received", 1) message_ids.append(notif["version"]) if message_ids: while message_ids: message_id = message_ids.pop() yield ack(channel_id=reg["channelID"], version=message_id) yield counter("notification.ack", 1) else: break if run_once: yield unregister(reg["channelID"]) yield disconnect() break else: yield disconnect() yield wait(notif_delay)
def connect_and_idle_forever(): """Connects without ever disconnecting""" yield connect() yield hello(None) while True: yield wait(100)
def notification_forever_bad_tokens(notif_delay=30, run_once=0, token_length=140): """Connects, then repeats every delay interval: 1. send notification with invalid token Repeats forever. """ yield connect() yield hello(None) # register only to retrieve valid endpoint path # (we'll replace valid token with invalid one) reg, endpoint = yield register(random_channel_id()) while True: endpoint = bad_push_endpoint(endpoint, token_length) length, data = random_data(min_length=2048, max_length=4096) response, content = yield send_notification(endpoint, data, 60) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) yield wait(notif_delay) if run_once: yield disconnect() break
def notification_forever_unsubscribed(notif_delay=30, run_once=0): """Connects, registers, unregisters, then repeat following steps every delay interval (ignoring 4XXs): 1. send notification 2. receive notification Repeats forever. """ yield connect() yield hello(None) reg, endpoint = yield register(random_channel_id()) unregister(reg["channelID"]) while True: length, data = random_data(min_length=2048, max_length=4096) yield timer_start("update.latency") response, content = yield send_notification(endpoint, data, 60) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) notif = yield expect_notification(reg["channelID"], 5) yield counter("notification.received", 1) yield timer_end("update.latency") yield ack(channel_id=notif["channelID"], version=notif["version"]) yield counter("notification.ack", 1) yield wait(notif_delay) if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def notification_forever_unsubscribed(notif_delay=30, run_once=0): """Connects, registers, unregisters, then repeat following steps every delay interval (ignoring 4XXs): 1. send notification 2. receive notification Repeats forever. """ yield connect() yield hello(None) reg, endpoint = yield register(random_channel_id()) unregister(reg["channelID"]) while True: length, data = random_data(min_length=2048, max_length=4096) yield timer_start("update.latency") response, content = yield send_notification(endpoint, data, headers={"TTL": "60"}) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) notif = yield expect_notification(reg["channelID"], 5) yield counter("notification.received", 1) yield timer_end("update.latency") yield ack(channel_id=notif["channelID"], version=notif["version"]) yield counter("notification.ack", 1) yield wait(notif_delay) if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def notification_forever_bad_tokens(notif_delay=30, run_once=0, token_length=140): """Connects, then repeats every delay interval: 1. send notification with invalid token Repeats forever. """ yield connect() yield hello(None) # register only to retrieve valid endpoint path # (we'll replace valid token with invalid one) reg, endpoint = yield register(random_channel_id()) while True: endpoint = bad_push_endpoint(endpoint, token_length) length, data = random_data(min_length=2048, max_length=4096) response, content = yield send_notification(endpoint, data, headers={"TTL": "60"}) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) yield wait(notif_delay) if run_once: yield disconnect() break
def notification_forever_stored(qty_stored=1000, ttl=300, flood_delay=30, notif_delay=30, run_once=0): """Connects, then repeats every delay interval: 1. register 2. send notifications x qty_stored (# of notifications to store) 3. wait for flood_delay (seconds) 4. receive notifications x qty_stored Repeats forever. """ yield connect() yield hello(None) reg, endpoint = yield register(random_channel_id()) while True: message_ids = [] length, data = random_data(min_length=2048, max_length=4096) for i in range(qty_stored): response, content = yield send_notification(endpoint, data, ttl) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", i) notif = yield expect_notification(reg["channelID"], ttl) yield counter("notification.received", 1) message_ids.append(notif["version"]) yield wait(notif_delay) yield wait(flood_delay) for i in range(qty_stored): yield ack(channel_id=notif["channelID"], version=message_ids[i]) yield counter("notification.ack", i) yield wait(notif_delay) if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def register_forever(reg_delay=30, run_once=0): """Connects, then repeats every delay interval: 1. register Repeats forever. """ yield connect() yield hello(None) while True: reg, endpoint = yield register(random_channel_id()) yield wait(reg_delay) if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def reconnect_forever(reconnect_delay=30, run_once=0): """Connects, then repeats every delay interval: 1. send notification 2. receive notification 3. disconnect 4. reconnect Repeats forever. """ yield connect() response = yield hello(None) reg, endpoint = yield register(random_channel_id()) assert "uaid" in response uaid = response["uaid"] while True: length, data = random_data(min_length=2048, max_length=4096) yield timer_start("update.latency") response, content = yield send_notification(endpoint, data, headers={"TTL": "60"}) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) notif = yield expect_notification(reg["channelID"], 5) yield counter("notification.received", 1) yield ack(channel_id=notif["channelID"], version=notif["version"]) yield counter("notification.ack", 1) yield timer_end("update.latency") yield wait(reconnect_delay) yield disconnect() try: yield connect() response = yield hello(uaid) assert response["uaid"] == uaid except Exception as ex: # Connect may not properly reconnect during some testing, the # following work-around ensures that tests pass for now until # the race condition can be identified. print(ex) break if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def notification_forever_direct_store(cycle_delay=10, run_once=0): """Connects, registers, then repeats the following steps even cycle delay: 1. send notification 2. receive notification 3. disconnect 4. wait cycle_delay 5. connect 6. receive notification 7. ack notification """ yield connect() response = yield hello(None) reg, endpoint = yield register(random_channel_id()) uaid = response["uaid"] ttl = 600 while True: length, data = random_data(min_length=2048, max_length=4096) response, content = yield send_notification(endpoint, data, headers={"TTL": str(ttl)}) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) notif = yield expect_notification(reg["channelID"], 2) if not notif: raise Exception("Needed notification") yield disconnect() yield wait(cycle_delay) yield connect() resp = yield hello(uaid) assert resp["uaid"] == uaid notif = yield expect_notification(reg["channelID"], 10) if not notif: raise Exception("Needed notification") yield ack(channel_id=reg["channelID"], version=notif["version"]) if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def notification_forever_bad_endpoints(notif_delay=30, run_once=0): """Connects, repeats every delay interval: 1. send notification with invalid endpoint. Repeats forever. """ yield connect() yield hello(None) while True: endpoint = bad_push_endpoint() length, data = random_data(min_length=2048, max_length=4096) response, content = yield send_notification(endpoint, data, 60) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) yield wait(notif_delay) if run_once: yield disconnect() break
def notification_forever_bad_endpoints(notif_delay=30, run_once=0): """Connects, repeats every delay interval: 1. send notification with invalid endpoint. Repeats forever. """ yield connect() yield hello(None) while True: endpoint = bad_push_endpoint() length, data = random_data(min_length=2048, max_length=4096) response, content = yield send_notification(endpoint, data, headers={"TTL": "60"}) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) yield wait(notif_delay) if run_once: yield disconnect() break
def reconnect_forever(reconnect_delay=30, run_once=0): """Connects, then repeats every delay interval: 1. send notification 2. receive notification 3. disconnect 4. reconnect Repeats forever. """ yield connect() response = yield hello(None) reg, endpoint = yield register(random_channel_id()) assert "uaid" in response uaid = response["uaid"] while True: length, data = random_data(min_length=2048, max_length=4096) yield timer_start("update.latency") response, content = yield send_notification(endpoint, data, 60) yield counter("notification.throughput.bytes", length) yield counter("notification.sent", 1) notif = yield expect_notification(reg["channelID"], 5) yield counter("notification.received", 1) yield ack(channel_id=notif["channelID"], version=notif["version"]) yield counter("notification.ack", 1) yield timer_end("update.latency") yield wait(reconnect_delay) yield disconnect() yield connect() response = yield hello(uaid) assert response["uaid"] == uaid if run_once: yield unregister(reg["channelID"]) yield disconnect() break
def _wait_multiple(): from aplt.commands import wait yield wait(0.1) yield wait(0.1) yield wait(0.1)
def _stack_gens(): from aplt.commands import wait yield _wait_multiple() yield wait(0.1)