示例#1
0
    async def get(self):
        ws = WebSocketResponse()
        await ws.prepare(self.request)

        with self.resource:
            while not ws.closed:
                try:
                    item = await asyncio.wait_for(self.resource.queue.get(), 2)
                except asyncio.TimeoutError:
                    ws.ping()
                    continue
                except asyncio.CancelledError:
                    break

                if item['action'] == 'cleared':
                    data = {'action': 'cleared'}
                elif item['action'] == 'received':
                    data = {
                        'action': 'received',
                        'msg': serialize_message(item['msg']),
                    }
                else:
                    data = None

                if data:
                    ws.send_str(json.dumps(data))

        return ws
示例#2
0
 def test_ping_closed(self):
     req = self.make_request('GET', '/')
     ws = WebSocketResponse()
     ws.start(req)
     self.loop.run_until_complete(ws.close())
     with self.assertRaises(RuntimeError):
         ws.ping()
示例#3
0
def test_ping_closed(make_request):
    req = make_request('GET', '/')
    ws = WebSocketResponse()
    yield from ws.prepare(req)
    yield from ws.close()
    with pytest.raises(RuntimeError):
        ws.ping()
示例#4
0
def test_ping_closed(make_request):
    req = make_request('GET', '/')
    ws = WebSocketResponse()
    yield from ws.prepare(req)
    yield from ws.close()
    with pytest.raises(RuntimeError):
        ws.ping()
示例#5
0
 def test_ping_closed(self):
     req = self.make_request("GET", "/")
     ws = WebSocketResponse()
     self.loop.run_until_complete(ws.prepare(req))
     self.loop.run_until_complete(ws.close())
     with self.assertRaises(RuntimeError):
         ws.ping()
 def test_ping_closing(self):
     req = self.make_request('GET', '/')
     ws = WebSocketResponse()
     ws.start(req)
     ws.close()
     with self.assertRaises(RuntimeError):
         ws.ping()
示例#7
0
def test_ping_closed(make_request, mocker):
    req = make_request('GET', '/')
    ws = WebSocketResponse()
    yield from ws.prepare(req)
    yield from ws.close()

    mocker.spy(ws_logger, 'warning')
    ws.ping()
    assert ws_logger.warning.called
示例#8
0
def function835(function271, arg1247):
    var816 = function271('GET', '/')
    var1269 = WebSocketResponse()
    yield from var1269.prepare(var816)
    var1269._reader.feed_data(WS_CLOSED_MESSAGE, 0)
    yield from var1269.close()
    arg1247.spy(ws_logger, 'warning')
    var1269.ping()
    assert ws_logger.warning.called
示例#9
0
async def test_ping_closed(make_request, mocker):
    req = make_request('GET', '/')
    ws = WebSocketResponse()
    await ws.prepare(req)
    ws._reader.feed_data(WS_CLOSED_MESSAGE, 0)
    await ws.close()

    mocker.spy(ws_logger, 'warning')
    ws.ping()
    assert ws_logger.warning.called
示例#10
0
def test_ping_closed(make_request, mocker):
    req = make_request('GET', '/')
    ws = WebSocketResponse()
    yield from ws.prepare(req)
    ws._reader.feed_data(WS_CLOSED_MESSAGE, 0)
    yield from ws.close()

    mocker.spy(ws_logger, 'warning')
    ws.ping()
    assert ws_logger.warning.called
示例#11
0
def test_nonstarted_ping():
    ws = WebSocketResponse()
    with pytest.raises(RuntimeError):
        ws.ping()
示例#12
0
 def test_nonstarted_ping(self):
     ws = WebSocketResponse()
     with self.assertRaises(RuntimeError):
         ws.ping()
示例#13
0
def test_nonstarted_ping():
    ws = WebSocketResponse()
    with pytest.raises(RuntimeError):
        ws.ping()
示例#14
0
def function2584():
    var1663 = WebSocketResponse()
    with pytest.raises(RuntimeError):
        var1663.ping()