diff --git a/SAS/TMSS/test/test_utils.py b/SAS/TMSS/test/test_utils.py index bc42fc9966675b0569c0716317d18c99f604813b..8191b2186065976eebf208065557d4e3786ba2c7 100644 --- a/SAS/TMSS/test/test_utils.py +++ b/SAS/TMSS/test/test_utils.py @@ -208,7 +208,7 @@ class TMSSDjangoServerInstance(): # wait for server to be up and running.... # or exit via TimeoutError - self.check_running_server(timeout=10) + self.check_running_server(timeout=30) def stop(self): ''' @@ -226,31 +226,29 @@ class TMSSDjangoServerInstance(): def check_running_server(self, timeout: float = 10) -> bool: '''Check the running django server for a valid response''' - try: - import requests, urllib3 - from _datetime import datetime, timedelta - start = datetime.utcnow() - while True: - try: - response = requests.get(self.url, auth=(self.ldap_dbcreds.user, self.ldap_dbcreds.password), timeout=max(1, timeout/10)) - - if response.status_code in [200, 401, 403]: - logger.info("TMSS Django server is up and running at %s with database: %s and LDAP: %s", - self.url, self.database_dbcreds, self.ldap_dbcreds) - - if response.status_code in [401, 403]: - logger.warning("TMSS Django server at %s could not autenticate with LDAP creds: %s", self.url, self.ldap_dbcreds) - - # TODO: logout, otherwise django remembers our login session. - return True - except Exception as e: - time.sleep(0.25) - - if datetime.utcnow() - start > timedelta(seconds=timeout): - raise TimeoutError("Could not get a valid response from the django server at %s" % self.url) - except Exception as e: - logger.error(e) - return False + import requests + from _datetime import datetime, timedelta + start = datetime.utcnow() + while True: + try: + logger.info("Checking if TMSS Django server is up and running at %s with database: %s and LDAP: %s ....", + self.url, self.database_dbcreds, self.ldap_dbcreds) + response = requests.get(self.url, auth=(self.ldap_dbcreds.user, self.ldap_dbcreds.password), timeout=max(1, timeout/10)) + + if response.status_code in [200, 401, 403]: + logger.info("TMSS Django server is up and running at %s with database: %s and LDAP: %s", + self.url, self.database_dbcreds, self.ldap_dbcreds) + + if response.status_code in [401, 403]: + logger.warning("TMSS Django server at %s could not autenticate with LDAP creds: %s", self.url, self.ldap_dbcreds) + + # TODO: logout, otherwise django remembers our login session. + return True + except Exception as e: + time.sleep(0.5) + + if datetime.utcnow() - start > timedelta(seconds=timeout): + raise TimeoutError("Could not get a valid response from the django server at %s within %s seconds" % (self.url,timeout)) def __enter__(self): try: