Skip to content

tests: Add test for event delivery direct #7541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/backend/tests/unit/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@ async def create_flow(client: AsyncClient, flow_data: str, headers: dict[str, st


async def build_flow(
client: AsyncClient, flow_id: UUID, headers: dict[str, str], json: dict[str, Any] | None = None
client: AsyncClient,
flow_id: UUID,
headers: dict[str, str],
json: dict[str, Any] | None = None,
event_delivery: str | None = None,
) -> dict[str, Any]:
"""Start a flow build and return the job_id."""
"""Start a flow build and return the job_id or events for direct delivery."""
if json is None:
json = {}
response = await client.post(f"api/v1/build/{flow_id}/flow", json=json, headers=headers)

# Add event_delivery to query params if specified
params = {}
if event_delivery:
params["event_delivery"] = event_delivery

response = await client.post(f"api/v1/build/{flow_id}/flow", json=json, headers=headers, params=params)
assert response.status_code == codes.OK
if event_delivery == "direct":
return response
return response.json()


Expand Down
13 changes: 13 additions & 0 deletions src/backend/tests/unit/test_chat_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,16 @@ async def mock_cancel_flow_build_with_cancelled_error(*_args, **_kwargs):
finally:
# Restore the original function to avoid affecting other tests
monkeypatch.setattr(langflow.api.v1.chat, "cancel_flow_build", original_cancel_flow_build)


@pytest.mark.benchmark
async def test_build_flow_direct(client, json_memory_chatbot_no_llm, logged_in_headers):
"""Test the build flow endpoint with direct event delivery."""
# First create the flow
flow_id = await create_flow(client, json_memory_chatbot_no_llm, logged_in_headers)

# Start the build with direct event delivery
response = await build_flow(client, flow_id, logged_in_headers, event_delivery="direct")
# Use the same consume_and_assert_stream function to verify the events
# We pass None as job_id since direct delivery doesn't use job_ids
await consume_and_assert_stream(response, None)
Loading