def setUp(self): def fakefromfd(fd, addressFamily, socketType): return FakeSocket(self) def fakerecvfd(fd): return "not an fd", "not a description" def fakeclose(fd): "" def fakegetsockfam(fd): return AF_INET self.patch(sendfdport, 'recvfd', fakerecvfd) self.patch(sendfdport, 'fromfd', fakefromfd) self.patch(sendfdport, 'close', fakeclose) self.patch(sendfdport, 'getsockfam', fakegetsockfam) self.patch(metafd, 'InheritedPort', InheritedPortForTesting) self.patch(metafd, 'Server', ServerTransportForTesting) # This last stubbed out just to prevent dirty reactor warnings. self.patch(HTTPChannel, "callLater", lambda *a, **k: None) self.svc = ReportingHTTPService(None, None, None) self.svc.startService()
class ReportingHTTPServiceTests(TestCase): """ Tests for L{ReportingHTTPService} """ peerNameSucceed = True def setUp(self): def fakefromfd(fd, addressFamily, socketType): return FakeSocket(self) def fakerecvfd(fd): return "not an fd", "not a description" def fakeclose(fd): "" def fakegetsockfam(fd): return AF_INET self.patch(sendfdport, 'recvfd', fakerecvfd) self.patch(sendfdport, 'fromfd', fakefromfd) self.patch(sendfdport, 'close', fakeclose) self.patch(sendfdport, 'getsockfam', fakegetsockfam) self.patch(metafd, 'InheritedPort', InheritedPortForTesting) self.patch(metafd, 'Server', ServerTransportForTesting) # This last stubbed out just to prevent dirty reactor warnings. self.patch(HTTPChannel, "callLater", lambda *a, **k: None) self.svc = ReportingHTTPService(None, None, None) self.svc.startService() def test_quickClosedSocket(self): """ If a socket is closed very quickly after being {accept()}ed, requesting its peer (or even host) address may fail with C{ENOTCONN}. If this happens, its transport should be supplied with a dummy peer address. """ self.peerNameSucceed = False self.svc.reportingFactory.inheritedPort.doRead() channels = self.svc.reportingFactory.connectedChannels self.assertEqual(len(channels), 1) self.assertEqual(list(channels)[0].transport.getPeer().host, "0.0.0.0")