MCPcopy Create free account
hub / github.com/langgenius/dify / test_workflow_stream

Method test_workflow_stream

scripts/stress-test/sse_benchmark.py:400–554  ·  view source on GitHub ↗

Test workflow SSE streaming endpoint

(self)

Source from the content-addressed store, hash-verified

398
399 @task
400 def test_workflow_stream(self) -> None:
401 """Test workflow SSE streaming endpoint"""
402
403 question = random.choice(self.questions)
404 self.user_counter += 1
405
406 headers = {
407 "Authorization": f"Bearer {self.api_token}",
408 "Content-Type": "application/json",
409 "Accept": "text/event-stream",
410 "Cache-Control": "no-cache",
411 }
412
413 data = WorkflowRequestData(
414 inputs=WorkflowInputs(question=question),
415 response_mode="streaming",
416 user=f"user_{self.user_counter}",
417 )
418
419 start_time = time.time()
420 first_event_time = None
421 event_count = 0
422 inter_event_times: list[float] = []
423 last_event_time = None
424 ttfe = 0
425 request_success = False
426 bytes_received = 0
427
428 metrics.connection_started()
429
430 # Use catch_response context manager directly
431 with self.client.request(
432 method="POST",
433 url=WORKFLOW_PATH,
434 headers=headers,
435 json=data,
436 stream=True,
437 catch_response=True,
438 timeout=(CONNECT_TIMEOUT, READ_TIMEOUT),
439 name="/v1/workflows/run", # Name for Locust stats
440 ) as response:
441 try:
442 # Validate response
443 if response.status_code >= 400:
444 error_type: ErrorType = "http_4xx" if response.status_code < 500 else "http_5xx"
445 metrics.record_error(error_type)
446 response.failure(f"HTTP {response.status_code}")
447 return
448
449 content_type = response.headers.get("Content-Type", "")
450 if "text/event-stream" not in content_type and "application/json" not in content_type:
451 logger.error(f"Expected text/event-stream, got: {content_type}")
452 metrics.record_error("invalid_response")
453 response.failure(f"Invalid content type: {content_type}")
454 return
455
456 # Parse SSE events
457 parser = SSEParser()

Callers

nothing calls this directly

Calls 15

parse_lineMethod · 0.95
WorkflowRequestDataClass · 0.85
WorkflowInputsClass · 0.85
SSEParserClass · 0.85
StreamMetricsClass · 0.85
choiceMethod · 0.80
timeMethod · 0.80
connection_startedMethod · 0.80
record_errorMethod · 0.80
iter_linesMethod · 0.80
event_receivedMethod · 0.80
record_ttfeMethod · 0.80

Tested by

no test coverage detected