3
我已经写了一个基于扭曲的服务器,我想用扭曲来测试它。测试扭曲的应用程序 - 加载客户端
但我想写一个负载测试,同时开始一堆请求。
但我相信,我没有得到扭转,主要是客户端的概念,因为我stucked这个问题:
from twisted.internet import reactor, protocol
from threading import Thread
from twisted.protocols.basic import LineReceiver
__author__="smota"
__date__ ="$30/10/2009 17:17:50$"
class SquitterClient(LineReceiver):
def connectionMade(self):
self.sendLine("message from " % threading.current_thread().name);
pass
def connectionLost(self, reason):
print "connection lost"
def sendMessage(self, msg):
for m in [ "a", "b", "c", "d", "e"]:
self.sendLine(msg % " - " % m);
class SquitterClientFactory(protocol.ClientFactory):
protocol = SquitterClient
def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
reactor.stop()
def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
reactor.stop()
def createAndRun():
f = SquitterClientFactory()
reactor.connectTCP("localhost", 4010, f)
reactor.run(installSignalHandlers=0)
# this connects the protocol to a server runing on port 8000
def main():
for n in range(0,10):
th=Thread(target=createAndRun)
th.start()
# this only runs if the module was *not* imported
if __name__ == '__main__':
main()
socket_client.py:35: DeprecationWarning:反应器已经运行了 !因为扭曲的8.0
reactor.run(installSignalHandlers = 0)
我缺少这个特性已经被废弃 ?
如何测试它?
谢谢
塞缪尔
您可能还想指出多个/线程/也不是必需的。 – 2009-11-01 14:20:33
添加关于线程的注释也是不必要的。 – 2009-11-01 14:34:42