Skip to content

Commit

Permalink
Make sure tests using scheduler have running event loop (#6872)
Browse files Browse the repository at this point in the history
Fix flaky scheduler test

Fixture 'try_queue_and_scheduler' double checks that the thread running the test has a running event loop.
  • Loading branch information
jonathan-eq authored Jan 2, 2024
1 parent a83cbf2 commit fc7c5ba
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import fileinput
import os
import pkgutil
Expand Down Expand Up @@ -252,6 +253,14 @@ def try_queue_and_scheduler(request, monkeypatch):
assert scheduler_mark
if scheduler_mark.kwargs.get("skip") and should_enable_scheduler:
pytest.skip("Skipping running test with scheduler enabled")
if should_enable_scheduler:
# Flaky - the new scheduler needs an event loop, which might not be initialized yet.
# This might be a bug in python 3.8, but it does not occur locally.
try:
asyncio.get_running_loop()
except RuntimeError:
asyncio.set_event_loop(asyncio.new_event_loop())

monkeypatch.setattr(
FeatureToggling._conf["scheduler"], "is_enabled", should_enable_scheduler
)
Expand Down

0 comments on commit fc7c5ba

Please sign in to comment.