#NEWLINE# def test_server_changes_go_to_client( self ) : #NEWLINE# #INDENT# application = Application ( ) #NEWLINE# with ManagedServerLoop ( application ) as server : #NEWLINE# #INDENT# doc = document . Document ( ) #NEWLINE# client_session = push_session ( doc , session_id = 'test_server_changes_go_to_client' , url = url ( server ) , io_loop = server . io_loop ) #NEWLINE# server_session = server . get_session ( '/' , do_remove_server_root . id ) #NEWLINE# assert ( len ( client_session . document . roots ) == 0 ) #NEWLINE# server_root = SomeModelInTestClientServer ( foo = 42 ) #NEWLINE# def do_add_server_root( ) : #NEWLINE# #INDENT# server_session . document . add_root ( server_root ) #NEWLINE# #UNINDENT# server_session . with_document_locked ( do_add_server_root ) #NEWLINE# def client_has_root( ) : #NEWLINE# #INDENT# return ( len ( doc . roots ) > 0 ) #NEWLINE# #UNINDENT# client_session . _connection . _loop_until ( client_has_root ) #NEWLINE# client_root = next ( iter ( client_session . document . roots ) ) #NEWLINE# assert ( client_root . foo == 42 ) #NEWLINE# assert ( server_root . foo == 42 ) #NEWLINE# def do_set_server_title( ) : #NEWLINE# #INDENT# server_session . document . title = 'Server Title' #NEWLINE# #UNINDENT# server_session . with_document_locked ( do_set_server_title ) #NEWLINE# def client_title_set( ) : #NEWLINE# #INDENT# return ( client_session . document . title != document . DEFAULT_TITLE ) #NEWLINE# #UNINDENT# client_session . _connection . _loop_until ( client_title_set ) #NEWLINE# assert ( client_session . document . title == 'Server Title' ) #NEWLINE# def do_set_property_on_server( ) : #NEWLINE# #INDENT# server_root . foo = 57 #NEWLINE# #UNINDENT# server_session . with_document_locked ( do_set_property_on_server ) #NEWLINE# def client_change_made( ) : #NEWLINE# #INDENT# return ( client_root . foo == 57 ) #NEWLINE# #UNINDENT# client_session . _connection . _loop_until ( client_change_made ) #NEWLINE# assert ( client_root . foo == 57 ) #NEWLINE# def do_remove_server_root( ) : #NEWLINE# #INDENT# server_session . document . remove_root ( server_root ) #NEWLINE# #UNINDENT# server_session . with_document_locked ( do_remove_server_root ) #NEWLINE# def client_lacks_root( ) : #NEWLINE# #INDENT# return ( len ( doc . roots ) == 0 ) #NEWLINE# #UNINDENT# client_session . _connection . _loop_until ( client_lacks_root ) #NEWLINE# assert ( len ( client_session . document . roots ) == 0 ) #NEWLINE# client_session . close ( ) #NEWLINE# client_session . loop_until_closed ( ) #NEWLINE# assert ( not client_session . connected )