Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use policy to determine wait time
Some unit tests needed to be updated.
In particular for the hash exception unit test, because we expect a hash
exception, we don't want to use the ``robot`` policy as that will make
it query and wait unnecessarily.
  • Loading branch information
PGijsbers committed May 6, 2021
commit 94927bca19ddededf975f36ae0ebd994ab658bf0
15 changes: 11 additions & 4 deletions openml/_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,17 @@ def _send_request(request_method, url, data, files=None, md5_checksum=None):
if retry_counter >= n_retries:
raise
else:
wait = retry_counter + (1 / (1 + math.exp(-(retry_counter - 6)))) * 20
variation = random.gauss(0, wait / 10)
wait_time = max(1.0, wait + variation)
time.sleep(wait_time)

def robot(n: int) -> float:
wait = (1 / (1 + math.exp(-(n * 0.5 - 4)))) * 60
variation = random.gauss(0, wait / 10)
return max(1.0, wait + variation)

def human(n: int) -> float:
return max(1.0, n)

delay = {"human": human, "robot": robot}[config.retry_policy](retry_counter)
time.sleep(delay)
if response is None:
raise ValueError("This should never happen!")
return response
Expand Down
4 changes: 3 additions & 1 deletion openml/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def setUp(self, n_levels: int = 1):
openml.config.cache_directory = self.workdir

# Increase the number of retries to avoid spurious server failures
self.retry_policy = openml.config.retry_policy
self.connection_n_retries = openml.config.connection_n_retries
openml.config.connection_n_retries = 10
openml.config.set_retry_policy("robot", n_retries=20)

def tearDown(self):
os.chdir(self.cwd)
Expand All @@ -109,6 +110,7 @@ def tearDown(self):
raise
openml.config.server = self.production_server
openml.config.connection_n_retries = self.connection_n_retries
openml.config.retry_policy = self.retry_policy

@classmethod
def _mark_entity_for_removal(self, entity_type, entity_id):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_datasets/test_dataset_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ def test__getarff_md5_issue(self):
"oml:md5_checksum": "abc",
"oml:url": "https://www.openml.org/data/download/61",
}
n = openml.config.connection_n_retries
Comment thread
mfeurer marked this conversation as resolved.
openml.config.connection_n_retries = 1

self.assertRaisesRegex(
OpenMLHashException,
"Checksum of downloaded file is unequal to the expected checksum abc when downloading "
Expand All @@ -514,6 +517,8 @@ def test__getarff_md5_issue(self):
description,
)

openml.config.connection_n_retries = n

def test__get_dataset_features(self):
features_file = _get_dataset_features_file(self.workdir, 2)
self.assertIsInstance(features_file, str)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_openml/test_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def test_retry_on_database_error(self, Session_class_mock, _):
):
openml._api_calls._send_request("get", "/abc", {})

self.assertEqual(Session_class_mock.return_value.__enter__.return_value.get.call_count, 10)
self.assertEqual(Session_class_mock.return_value.__enter__.return_value.get.call_count, 20)
4 changes: 2 additions & 2 deletions tests/test_openml/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_get_config_as_dict(self):
_config["server"] = "https://test.openml.org/api/v1/xml"
_config["cachedir"] = self.workdir
_config["avoid_duplicate_runs"] = False
_config["connection_n_retries"] = 10
_config["retry_policy"] = "human"
_config["connection_n_retries"] = 20
_config["retry_policy"] = "robot"
self.assertIsInstance(config, dict)
self.assertEqual(len(config), 6)
self.assertDictEqual(config, _config)
Expand Down