Skip to content

Commit 2f00b4d

Browse files
authored
Mpirnovar update error (#433)
* updare error log message * test for the log message * upate to generic exception
1 parent 3d1a21c commit 2f00b4d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

optimizely/config_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ def _run(self) -> None:
420420
if self.stopped.wait(self.update_interval):
421421
self.stopped.clear()
422422
break
423-
except (OSError, OverflowError) as err:
423+
except Exception as err:
424424
self.logger.error(
425-
f'Provided update_interval value may be too big. Error: {err}'
425+
f'Thread for background datafile polling failed. Error: {err}'
426426
)
427427
raise
428428

tests/test_config_manager.py

+26
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,32 @@ def test_fetch_datafile__request_exception_raised(self, _):
494494
self.assertEqual(test_headers['Last-Modified'], project_config_manager.last_modified)
495495
self.assertIsInstance(project_config_manager.get_config(), project_config.ProjectConfig)
496496

497+
def test_fetch_datafile__exception_polling_thread_failed(self, _):
498+
""" Test that exception is raised when polling thread stops. """
499+
sdk_key = 'some_key'
500+
mock_logger = mock.Mock()
501+
502+
test_headers = {'Last-Modified': 'New Time'}
503+
test_datafile = json.dumps(self.config_dict_with_features)
504+
test_response = requests.Response()
505+
test_response.status_code = 200
506+
test_response.headers = test_headers
507+
test_response._content = test_datafile
508+
509+
with mock.patch('requests.get', return_value=test_response):
510+
project_config_manager = config_manager.PollingConfigManager(sdk_key=sdk_key,
511+
logger=mock_logger,
512+
update_interval=12345678912345)
513+
514+
project_config_manager.stop()
515+
516+
# verify the error log message
517+
log_messages = [args[0] for args, _ in mock_logger.error.call_args_list]
518+
for message in log_messages:
519+
if "Thread for background datafile polling failed. " \
520+
"Error: timestamp too large to convert to C _PyTime_t" not in message:
521+
assert False
522+
497523
def test_is_running(self, _):
498524
""" Test that polling thread is running after instance of PollingConfigManager is created. """
499525
with mock.patch('optimizely.config_manager.PollingConfigManager.fetch_datafile'):

0 commit comments

Comments
 (0)