def test_properlyCloseFiles(self):
"""
Test that lost connections properly have their underlying socket
resources cleaned up.
"""
onServerConnectionLost = defer.Deferred()
serverFactory = protocol.ServerFactory()
serverFactory.protocol = lambda: ConnectionLostNotifyingProtocol(
onServerConnectionLost)
serverPort = self.createServer('127.0.0.1', 0, serverFactory)
onClientConnectionLost = defer.Deferred()
serverAddr = serverPort.getHost()
clientCreator = protocol.ClientCreator(
reactor, lambda: HandleSavingProtocol(onClientConnectionLost))
clientDeferred = self.connectClient(
serverAddr.host, serverAddr.port, clientCreator)
def clientConnected(client):
"""
Disconnect the client. Return a Deferred which fires when both
the client and the server have received disconnect notification.
"""
client.transport.loseConnection()
return defer.gatherResults([
onClientConnectionLost, onServerConnectionLost])
clientDeferred.addCallback(clientConnected)
def clientDisconnected((client, server)):
"""
Verify that the underlying platform socket handle has been
cleaned up.
"""
expectedErrorCode = self.getHandleErrorCode()
err = self.assertRaises(
self.getHandleExceptionType(), client.handle.send, 'bytes')
self.assertEqual(err.args[0], expectedErrorCode)
评论列表
文章目录