1010from enum import Enum , unique
1111from typing import Any , Final
1212
13- import httpx
1413from playwright ._impl ._sync_base import EventContextManager
15- from playwright .sync_api import FrameLocator , Page , Request
14+ from playwright .sync_api import APIRequestContext , FrameLocator , Page , Request
1615from playwright .sync_api import TimeoutError as PlaywrightTimeoutError
1716from playwright .sync_api import WebSocket
1817from pydantic import AnyUrl
@@ -294,6 +293,7 @@ class SocketIONodeProgressCompleteWaiter:
294293 node_id : str
295294 logger : logging .Logger
296295 product_url : AnyUrl
296+ api_request_context : APIRequestContext
297297 _current_progress : dict [NodeProgressType , float ] = field (
298298 default_factory = defaultdict
299299 )
@@ -326,29 +326,29 @@ def __call__(self, message: str) -> bool:
326326 self .logger .info (
327327 "Current startup progress [expected number of node-progress-types=%d]: %s" ,
328328 len (NodeProgressType .required_types_for_started_service ()),
329- f"{ json .dumps ({k :round (v ,1 ) for k ,v in self ._current_progress .items ()})} " ,
329+ f"{ json .dumps ({k : round (v , 1 ) for k , v in self ._current_progress .items ()})} " ,
330330 )
331331
332332 return self .got_expected_node_progress_types () and all (
333333 round (progress , 1 ) == 1.0
334334 for progress in self ._current_progress .values ()
335335 )
336336
337+ # TODO: That is NOT what the frontend is doing... AND 401 is not OK it just means traefik responded that we are not authorized...
338+ # therefore it stops WAY too early and will generate false negatives!!
337339 _current_timestamp = datetime .now (UTC )
338340 if _current_timestamp - self ._last_poll_timestamp > timedelta (seconds = 5 ):
339341 url = f"https://{ self .node_id } .services.{ self .get_partial_product_url ()} "
340- response = httpx . get (url , timeout = 10 )
342+ response = self . api_request_context . get (url , timeout = 1000 )
341343 self .logger .info (
342344 "Querying the service endpoint from the E2E test. Url: %s Response: %s TIP: %s" ,
343345 url ,
344346 response ,
345347 (
346- "Response 401 is OK. It means that service is ready."
347- if response .status_code == 401
348- else "We are emulating the frontend; a 500 response is acceptable if the service is not yet ready."
348+ "We are emulating the frontend; a 500 response is acceptable if the service is not yet ready."
349349 ),
350350 )
351- if response .status_code <= 401 :
351+ if response .status <= 400 :
352352 # NOTE: If the response status is less than 400, it means that the backend is ready (There are some services that respond with a 3XX)
353353 # MD: for now I have included 401 - as this also means that backend is ready
354354 if self .got_expected_node_progress_types ():
@@ -408,8 +408,9 @@ def _node_started_predicate(request: Request) -> bool:
408408
409409
410410def _trigger_service_start (page : Page , node_id : str ) -> None :
411- with log_context (logging .INFO , msg = "trigger start button" ), page .expect_request (
412- _node_started_predicate , timeout = 35 * SECOND
411+ with (
412+ log_context (logging .INFO , msg = "trigger start button" ),
413+ page .expect_request (_node_started_predicate , timeout = 35 * SECOND ),
413414 ):
414415 page .get_by_test_id (f"Start_{ node_id } " ).click ()
415416
@@ -433,12 +434,14 @@ def expected_service_running(
433434 logging .INFO , msg = f"Waiting for node to run. Timeout: { timeout } "
434435 ) as ctx :
435436 waiter = SocketIONodeProgressCompleteWaiter (
436- node_id = node_id , logger = ctx .logger , product_url = product_url
437+ node_id = node_id ,
438+ logger = ctx .logger ,
439+ product_url = product_url ,
440+ api_request_context = page .request ,
437441 )
438442 service_running = ServiceRunning (iframe_locator = None )
439443
440444 try :
441-
442445 with websocket .expect_event ("framereceived" , waiter , timeout = timeout ):
443446 if press_start_button :
444447 _trigger_service_start (page , node_id )
@@ -475,7 +478,10 @@ def wait_for_service_running(
475478 logging .INFO , msg = f"Waiting for node to run. Timeout: { timeout } "
476479 ) as ctx :
477480 waiter = SocketIONodeProgressCompleteWaiter (
478- node_id = node_id , logger = ctx .logger , product_url = product_url
481+ node_id = node_id ,
482+ logger = ctx .logger ,
483+ product_url = product_url ,
484+ api_request_context = page .request ,
479485 )
480486 with websocket .expect_event ("framereceived" , waiter , timeout = timeout ):
481487 if press_start_button :
0 commit comments