Esempio n. 1
0
 def test_reject_invalidation(self):
     """Test rejecting invalidation."""
     fd, tmp_file = tempfile.mkstemp()
     with open(tmp_file, 'w') as f:
         f.write('\n'.join(HostSelectorWithLocalFileTestCase.HOST_LIST))
     host_provider = HostsProvider(HostSelectorWithLocalFileTestCase.HOST_LIST, file_path=tmp_file)
     base_host_selector = BaseHostSelector(host_provider, expire_time=0, retry_time=0)
     with patch(hosts.__name__ + ".BaseHostSelector._choose_host",
                new=Mock(return_value=HostSelectorWithLocalFileTestCase.HOST_LIST[0])):
         # Get one host.
         host1 = base_host_selector.get_host()
         self.assertEquals(host1, HostSelectorWithLocalFileTestCase.HOST_LIST[0])
         # If invalidated the state of the object changes.
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector.invalidate()
         # Because 1 is larger than 2 * 0.2 = 0.4
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector._invalidation_threshold = 0.5
         host1 = base_host_selector.get_host()
         self.assertEquals(host1, HostSelectorWithLocalFileTestCase.HOST_LIST[0])
         base_host_selector.invalidate()
         # Because 1 <= 2 * 0.5 = 1.0
         self.assertTrue(host1 in base_host_selector._bad_hosts)
     HostSelectorWithLocalFileTestCase.FILE_WATCH._clear_all_watches()
     os.remove(tmp_file)
Esempio n. 2
0
 def test_reject_invalidation(self):
     """Test rejecting invalidation."""
     fd, tmp_file = tempfile.mkstemp()
     with open(tmp_file, 'w') as f:
         f.write('\n'.join(HostSelectorWithLocalFileTestCase.HOST_LIST))
     host_provider = HostsProvider(
         HostSelectorWithLocalFileTestCase.HOST_LIST, file_path=tmp_file)
     base_host_selector = BaseHostSelector(host_provider,
                                           expire_time=0,
                                           retry_time=0)
     with patch(hosts.__name__ + ".BaseHostSelector._choose_host",
                new=Mock(return_value=HostSelectorWithLocalFileTestCase.
                         HOST_LIST[0])):
         # Get one host.
         host1 = base_host_selector.get_host()
         self.assertEquals(host1,
                           HostSelectorWithLocalFileTestCase.HOST_LIST[0])
         # If invalidated the state of the object changes.
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector.invalidate()
         # Because 1 is larger than 2 * 0.2 = 0.4
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector._invalidation_threshold = 0.5
         host1 = base_host_selector.get_host()
         self.assertEquals(host1,
                           HostSelectorWithLocalFileTestCase.HOST_LIST[0])
         base_host_selector.invalidate()
         # Because 1 <= 2 * 0.5 = 1.0
         self.assertTrue(host1 in base_host_selector._bad_hosts)
     HostSelectorWithLocalFileTestCase.FILE_WATCH._clear_all_watches()
     os.remove(tmp_file)
Esempio n. 3
0
 def test_reject_invalidation(self):
     """Test rejecting invalidation."""
     host_provider = HostsProvider(HostSelectorTestCase.HOST_LIST)
     base_host_selector = BaseHostSelector(host_provider, expire_time=0,
                                           retry_time=0)
     with patch(hosts.__name__ + ".BaseHostSelector._choose_host",
                new=Mock(return_value=HostSelectorTestCase.HOST_LIST[0])):
         # Get one host.
         host1 = base_host_selector.get_host()
         self.assertEquals(host1, HostSelectorTestCase.HOST_LIST[0])
         # If invalidated the state of the object changes.
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector.invalidate()
         # Because 1 is larger than 2 * 0.2 = 0.4
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector._invalidation_threshold = 0.5
         host1 = base_host_selector.get_host()
         self.assertEquals(host1, HostSelectorTestCase.HOST_LIST[0])
         base_host_selector.invalidate()
         # Because 1 <= 2 * 0.5 = 1.0
         self.assertTrue(host1 in base_host_selector._bad_hosts)
Esempio n. 4
0
 def test_reject_invalidation(self):
     """Test rejecting invalidation."""
     host_provider = HostsProvider(HostSelectorTestCase.HOST_LIST)
     base_host_selector = BaseHostSelector(host_provider,
                                           expire_time=0,
                                           retry_time=0)
     with patch(hosts.__name__ + ".BaseHostSelector._choose_host",
                new=Mock(return_value=HostSelectorTestCase.HOST_LIST[0])):
         # Get one host.
         host1 = base_host_selector.get_host()
         self.assertEquals(host1, HostSelectorTestCase.HOST_LIST[0])
         # If invalidated the state of the object changes.
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector.invalidate()
         # Because 1 is larger than 2 * 0.2 = 0.4
         self.assertTrue(host1 not in base_host_selector._bad_hosts)
         base_host_selector._invalidation_threshold = 0.5
         host1 = base_host_selector.get_host()
         self.assertEquals(host1, HostSelectorTestCase.HOST_LIST[0])
         base_host_selector.invalidate()
         # Because 1 <= 2 * 0.5 = 1.0
         self.assertTrue(host1 in base_host_selector._bad_hosts)