Esempio n. 1
0
 def test_constructor_with_unreachable_addresses(self):
     addr = Address("192.168.0.1", 5701)
     config = _Config()
     start = get_current_timestamp()
     conn = AsyncoreConnection(MagicMock(map=dict()), MagicMock(), None,
                               addr, config, None)
     try:
         # Server is unreachable, but this call should return
         # before connection timeout
         self.assertLess(get_current_timestamp() - start,
                         config.connection_timeout)
     finally:
         conn.close_connection(None, None)
Esempio n. 2
0
 def test_resources_cleaned_up_after_immediate_failure(self):
     addr = Address("invalid-address", 5701)
     config = _Config()
     mock_reactor = MagicMock(map={})
     try:
         conn = AsyncoreConnection(mock_reactor, MagicMock(), None, addr,
                                   config, None)
         conn.close_connection(None, None)
         self.fail(
             "Connection attempt to an invalid address should fail immediately"
         )
     except socket.error:
         # Constructor of the connection should remove itself from the
         # dispatchers map of the reactor.
         self.assertEqual(0, len(mock_reactor.map))