Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes flaky test #68

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/service-library/tests/test_async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ async def get_all(self) -> List[Any]:
return list(self._queue)


def _compensate_for_slow_systems(number: float) -> float:
# NOTE: in slower systems it is important to allow for enough time to pass
# raising by one order of magnitude
return number * 10


async def test_context_aware_dispatch(
sleep_duration: float,
ensure_run_in_sequence_context_is_empty: None,
Expand Down Expand Up @@ -151,12 +157,10 @@ async def target_function(the_param: Any) -> None:
assert str(excinfo.value).startswith(message) is True


@pytest.mark.flaky(max_runs=3) # FIXME: ANE pls review and remove this flaky mark
async def test_context_aware_measure_parallelism(
sleep_duration: float,
ensure_run_in_sequence_context_is_empty: None,
) -> None:
# expected duration 1 second
@run_sequentially_in_context(target_args=["control"])
async def sleep_for(sleep_interval: float, control: Any) -> Any:
await asyncio.sleep(sleep_interval)
Expand All @@ -169,8 +173,8 @@ async def sleep_for(sleep_interval: float, control: Any) -> Any:
result = await asyncio.gather(*functions)
elapsed = time() - start

assert elapsed < sleep_duration * 2 # allow for some internal delay
assert control_sequence == result
assert elapsed < _compensate_for_slow_systems(sleep_duration)


async def test_context_aware_measure_serialization(
Expand Down