Skip to content

Commit

Permalink
[wdspec] Increase time range for BiDi network events timing assertions
Browse files Browse the repository at this point in the history
Adds a helper to compute time range for BiDi network event timings assertions and
increases the allowed range by 100ms instead of 1ms to avoid intermittent issues on windows CI.

Differential Revision: https://phabricator.services.mozilla.com/D234938

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1942664
gecko-commit: 4645596600ce8b0fdb451f1be39c13465f699d3e
gecko-reviewers: webdriver-reviewers, Sasha
  • Loading branch information
juliandescottes authored and moz-wptsync-bot committed Jan 23, 2025
1 parent 48987b1 commit 0abe43d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 27 deletions.
18 changes: 17 additions & 1 deletion webdriver/tests/bidi/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
any_string_or_null,
assert_cookies,
int_interval,
number_interval,
recursive_compare,
)



def assert_bytes_value(bytes_value):
assert bytes_value["type"] in ["string", "base64"]
any_string(bytes_value["value"])
Expand Down Expand Up @@ -334,6 +334,22 @@ def get_cached_url(content_type, response):
return f"/webdriver/tests/support/http_handlers/cached.py?{query_string}"


def get_network_event_timerange(start, end, bidi_session):
"""
Compute a number_interval to be used for timing comparisons in BiDi network
events.
NOTE: This would ideally be just `number_interval(start - 1, end + 1)`,
however on Firefox Windows CI builds, there have been relatively frequent
intermittent failures where the values are a few ms off the expected time.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1921712
"""
if bidi_session.capabilities.get("browserName") == "firefox":
return number_interval(start - 100, end + 1)

return number_interval(start - 1, end + 1)


# Array of status and status text expected to be available in network events
HTTP_STATUS_AND_STATUS_TEXT = [
(101, "Switching Protocols"),
Expand Down
4 changes: 2 additions & 2 deletions webdriver/tests/bidi/network/auth_required/auth_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from tests.support.sync import AsyncPoll

from ... import number_interval
from .. import (
assert_response_event,
get_network_event_timerange,
AUTH_REQUIRED_EVENT,
PAGE_EMPTY_HTML,
)
Expand Down Expand Up @@ -116,7 +116,7 @@ async def test_request_timing_info(
await wait_for_future_safe(on_auth_required)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1
expected_request = {"method": "GET", "url": auth_url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from tests.support.sync import AsyncPoll

from ... import number_interval
from .. import (
assert_before_request_sent_event,
get_network_event_timerange,
PAGE_DATA_URL_HTML,
PAGE_DATA_URL_IMAGE,
PAGE_EMPTY_HTML,
Expand Down Expand Up @@ -283,6 +283,7 @@ async def test_request_cookies(

@pytest.mark.asyncio
async def test_request_timing_info(
bidi_session,
url,
wait_for_event,
wait_for_future_safe,
Expand All @@ -301,7 +302,7 @@ async def test_request_timing_info(
await wait_for_future_safe(on_before_request_sent)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -474,7 +475,7 @@ async def test_serviceworker_request(
await wait_for_future_safe(on_before_request_sent)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand All @@ -491,7 +492,13 @@ async def test_serviceworker_request(

@pytest.mark.asyncio
async def test_url_with_fragment(
url, wait_for_event, wait_for_future_safe, fetch, setup_network_test, current_time
bidi_session,
url,
wait_for_event,
wait_for_future_safe,
fetch,
setup_network_test,
current_time,
):
fragment_url = url(f"{PAGE_EMPTY_HTML}#foo")

Expand All @@ -507,7 +514,7 @@ async def test_url_with_fragment(
await wait_for_future_safe(on_before_request_sent)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -552,7 +559,7 @@ async def test_navigate_data_url(
await wait_for_future_safe(on_before_request_sent)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand All @@ -576,6 +583,7 @@ async def test_navigate_data_url(
)
@pytest.mark.asyncio
async def test_fetch_data_url(
bidi_session,
wait_for_event,
wait_for_future_safe,
fetch,
Expand All @@ -595,7 +603,7 @@ async def test_fetch_data_url(
await wait_for_future_safe(on_before_request_sent)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down
4 changes: 2 additions & 2 deletions webdriver/tests/bidi/network/fetch_error/fetch_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from tests.support.sync import AsyncPoll

from ... import number_interval
from .. import (
assert_fetch_error_event,
assert_response_event,
get_network_event_timerange,
FETCH_ERROR_EVENT,
PAGE_EMPTY_HTML,
RESPONSE_COMPLETED_EVENT,
Expand Down Expand Up @@ -245,7 +245,7 @@ async def test_request_timing_info(
await wait_for_future_safe(on_fetch_error)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1
expected_request = {"method": "GET", "url": PAGE_INVALID_URL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from tests.support.sync import AsyncPoll

from ... import number_interval
from .. import (
assert_response_event,
get_network_event_timerange,
HTTP_STATUS_AND_STATUS_TEXT,
PAGE_DATA_URL_HTML,
PAGE_DATA_URL_IMAGE,
Expand Down Expand Up @@ -166,7 +166,12 @@ async def test_load_page_twice(

@pytest.mark.asyncio
async def test_request_timing_info(
url, wait_for_event, wait_for_future_safe, fetch, setup_network_test,
bidi_session,
url,
wait_for_event,
wait_for_future_safe,
fetch,
setup_network_test,
current_time,
):
network_events = await setup_network_test(events=[RESPONSE_COMPLETED_EVENT])
Expand All @@ -180,7 +185,7 @@ async def test_request_timing_info(
await wait_for_future_safe(on_response_completed)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -449,7 +454,7 @@ async def test_serviceworker_request(
await wait_for_future_safe(on_response_completed)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand All @@ -470,7 +475,13 @@ async def test_serviceworker_request(

@pytest.mark.asyncio
async def test_url_with_fragment(
url, wait_for_event, wait_for_future_safe, fetch, setup_network_test, current_time
bidi_session,
url,
wait_for_event,
wait_for_future_safe,
fetch,
setup_network_test,
current_time,
):
fragment_url = url(f"{PAGE_EMPTY_HTML}#foo")

Expand All @@ -486,7 +497,7 @@ async def test_url_with_fragment(
await wait_for_future_safe(on_response_completed)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -534,7 +545,7 @@ async def test_navigate_data_url(
await wait_for_future_safe(on_response_completed)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -568,6 +579,7 @@ async def test_navigate_data_url(
)
@pytest.mark.asyncio
async def test_fetch_data_url(
bidi_session,
wait_for_event,
wait_for_future_safe,
fetch,
Expand All @@ -587,7 +599,7 @@ async def test_fetch_data_url(
await wait_for_future_safe(on_response_completed)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down
22 changes: 15 additions & 7 deletions webdriver/tests/bidi/network/response_started/response_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from tests.support.sync import AsyncPoll

from ... import number_interval
from .. import (
assert_response_event,
get_network_event_timerange,
HTTP_STATUS_AND_STATUS_TEXT,
PAGE_DATA_URL_HTML,
PAGE_DATA_URL_IMAGE,
Expand Down Expand Up @@ -170,6 +170,7 @@ async def test_request_bodysize(

@pytest.mark.asyncio
async def test_request_timing_info(
bidi_session,
url,
wait_for_event,
wait_for_future_safe,
Expand All @@ -188,7 +189,7 @@ async def test_request_timing_info(
await wait_for_future_safe(on_response_started)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -422,7 +423,7 @@ async def test_serviceworker_request(
await wait_for_future_safe(on_response_started)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand All @@ -443,7 +444,13 @@ async def test_serviceworker_request(

@pytest.mark.asyncio
async def test_url_with_fragment(
url, wait_for_event, wait_for_future_safe, fetch, setup_network_test, current_time
bidi_session,
url,
wait_for_event,
wait_for_future_safe,
fetch,
setup_network_test,
current_time,
):
fragment_url = url(f"{PAGE_EMPTY_HTML}#foo")

Expand All @@ -459,7 +466,7 @@ async def test_url_with_fragment(
await wait_for_future_safe(on_response_started)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -507,7 +514,7 @@ async def test_navigate_data_url(
await wait_for_future_safe(on_response_started)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down Expand Up @@ -541,6 +548,7 @@ async def test_navigate_data_url(
)
@pytest.mark.asyncio
async def test_fetch_data_url(
bidi_session,
wait_for_event,
wait_for_future_safe,
fetch,
Expand All @@ -560,7 +568,7 @@ async def test_fetch_data_url(
await wait_for_future_safe(on_response_started)

time_end = await current_time()
time_range = number_interval(time_start - 1, time_end + 1)
time_range = get_network_event_timerange(time_start, time_end, bidi_session)

assert len(events) == 1

Expand Down

0 comments on commit 0abe43d

Please sign in to comment.