Esempio n. 1
0
 def socket_creator():
     ws_app, wait_for_sock = make_virtual_socket(
         '127.0.0.1', web_config_port)
     gr = eventlet.spawn(ws_app.run_forever)
     active_sockets.append((gr, ws_app))
     socket = wait_for_sock()
     socket.app = ws_app
     return socket
Esempio n. 2
0
 def socket_creator():
     ws_app, wait_for_sock = make_virtual_socket(
         '127.0.0.1', web_config_port)
     gr = eventlet.spawn(ws_app.run_forever)
     active_sockets.append((gr, ws_app))
     socket = wait_for_sock()
     socket.app = ws_app
     return socket
Esempio n. 3
0
def test_client_closing_connection(container, web_config_port):
    ws_app, wait_for_sock = make_virtual_socket('127.0.0.1', web_config_port)

    gt = eventlet.spawn(ws_app.run_forever)
    wait_for_sock()

    wait_for_close = Event()

    def on_close(ws):
        wait_for_close.send(None)

    ws_app.on_close = on_close

    ws_app.send(b'\xff\x00')  # "Close the connection" packet.
    wait_for_close.wait()

    ws_app.close()
    gt.kill()

    assert container.stop() is None
Esempio n. 4
0
def test_client_closing_connection(container, web_config_port):
    ws_app, wait_for_sock = make_virtual_socket('127.0.0.1', web_config_port)

    gt = eventlet.spawn(ws_app.run_forever)
    wait_for_sock()

    wait_for_close = Event()

    def on_close(ws):
        wait_for_close.send(None)

    ws_app.on_close = on_close

    ws_app.send(b'\xff\x00')  # "Close the connection" packet.
    wait_for_close.wait()

    ws_app.close()
    gt.kill()

    assert container.stop() is None
Esempio n. 5
0
def test_badly_encoded_data(container, web_config_port):
    ws_app, wait_for_sock = make_virtual_socket('127.0.0.1', web_config_port)

    gt = eventlet.spawn(ws_app.run_forever)
    wait_for_sock()
    result = Event()

    def on_message(ws, message):
        response = json.loads(message)
        assert not response['success']
        exc = deserialize(response['error'])
        result.send_exception(exc)
    ws_app.on_message = on_message
    ws_app.send('foo: bar')

    with pytest.raises(MalformedRequest) as exc:
        result.wait()
    assert 'Invalid JSON data' in str(exc)

    ws_app.close()
    gt.kill()
Esempio n. 6
0
def test_badly_encoded_data(container, web_config_port):
    ws_app, wait_for_sock = make_virtual_socket('127.0.0.1', web_config_port)

    gt = eventlet.spawn(ws_app.run_forever)
    wait_for_sock()
    result = Event()

    def on_message(ws, message):
        response = json.loads(message)
        assert not response['success']
        exc = deserialize(response['error'])
        result.send_exception(exc)
    ws_app.on_message = on_message
    ws_app.send('foo: bar')

    with pytest.raises(MalformedRequest) as exc:
        result.wait()
    assert 'Invalid JSON data' in str(exc)

    ws_app.close()
    gt.kill()