私のクライアント(ねじれに基づいて)は、接続が失われたときに自動的にサーバーに再接続するはずです。私はこの機能のテストを行う必要があります。@todoコメントがどのような動作が期待されるかについて非常に明確なテスト方法です。Pythonでサーバーをシャットダウンして起動する方法Twisted?
サーバー側では@defer.inlineCallbacks
def test_reconnect_on_connection_loss(self):
client = SMPPClientFactory(self.config)
client.reConnect = mock.Mock(wraps=client.reConnect)
# Connect
smpp = yield client.connect()
# Bind
yield smpp.bindAsTransmitter()
# @todo: A connection loss is expected here
# the client is supposed to try reconnections
# for a while, the server then shall start
# again and the client will get connected.
# Unbind & Disconnect
yield smpp.unbindAndDisconnect()
##############
# Assertions :
# Protocol verification
self.assertNotEqual(0, client.reConnect.call_count)
、ちょうどbindAsTransmitter要求を受信した後、接続中止しようとしています:接続が正常に中止され
class LooseConnectionOnBindSMSC(SMSC):
def handleBindAsTransmitter(self, reqPDU):
self.sendSuccessResponse(reqPDU)
# Connection is aborted here:
self.transport.abortConnection()
、私のクライアントは期待通りに再接続しようとして開始しますが、それは道を取得することはありません私のサーバーを再びUPする。
Jean paulはい、サーバーはまだ私がabortConnectionサーバー側を聞いています...私は数秒間リッスンを停止し、再度開始する方法が必要です。 –