Skip to content

Commit

Permalink
chore: added a timeout setting for running component tests so that yo…
Browse files Browse the repository at this point in the history
…u can test situations where you don't expect any output (#34)
  • Loading branch information
efunneko authored Sep 23, 2024
1 parent be10555 commit 2e1c1c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/solace_ai_connector/test_utils/utils_for_test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def run_component_test(
input_messages=None,
input_selection=None,
input_transforms=None,
max_response_timeout=None,
):
if not input_data and not input_messages:
raise ValueError("Either input_data or input_messages must be provided")
Expand Down Expand Up @@ -125,7 +126,8 @@ def run_component_test(
],
}
]
}
},
queue_timeout=max_response_timeout,
)

if input_data:
Expand All @@ -135,10 +137,20 @@ def run_component_test(
input_messages.append(message)

# Send each message through, one at a time
output_data_list = []
output_message_list = []
for message in input_messages:
send_message_to_flow(flows[0], message)
output_message = get_message_from_flow(flows[0])
validation_func(output_message.get_previous(), output_message, message)
if not output_message:
# This only happens if the max_response_timeout is reached
output_message_list.append(None)
output_data_list.append(None)
continue
output_data_list.append(output_message.get_data("previous"))
output_message_list.append(output_message)

validation_func(output_data_list, output_message_list, message)

finally:
if connector:
Expand Down Expand Up @@ -194,6 +206,8 @@ def send_message_to_flow(flow_info, message):
def get_message_from_flow(flow_info):
output_component = flow_info["output_component"]
event = output_component.get_output()
if not event:
return event
if event.event_type != EventType.MESSAGE:
raise ValueError("Expected a message event")
return event.data
Expand Down
8 changes: 4 additions & 4 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def test_transform_with_run_component_test():
"""This test is actually testing the test infrastructure method: run_component_test"""

def validation_func(output_data, output_message, _input_message):
assert output_data == "Hello, World!"
assert output_message.get_data("user_data.temp") == {
assert output_data[0] == "Hello, World!"
assert output_message[0].get_data("user_data.temp") == {
"payload": {"text": "Hello, World!", "greeting": "Static Greeting!"}
}

Expand Down Expand Up @@ -79,8 +79,8 @@ def test_transform_with_run_component_test_with_static_import():
"""This test is actually testing the test infrastructure method: run_component_test"""

def validation_func(output_data, output_message, _input_message):
assert output_data == "Hello, World!"
assert output_message.get_data("user_data.temp") == {
assert output_data == ["Hello, World!"]
assert output_message[0].get_data("user_data.temp") == {
"payload": {"text": "Hello, World!", "greeting": "Static Greeting!"}
}

Expand Down

0 comments on commit 2e1c1c6

Please sign in to comment.