#NEWLINE# def test_lots_of_concurrent_messages( self ) : #NEWLINE# #INDENT# application = Application ( ) #NEWLINE# def setup_stuff( doc ) : #NEWLINE# #INDENT# m1 = AnotherModelInTestClientServer ( bar = 43 , name = 'm1' ) #NEWLINE# m2 = SomeModelInTestClientServer ( foo = 42 , name = 'm2' ) #NEWLINE# m3 = SomeModelInTestClientServer ( foo = 68 , name = 'm3' ) #NEWLINE# doc . add_root ( m1 ) #NEWLINE# doc . add_root ( m2 ) #NEWLINE# doc . add_root ( m3 ) #NEWLINE# def timeout1( ) : #NEWLINE# #INDENT# m1 . bar += 1 #NEWLINE# #UNINDENT# doc . add_timeout_callback ( timeout1 , 1 ) #NEWLINE# def timeout2( ) : #NEWLINE# #INDENT# m2 . foo += 1 #NEWLINE# #UNINDENT# doc . add_timeout_callback ( timeout2 , 3 ) #NEWLINE# def periodic1( ) : #NEWLINE# #INDENT# m1 . bar += 1 #NEWLINE# doc . remove_timeout_callback ( timeout1 ) #NEWLINE# doc . add_timeout_callback ( timeout1 , ( m1 . bar % 7 ) ) #NEWLINE# #UNINDENT# doc . add_periodic_callback ( periodic1 , 3 ) #NEWLINE# def periodic2( ) : #NEWLINE# #INDENT# m2 . foo += 1 #NEWLINE# doc . remove_timeout_callback ( timeout2 ) #NEWLINE# doc . add_timeout_callback ( timeout2 , ( m2 . foo % 7 ) ) #NEWLINE# #UNINDENT# doc . add_periodic_callback ( periodic2 , 1 ) #NEWLINE# def server_on_change( event ) : #NEWLINE# #INDENT# if ( isinstance ( event , ModelChangedEvent ) and ( event . model is m3 ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# m3 . foo += 1 #NEWLINE# #UNINDENT# doc . on_change ( server_on_change ) #NEWLINE# #UNINDENT# handler = FunctionHandler ( setup_stuff ) #NEWLINE# application . add ( handler ) #NEWLINE# with ManagedServerLoop ( application , keep_alive_milliseconds = 1 ) as server : #NEWLINE# #INDENT# session = pull_session ( session_id = 'test_lots_of_concurrent_messages' , url = url ( server ) , io_loop = server . io_loop ) #NEWLINE# assert session . connected #NEWLINE# server_session = server . get_session ( '/' , session . id ) #NEWLINE# def client_timeout( ) : #NEWLINE# #INDENT# m = session . document . roots [ 0 ] #NEWLINE# m . name = m . name [ : : ( - 1 ) ] #NEWLINE# #UNINDENT# session . document . add_timeout_callback ( client_timeout , 3 ) #NEWLINE# def client_periodic( ) : #NEWLINE# #INDENT# m = session . document . roots [ 1 ] #NEWLINE# m . name = m . name [ : : ( - 1 ) ] #NEWLINE# session . document . remove_timeout_callback ( client_timeout ) #NEWLINE# session . document . add_timeout_callback ( client_timeout , 3 ) #NEWLINE# #UNINDENT# session . document . add_periodic_callback ( client_periodic , 1 ) #NEWLINE# result = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# def end_test( ) : #NEWLINE# #INDENT# result [ 'connected' ] = session . connected #NEWLINE# result [ 'server_connection_count' ] = server_session . connection_count #NEWLINE# result [ 'server_close_code' ] = next ( iter ( server . _tornado . _clients ) ) . _socket . close_code #NEWLINE# result [ 'doc' ] = session . document . to_json ( ) #NEWLINE# session . close ( ) #NEWLINE# #UNINDENT# session . document . add_timeout_callback ( end_test , 250 ) #NEWLINE# def client_on_change( event ) : #NEWLINE# #INDENT# if ( not isinstance ( event , TitleChangedEvent ) ) : #NEWLINE# #INDENT# session . document . title = session . document . title [ : : ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# session . document . on_change ( end_test ) #NEWLINE# session . loop_until_closed ( ) #NEWLINE# assert ( not session . connected ) #NEWLINE# assert ( 'connected' in result ) #NEWLINE# assert result [ 'connected' ] #NEWLINE# assert ( result [ 'server_connection_count' ] == 1 ) #NEWLINE# assert ( result [ 'server_close_code' ] is None )