Skip to content

Commit

Permalink
🐛E2E: fixes how videostreaming checked (ITISFoundation#6569)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg authored Oct 21, 2024
1 parent 34892ae commit edc9ea0
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
wait_for_service_running,
)

_S4L_STREAMING_ESTABLISHMENT_MIN_WAITING_TIME: Final[int] = 5 * SECOND
_S4L_STREAMING_ESTABLISHMENT_MAX_TIME: Final[int] = 30 * SECOND
_S4L_SOCKETIO_REGEX: Final[re.Pattern] = re.compile(
r"^(?P<protocol>[^:]+)://(?P<node_id>[^\.]+)\.services\.(?P<hostname>[^\/]+)\/socket\.io\/.+$"
Expand Down Expand Up @@ -47,7 +48,7 @@ def __call__(self, new_websocket: WebSocket) -> bool:

@dataclass(kw_only=True)
class _S4LSocketIOCheckBitRateIncreasesMessagePrinter:
observation_time: datetime.timedelta
min_waiting_time_before_checking_bitrate: datetime.timedelta
logger: logging.Logger
_initial_bit_rate: float = 0
_initial_bit_rate_time: datetime.datetime = arrow.utcnow().datetime
Expand All @@ -59,9 +60,9 @@ def __call__(self, message: str) -> bool:
decoded_message.name == "server.video_stream.bitrate_data"
and "bitrate" in decoded_message.obj
):
current_bitrate = decoded_message.obj["bitrate"]
current_bit_rate = decoded_message.obj["bitrate"]
if self._initial_bit_rate == 0:
self._initial_bit_rate = current_bitrate
self._initial_bit_rate = current_bit_rate
self._initial_bit_rate_time = arrow.utcnow().datetime
self.logger.info(
"%s",
Expand All @@ -71,16 +72,21 @@ def __call__(self, message: str) -> bool:

# NOTE: MaG says the value might also go down, but it shall definitely change,
# if this code proves unsafe we should change it.
if "bitrate" in decoded_message.obj:
self.logger.info(
"bitrate: %s",
f"{TypeAdapter(ByteSize).validate_python(current_bit_rate).human_readable()}/s",
)
elapsed_time = arrow.utcnow().datetime - self._initial_bit_rate_time
if (
elapsed_time > self.observation_time
elapsed_time > self.min_waiting_time_before_checking_bitrate
and "bitrate" in decoded_message.obj
):
current_bitrate = decoded_message.obj["bitrate"]
bitrate_test = bool(self._initial_bit_rate != current_bitrate)
current_bit_rate = decoded_message.obj["bitrate"]
bitrate_test = bool(self._initial_bit_rate != current_bit_rate)
self.logger.info(
"%s",
f"{TypeAdapter(ByteSize).validate_python(current_bitrate).human_readable()}/s after {elapsed_time=}: {'good!' if bitrate_test else 'failed! bitrate did not change! TIP: talk with MaG about underwater cables!'}",
f"{TypeAdapter(ByteSize).validate_python(current_bit_rate).human_readable()}/s after {elapsed_time=}: {'good!' if bitrate_test else 'failed! bitrate did not change! TIP: talk with MaG about underwater cables!'}",
)
return bitrate_test

Expand Down Expand Up @@ -144,10 +150,14 @@ def interact_with_s4l(page: Page, s4l_iframe: FrameLocator) -> None:
def check_video_streaming(
page: Page, s4l_iframe: FrameLocator, s4l_websocket: WebSocket
) -> None:
assert (
_S4L_STREAMING_ESTABLISHMENT_MIN_WAITING_TIME
< _S4L_STREAMING_ESTABLISHMENT_MAX_TIME
)
with log_context(logging.INFO, "Check videostreaming works") as ctx:
waiter = _S4LSocketIOCheckBitRateIncreasesMessagePrinter(
observation_time=datetime.timedelta(
milliseconds=_S4L_STREAMING_ESTABLISHMENT_MAX_TIME / 2.0,
min_waiting_time_before_checking_bitrate=datetime.timedelta(
milliseconds=_S4L_STREAMING_ESTABLISHMENT_MIN_WAITING_TIME,
),
logger=ctx.logger,
)
Expand Down

0 comments on commit edc9ea0

Please sign in to comment.