Пример #1
0
def test_endpoint():
    # Create environment
    server, session, transport, conn = _get_test_environment()

    # Connect endpoint
    transport.recv(proto.connect('/test?a=123&b=456'))

    # Verify that client received connect message
    eq_(transport.pop_outgoing(), '1::/test')

    # Verify that connection object was created
    conn_test = session.endpoints['/test']
    eq_(conn_test.endpoint, '/test')
    eq_(conn_test.is_open, True)
    eq_(conn_test.request.arguments, dict(a=['123'], b=['456']))
    eq_(conn_test.request.get_argument('a'), '123')

    # Send message to endpoint and verify that it was received
    transport.recv(proto.message('/test', 'abc'))
    eq_(conn_test.pop_incoming(), 'abc')
    eq_(transport.pop_outgoing(), '3::/test:abc')

    # Close endpoint connection from client
    transport.recv(proto.disconnect('/test'))

    # Verify that everything was cleaned up
    eq_(transport.pop_outgoing(), '0::/test')
    eq_(conn_test.is_open, False)
    eq_(conn.is_open, True)
    eq_(session.is_closed, False)

    eq_(session.endpoints, dict())

    # Open another endpoint connection
    transport.recv(proto.connect('/test2'))

    # Verify that client received connect message
    eq_(transport.pop_outgoing(), '1::/test2')

    # Get connection
    conn_test = session.endpoints['/test2']
    eq_(conn_test.request.arguments, dict())

    # Close main connection
    transport.recv(proto.disconnect())

    # Check if connections were closed and sent out
    eq_(transport.pop_outgoing(), '0::/test2')
    eq_(transport.pop_outgoing(), '0::')

    eq_(conn_test.is_open, False)
    eq_(conn.is_open, False)
    eq_(session.is_closed, True)
Пример #2
0
def test_endpoint():
    # Create environment
    server, session, transport, conn = _get_test_environment()

    # Connect endpoint
    transport.recv(proto.connect('/test?a=123&b=456'))

    # Verify that client received connect message
    eq_(transport.pop_outgoing(), '1::/test')

    # Verify that connection object was created
    conn_test = session.endpoints['/test']
    eq_(conn_test.endpoint, '/test')
    eq_(conn_test.is_open, True)
    eq_(conn_test.request.arguments, dict(a=['123'], b=['456']))
    eq_(conn_test.request.get_argument('a'), '123')

    # Send message to endpoint and verify that it was received
    transport.recv(proto.message('/test', 'abc'))
    eq_(conn_test.pop_incoming(), 'abc')
    eq_(transport.pop_outgoing(), '3::/test:abc')

    # Close endpoint connection from client
    transport.recv(proto.disconnect('/test'))

    # Verify that everything was cleaned up
    eq_(transport.pop_outgoing(), '0::/test')
    eq_(conn_test.is_open, False)
    eq_(conn.is_open, True)
    eq_(session.is_closed, False)

    eq_(session.endpoints, dict())

    # Open another endpoint connection
    transport.recv(proto.connect('/test2'))

    # Verify that client received connect message
    eq_(transport.pop_outgoing(), '1::/test2')

    # Get connection
    conn_test = session.endpoints['/test2']
    eq_(conn_test.request.arguments, dict())

    # Close main connection
    transport.recv(proto.disconnect())

    # Check if connections were closed and sent out
    eq_(transport.pop_outgoing(), '0::/test2')
    eq_(transport.pop_outgoing(), '0::')

    eq_(conn_test.is_open, False)
    eq_(conn.is_open, False)
    eq_(session.is_closed, True)
Пример #3
0
def test_endpoint():
    # Create environment
    server, session, transport, conn = _get_test_environment()

    # Connect endpoint
    transport.recv(proto.connect("/test?a=123&b=456"))

    # Verify that client received connect message
    eq_(transport.pop_outgoing(), "1::/test")

    # Verify that connection object was created
    conn_test = session.endpoints["/test"]
    eq_(conn_test.endpoint, "/test")
    eq_(conn_test.is_open, True)
    eq_(conn_test.request.arguments, dict(a=["123"], b=["456"]))
    eq_(conn_test.request.get_argument("a"), "123")

    # Send message to endpoint and verify that it was received
    transport.recv(proto.message("/test", "abc"))
    eq_(conn_test.pop_incoming(), "abc")
    eq_(transport.pop_outgoing(), "3::/test:abc")

    # Close endpoint connection from client
    transport.recv(proto.disconnect("/test"))

    # Verify that everything was cleaned up
    eq_(transport.pop_outgoing(), "0::/test")
    eq_(conn_test.is_open, False)
    eq_(conn.is_open, True)
    eq_(session.is_closed, False)

    eq_(session.endpoints, dict())

    # Open another endpoint connection
    transport.recv(proto.connect("/test2"))

    # Verify that client received connect message
    eq_(transport.pop_outgoing(), "1::/test2")

    # Get connection
    conn_test = session.endpoints["/test2"]
    eq_(conn_test.request.arguments, dict())

    # Close main connection
    transport.recv(proto.disconnect())

    # Check if connections were closed and sent out
    eq_(transport.pop_outgoing(), "0::/test2")
    eq_(transport.pop_outgoing(), "0::")

    eq_(conn_test.is_open, False)
    eq_(conn.is_open, False)
    eq_(session.is_closed, True)
Пример #4
0
    def close(self, endpoint=None):
        """Close session or endpoint connection.

        `endpoint`
            If endpoint is passed, will close open endpoint connection. Otherwise
            will close whole socket.
        """
        if endpoint is None:
            if not self.conn.is_closed:
                # Close child connections
                for k in self.endpoints.keys():
                    self.disconnect_endpoint(k)

                # Close parent connections
                try:
                    self.conn.on_close()
                finally:
                    self.conn.is_closed = True

                    # Stats
                    self.server.stats.session_closed()

                # Stop heartbeats
                self.stop_heartbeat()

                # Send disconnection message
                self.send_message(proto.disconnect())

                # Notify transport that session was closed
                if self.handler is not None:
                    self.handler.session_closed()
        else:
            # Disconnect endpoint
            self.disconnect_endpoint(endpoint)
Пример #5
0
    def close(self, endpoint=None):
        """Close session or endpoint connection.

        `endpoint`
            If endpoint is passed, will close open endpoint connection. Otherwise
            will close whole socket.
        """
        if endpoint is None:
            if not self.conn.is_closed:
                # Close child connections
                for k in self.endpoints.keys():
                    self.disconnect_endpoint(k)

                # Close parent connections
                try:
                    self.conn.on_close()
                finally:
                    self.conn.is_closed = True

                    # Stats
                    self.server.stats.session_closed()

                # Stop heartbeats
                self.stop_heartbeat()

                # Send disconnection message
                self.send_message(proto.disconnect())

                # Notify transport that session was closed
                if self.handler is not None:
                    self.handler.session_closed()
        else:
            # Disconnect endpoint
            self.disconnect_endpoint(endpoint)
Пример #6
0
def test_client_disconnect():
    # Create environment
    server, session, transport, conn = _get_test_environment()

    # Send disconnect message
    transport.recv(proto.disconnect())

    # Check if connection was closed
    eq_(transport.pop_outgoing(), '0::')

    eq_(conn.is_open, False)
    eq_(session.is_closed, True)
Пример #7
0
def test_client_disconnect():
    # Create environment
    server, session, transport, conn = _get_test_environment()

    # Send disconnect message
    transport.recv(proto.disconnect())

    # Check if connection was closed
    eq_(transport.pop_outgoing(), '0::')

    eq_(conn.is_open, False)
    eq_(session.is_closed, True)
Пример #8
0
    def disconnect_endpoint(self, endpoint):
        """Disconnect endpoint

        `endpoint`
            endpoint name
        """
        if endpoint not in self.endpoints:
            logging.error('Invalid endpoint for disconnect %s' % endpoint)
            return

        conn = self.endpoints[endpoint]

        del self.endpoints[endpoint]

        conn.on_close()
        self.send_message(proto.disconnect(endpoint))
Пример #9
0
    def disconnect_endpoint(self, endpoint):
        """Disconnect endpoint

        `endpoint`
            endpoint name
        """
        if endpoint not in self.endpoints:
            logging.error('Invalid endpoint for disconnect %s' % endpoint)
            return

        conn = self.endpoints[endpoint]

        del self.endpoints[endpoint]

        conn.on_close()
        self.send_message(proto.disconnect(endpoint))