Ticket #4710: endpoint_test.py

File endpoint_test.py, 0.9 KB (added by marienz, 3 years ago)

failing testcase

Line 
1
2
3import socket
4
5from twisted.trial import unittest
6from twisted.internet import endpoints, protocol
7
8
9class TestFactory(protocol.Factory):
10
11    def buildProtocol(self, addr):
12        raise Exception('we should not get this far')
13
14
15class HorribleTest(unittest.TestCase):
16
17    def test_TCP4ClientConnectionCancelled(self):
18        # Create an actual socket (listening on loopback) to test against.
19        # We are never going to accept connection attempts on it.
20        sock = socket.socket()
21        sock.bind(('127.0.0.1', 0))
22        sock.listen(1)
23        self.addCleanup(sock.close)
24
25        localhost, port = sock.getsockname()
26
27        from twisted.internet import reactor
28
29        ep = endpoints.TCP4ClientEndpoint(reactor, localhost, port)
30
31        factory = TestFactory()
32
33        d = ep.connect(factory)
34
35        d.cancel()
36
37        return self.assertFailure(d, error.ConnectingCancelledError)