Test: hosting: handle writes during start_room (#3492)

Note: maybe we'd also want to add such handling to WebHost itself,
      but this is out of scope for getting hosting test to work.
This commit is contained in:
black-sliver 2024-06-08 17:51:09 +02:00 committed by GitHub
parent a0653cdfe0
commit 302017c69e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -66,12 +66,19 @@ def create_room(app_client: "FlaskClient", seed: str, auto_start: bool = False)
def start_room(app_client: "FlaskClient", room_id: str, timeout: float = 30) -> str:
from time import sleep
import pony.orm
poll_interval = .2
print(f"Starting room {room_id}")
no_timeout = timeout <= 0
while no_timeout or timeout > 0:
response = app_client.get(f"/room/{room_id}")
try:
response = app_client.get(f"/room/{room_id}")
except pony.orm.core.OptimisticCheckError:
# hoster wrote to room during our transaction
continue
assert response.status_code == 200, f"Starting room for {room_id} failed: status {response.status_code}"
match = re.search(r"/connect ([\w:.\-]+)", response.text)
if match: