From 3c231f438fb01aab4603ab252fd02c0f92844a9d Mon Sep 17 00:00:00 2001 From: thomasstorm Date: Tue, 16 Jan 2024 13:54:14 +0100 Subject: [PATCH 1/4] fixing #886 --- xcube/server/testing.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xcube/server/testing.py b/xcube/server/testing.py index cb5e5281c..4f16b537b 100644 --- a/xcube/server/testing.py +++ b/xcube/server/testing.py @@ -23,6 +23,7 @@ import json import socket import threading +import time import unittest from abc import ABC from contextlib import closing @@ -65,6 +66,14 @@ def setUp(self) -> None: self.http = urllib3.PoolManager() + while True: + # noinspection PyBroadException + try: + self.fetch('/') + break + except Exception: + time.sleep(0.1) + def tearDown(self) -> None: self.server.stop() From be57273412ee55c2a13ae3d492ae395ab74ce94e Mon Sep 17 00:00:00 2001 From: thomasstorm Date: Tue, 16 Jan 2024 23:11:52 +0100 Subject: [PATCH 2/4] update according to change requests - ensuring that test won't run endlessly if the server does not start properly --- xcube/server/testing.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xcube/server/testing.py b/xcube/server/testing.py index 4f16b537b..98d89851c 100644 --- a/xcube/server/testing.py +++ b/xcube/server/testing.py @@ -31,6 +31,7 @@ import urllib3 from tornado.platform.asyncio import AnyThreadEventLoopPolicy +from urllib3.exceptions import MaxRetryError from xcube.server.server import Server from xcube.server.webservers.tornado import TornadoFramework @@ -66,13 +67,20 @@ def setUp(self) -> None: self.http = urllib3.PoolManager() + # Taking care that server is fully started until tests make requests. + # Fixing https://github.com/dcs4cop/xcube/issues/899 + elapsed_time = 0.0 while True: - # noinspection PyBroadException + if elapsed_time > 60: + self.fail('Server did not respond after one minute. ' + 'Failing the test.') try: self.fetch('/') break - except Exception: - time.sleep(0.1) + except (MaxRetryError, TimeoutError): + sleep_time = 0.1 + time.sleep(sleep_time) + elapsed_time += sleep_time def tearDown(self) -> None: self.server.stop() From 8a18c55153009a361866168637f5410d4c9112d1 Mon Sep 17 00:00:00 2001 From: thomasstorm Date: Tue, 16 Jan 2024 23:14:49 +0100 Subject: [PATCH 3/4] removed check which took care of a case that never appeared. --- xcube/server/testing.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xcube/server/testing.py b/xcube/server/testing.py index 98d89851c..68eb83d44 100644 --- a/xcube/server/testing.py +++ b/xcube/server/testing.py @@ -69,18 +69,12 @@ def setUp(self) -> None: # Taking care that server is fully started until tests make requests. # Fixing https://github.com/dcs4cop/xcube/issues/899 - elapsed_time = 0.0 while True: - if elapsed_time > 60: - self.fail('Server did not respond after one minute. ' - 'Failing the test.') try: self.fetch('/') break except (MaxRetryError, TimeoutError): - sleep_time = 0.1 - time.sleep(sleep_time) - elapsed_time += sleep_time + time.sleep(0.1) def tearDown(self) -> None: self.server.stop() From 7102fbb5901793e083ede210aaa2042c84b7e2ac Mon Sep 17 00:00:00 2001 From: Thomas Storm Date: Thu, 18 Jan 2024 11:28:16 +0100 Subject: [PATCH 4/4] Update xcube/server/testing.py Co-authored-by: Pontus Lurcock --- xcube/server/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcube/server/testing.py b/xcube/server/testing.py index 68eb83d44..09779ee03 100644 --- a/xcube/server/testing.py +++ b/xcube/server/testing.py @@ -67,7 +67,7 @@ def setUp(self) -> None: self.http = urllib3.PoolManager() - # Taking care that server is fully started until tests make requests. + # Taking care that server is fully started before tests make requests. # Fixing https://github.com/dcs4cop/xcube/issues/899 while True: try: