~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-15 07:44:56 UTC
  • mfrom: (3180.1.3 smart-tcp-unknown-host)
  • Revision ID: pqm@pqm.ubuntu.com-20080115074456-0v1w54h783oq7n48
(andrew) Don't traceback on host name errors when connecting to
        bzr:// URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        return self.vendor.read_from, self.vendor.write_to
81
81
 
82
82
 
 
83
class _InvalidHostnameFeature(tests.Feature):
 
84
    """Does 'non_existent.invalid' fail to resolve?
 
85
    
 
86
    RFC 2606 states that .invalid is reserved for invalid domain names, and
 
87
    also underscores are not a valid character in domain names.  Despite this,
 
88
    it's possible a badly misconfigured name server might decide to always
 
89
    return an address for any name, so this feature allows us to distinguish a
 
90
    broken system from a broken test.
 
91
    """
 
92
 
 
93
    def _probe(self):
 
94
        try:
 
95
            socket.gethostbyname('non_existent.invalid')
 
96
        except socket.gaierror:
 
97
            # The host name failed to resolve.  Good.
 
98
            return True
 
99
        else:
 
100
            return False
 
101
 
 
102
    def feature_name(self):
 
103
        return 'invalid hostname'
 
104
 
 
105
InvalidHostnameFeature = _InvalidHostnameFeature()
 
106
 
83
107
 
84
108
class SmartClientMediumTests(tests.TestCase):
85
109
    """Tests for SmartClientMedium.
443
467
        # really did disconnect.
444
468
        medium.disconnect()
445
469
 
 
470
    def test_tcp_client_host_unknown_connection_error(self):
 
471
        self.requireFeature(InvalidHostnameFeature)
 
472
        client_medium = medium.SmartTCPClientMedium(
 
473
            'non_existent.invalid', 4155)
 
474
        self.assertRaises(
 
475
            errors.ConnectionError, client_medium._ensure_connection)
 
476
 
446
477
 
447
478
class TestSmartClientStreamMediumRequest(tests.TestCase):
448
479
    """Tests the for SmartClientStreamMediumRequest.