<s> import time <EOL> import monocle <EOL> from monocle import _o <EOL> from monocle . stack . network import add_service , Service , Client , ConnectionLost <EOL> from o_test import test <EOL> @ _o <EOL> def handle_echo ( conn ) : <EOL> while True : <EOL> try : <EOL> message = yield conn . read_until ( '<STR_LIT:\r\n>' ) <EOL> except ConnectionLost : <EOL> break <EOL> yield conn . write ( "<STR_LIT>" % message . strip ( ) ) <EOL> @ test <EOL> @ _o <EOL> def test_lots_of_messages ( ) : <EOL> add_service ( Service ( handle_echo , port = <NUM_LIT> ) ) <EOL> try : <EOL> client = Client ( ) <EOL> yield client . connect ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> t = time . time ( ) <EOL> for x in xrange ( <NUM_LIT> ) : <EOL> msg = "<STR_LIT>" % x <EOL> yield client . write ( msg + '<STR_LIT:\r\n>' ) <EOL> echo_result = yield client . read_until ( "<STR_LIT:\r\n>" ) <EOL> assert echo_result . strip ( ) == "<STR_LIT>" % msg <EOL> print '<STR_LIT>' % ( time . time ( ) - t ) <EOL> finally : <EOL> client . close ( ) </s>
