@@ -45,6 +45,7 @@ def __init__(self, app_port: int = 8000):
4545 self .app_port = app_port
4646 self .app_process : subprocess .Popen | None = None
4747 self .exit_code = 0
48+ self .expected_request_count : int | None = None
4849
4950 # Register signal handlers for cleanup
5051 signal .signal (signal .SIGTERM , self ._signal_handler )
@@ -76,6 +77,17 @@ def run_command(self, cmd: list[str], env: dict | None = None, check: bool = Tru
7677
7778 return result
7879
80+ def _parse_request_count (self , output : str ):
81+ """Parse the request count from test_requests.py output."""
82+ for line in output .split ("\n " ):
83+ if line .startswith ("TOTAL_REQUESTS_SENT:" ):
84+ try :
85+ count = int (line .split (":" )[1 ])
86+ self .expected_request_count = count
87+ self .log (f"Captured request count: { count } " , Colors .GREEN )
88+ except (ValueError , IndexError ):
89+ self .log (f"Failed to parse request count from: { line } " , Colors .YELLOW )
90+
7991 def wait_for_service (self , check_cmd : list [str ], timeout : int = 30 , interval : int = 1 ) -> bool :
8092 """Wait for a service to become ready."""
8193 elapsed = 0
@@ -138,8 +150,8 @@ def record_traces(self) -> bool:
138150 self .app_process = subprocess .Popen (
139151 ["python" , "src/app.py" ],
140152 env = {** os .environ , ** env },
141- stdout = subprocess .PIPE ,
142- stderr = subprocess .STDOUT ,
153+ stdout = subprocess .DEVNULL ,
154+ stderr = subprocess .DEVNULL ,
143155 text = True ,
144156 )
145157
@@ -164,7 +176,13 @@ def record_traces(self) -> bool:
164176 # Execute test requests
165177 self .log ("Executing test requests..." , Colors .GREEN )
166178 try :
167- self .run_command (["python" , "src/test_requests.py" ])
179+ # Pass PYTHONPATH so test_requests.py can import from e2e_common
180+ result = self .run_command (
181+ ["python" , "src/test_requests.py" ],
182+ env = {"PYTHONPATH" : "/sdk" },
183+ )
184+ # Parse request count from output
185+ self ._parse_request_count (result .stdout )
168186 except subprocess .CalledProcessError :
169187 self .log ("Test requests failed" , Colors .RED )
170188 self .exit_code = 1
@@ -257,13 +275,15 @@ def parse_test_results(self, output: str):
257275 idx += 1
258276
259277 all_passed = True
278+ passed_count = 0
260279 for result in results :
261280 test_id = result .get ("test_id" , "unknown" )
262281 passed = result .get ("passed" , False )
263282 duration = result .get ("duration" , 0 )
264283
265284 if passed :
266285 self .log (f"✓ Test ID: { test_id } (Duration: { duration } ms)" , Colors .GREEN )
286+ passed_count += 1
267287 else :
268288 self .log (f"✗ Test ID: { test_id } (Duration: { duration } ms)" , Colors .RED )
269289 all_passed = False
@@ -276,6 +296,20 @@ def parse_test_results(self, output: str):
276296 self .log ("Some tests failed!" , Colors .RED )
277297 self .exit_code = 1
278298
299+ # Validate request count matches passed tests
300+ if self .expected_request_count is not None :
301+ if passed_count < self .expected_request_count :
302+ self .log (
303+ f"✗ Request count mismatch: { passed_count } passed tests != { self .expected_request_count } requests sent" ,
304+ Colors .RED ,
305+ )
306+ self .exit_code = 1
307+ else :
308+ self .log (
309+ f"✓ Request count validation: { passed_count } passed tests >= { self .expected_request_count } requests sent" ,
310+ Colors .GREEN ,
311+ )
312+
279313 except Exception as e :
280314 self .log (f"Failed to parse test results: { e } " , Colors .RED )
281315 self .log (f"Raw output:\n { output } " , Colors .YELLOW )
0 commit comments