Ticket #2447: test_cl.py

File test_cl.py, 907 bytes (added by ghazel, 15 years ago)

testcase that leaves the reactor unclean.

Line 
1from twisted.trial import unittest
2from twisted.web import server, resource
3from twisted.internet import protocol, defer, reactor
4
5
6class C(protocol.Protocol):
7
8    def connectionMade(self):
9        self.transport.write("GET / HTTP/1.0\r\n\r\n")
10        self.transport.loseConnection()
11
12    def connectionLost(self, reason):
13        self.factory.deferred.callback(1)
14
15
16class R(resource.Resource):
17
18    def render(self, request):
19        return "blagoblag"
20
21
22class TestCL(unittest.TestCase):
23
24    def testCL(self):
25
26        hi_factory = server.Site(R())
27        tport = reactor.listenTCP(19999, hi_factory)
28
29        f = protocol.ClientFactory()
30        f.protocol = C
31        f.deferred = defer.Deferred()
32        reactor.connectTCP('localhost', 19999, f)
33
34        def done(r):
35            hi_factory.doStop()
36            tport.stopListening()
37        f.deferred.addCallback(done)
38
39        return f.deferred