Modify perform_test_obj to handle messages received in any order

This commit is contained in:
Stuckinaboot 2019-04-03 16:28:32 -04:00
parent 2ba281b511
commit d83db6d910

View File

@ -175,6 +175,8 @@ async def perform_test_from_obj(obj):
topics_in_msgs_ordered = [] topics_in_msgs_ordered = []
messages = obj["messages"] messages = obj["messages"]
tasks_publish = [] tasks_publish = []
all_actual_msgs = {}
for msg in messages: for msg in messages:
topics = msg["topics"] topics = msg["topics"]
@ -196,7 +198,10 @@ async def perform_test_from_obj(obj):
# TODO: Update message sender to be correct message sender before # TODO: Update message sender to be correct message sender before
# adding msg_talk to this list # adding msg_talk to this list
for topic in topics: for topic in topics:
topics_in_msgs_ordered.append((topic, msg_talk)) if topic in all_actual_msgs:
all_actual_msgs[topic].append(msg_talk.publish[0].SerializeToString())
else:
all_actual_msgs[topic] = [msg_talk.publish[0].SerializeToString()]
# Allow time for publishing before continuing # Allow time for publishing before continuing
# await asyncio.sleep(0.4) # await asyncio.sleep(0.4)
@ -204,13 +209,24 @@ async def perform_test_from_obj(obj):
await asyncio.gather(*tasks_publish) await asyncio.gather(*tasks_publish)
# Step 4) Check that all messages were received correctly. # Step 4) Check that all messages were received correctly.
# TODO: Check message sender too for topic in all_actual_msgs:
for i in range(len(topics_in_msgs_ordered)):
topic, actual_msg = topics_in_msgs_ordered[i]
for node_id in topic_map[topic]: for node_id in topic_map[topic]:
all_received_msgs_in_topic = []
# Add all messages to message received list for given node in given topic
while (queues_map[node_id][topic].qsize() > 0):
# Get message from subscription queue # Get message from subscription queue
msg_on_node_str = await queues_map[node_id][topic].get() msg_on_node = (await queues_map[node_id][topic].get()).SerializeToString()
assert actual_msg.publish[0].SerializeToString() == msg_on_node_str.SerializeToString() all_received_msgs_in_topic.append(msg_on_node)
# Ensure each message received was the same as one sent
print(all_received_msgs_in_topic)
print(all_actual_msgs)
for msg_on_node in all_received_msgs_in_topic:
assert msg_on_node in all_actual_msgs[topic]
# Ensure same number of messages received as sent
assert len(all_received_msgs_in_topic) == len(all_actual_msgs[topic])
# Success, terminate pending tasks. # Success, terminate pending tasks.
await cleanup() await cleanup()