Web Proxy to Simulate Network Problems
I need a way to simulate connectivity problems in an automated test suite, on Linux, and preferably from Python. Some sort of proxy that I can put in front of the web server that can hang or drop connections after one trigger or another (after X bytes transferred, etc) would be perfect.
It doesn't seem too hard to build, but I'd rather grab something pre-existing,开发者_运维百科 if anyone has any good recommendations.
when i needed one, i found that building it yourself is the best thing.. start by raising a threaded server in python http://docs.python.org/dev/library/socketserver.html (you don't have to use the class itself). and it's very simple: in the new connection thread, you create a new socket and connects it to the real server. then, you put both of them in a list and sends it to select.select (import select). then, when socket x receive data - sends it to y. when socket y receives data sends it to x. (don't forget to close the socket when you receive empty string).
now you can do whatever you want..
if you need anything, i'm here..
精彩评论