Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dezhidki committed Aug 4, 2023
1 parent 208b43c commit 5cd86b3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions timApp/tests/server/test_csplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class CsPluginTest(TimRouteTest):
def test_csplugin_pointsrule(self):
self.wait_for_url("http://csplugin:5000/cs/reqs")
self.login_test1()
d = self.create_doc(
initial_par="""
Expand Down Expand Up @@ -62,6 +63,7 @@ def first_answer():
self.assertEqual(2, first_answer().points)

def test_csplugin_csharp(self):
self.wait_for_url("http://csplugin:5000/cs/reqs")
self.login_test1()
d = self.create_doc(
initial_par="""
Expand Down
28 changes: 28 additions & 0 deletions timApp/tests/server/timroutetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import json
import re
import socket
import time
import warnings
from base64 import b64encode
from contextlib import contextmanager
from datetime import datetime
from functools import lru_cache
from typing import Union, Any, Generator

import requests
import responses
from flask import (
Response,
Expand Down Expand Up @@ -1397,6 +1399,32 @@ def temp_config(self, settings: dict[str, Any]):
for k, v in old_settings.items():
app.config[k] = v

@staticmethod
def wait_for_url(url: str, wait_time: float = 1.0, timeout: float = 30.0) -> None:
"""
Waits for a URL to become available. Useful for waiting for a container to start.
:param url: URL to wait for
:param wait_time: Time to wait between requests
:param timeout: Timeout in seconds. If None, uses default timeout.
"""
start_time = time.time()
while True:
# noinspection PyBroadException
try:
res = requests.get(url)
ok = res.status_code == 200
except Exception:
ok = False

if not ok:
now = time.time()
if now - start_time > timeout:
raise TimeoutError(f"Timeout waiting for {url}")
time.sleep(wait_time)
else:
break


class TimRouteTest(TimRouteTestBase):
def _init_client(self) -> FlaskClient:
Expand Down

0 comments on commit 5cd86b3

Please sign in to comment.