Skip to content

Commit

Permalink
Trying to fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabbasrizvi committed Oct 24, 2019
1 parent 153e8f9 commit b2eb96c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/test_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ def test_get_config(self):
# Assert that config is set.
self.assertIsInstance(project_config_manager.get_config(), project_config.ProjectConfig)

def test_get_config_blocks(self):
""" Test that get_config blocks until blocking timeout is hit. """
start_time = time.time()
project_config_manager = config_manager.PollingConfigManager(sdk_key='sdk_key',
blocking_timeout=5)
# Assert get_config should block until blocking timeout.
project_config_manager.get_config()
end_time = time.time()
self.assertEqual(5, round(end_time - start_time))


@mock.patch('requests.get')
class PollingConfigManagerTest(base.BaseTest):
Expand Down Expand Up @@ -217,7 +227,8 @@ def test_get_datafile_url__sdk_key_and_url_and_template_provided(self, _):

def test_set_update_interval(self, _):
""" Test set_update_interval with different inputs. """
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')
with mock.patch('optimizely.config_manager.PollingConfigManager.fetch_datafile'):
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')

# Assert that if invalid update_interval is set, then exception is raised.
with self.assertRaisesRegexp(optimizely_exceptions.InvalidInputException,
Expand All @@ -238,7 +249,8 @@ def test_set_update_interval(self, _):

def test_set_blocking_timeout(self, _):
""" Test set_blocking_timeout with different inputs. """
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')
with mock.patch('optimizely.config_manager.PollingConfigManager.fetch_datafile'):
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')

# Assert that if invalid blocking_timeout is set, then exception is raised.
with self.assertRaisesRegexp(optimizely_exceptions.InvalidInputException,
Expand All @@ -261,16 +273,10 @@ def test_set_blocking_timeout(self, _):
project_config_manager.set_blocking_timeout(5)
self.assertEqual(5, project_config_manager.blocking_timeout)

# Assert get_config should block until blocking timeout.
project_config_manager._config_ready_event.clear()
start_time = time.time()
project_config_manager.get_config()
end_time = time.time()
self.assertEqual(5, round(end_time - start_time))

def test_set_last_modified(self, _):
""" Test that set_last_modified sets last_modified field based on header. """
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')
with mock.patch('optimizely.config_manager.PollingConfigManager.fetch_datafile'):
project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key')

last_modified_time = 'Test Last Modified Time'
test_response_headers = {
Expand Down

0 comments on commit b2eb96c

Please sign in to comment.