def test_constructor_with_unreachable_addresses(self): addr = Address("192.168.0.1", 5701) config = _Config() start = time.time() conn = AsyncoreConnection(MagicMock(map=dict()), MagicMock(), None, addr, config, None) try: # Server is unreachable, but this call should return # before connection timeout self.assertLess(time.time() - start, config.connection_timeout) finally: conn.close(None, None)
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(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))