示例#1
0
    def test_str(self):
        session = self.make_session('test')
        session.state = protocol.STATE_OPEN

        self.assertEqual(str(session), "id='test' connected")

        session._hits = 10
        session._heartbeats = 50
        session.state = protocol.STATE_CLOSING
        self.assertEqual(str(session),
                         "id='test' disconnected hits=10 heartbeats=50")

        session._feed(protocol.FRAME_MESSAGE, 'msg')
        self.assertEqual(
            str(session),
            "id='test' disconnected queue[1] hits=10 heartbeats=50")

        session.state = protocol.STATE_CLOSED
        self.assertEqual(
            str(session),
            "id='test' closed queue[1] hits=10 heartbeats=50")

        session.state = protocol.STATE_OPEN
        session.acquired = True
        self.assertEqual(
            str(session),
            "id='test' connected acquired queue[1] hits=10 heartbeats=50")
示例#2
0
    def test_feed_with_waiter(self):
        session = self.make_session('test')
        session._waiter = waiter = asyncio.Future(loop=self.loop)
        session._feed(protocol.FRAME_MESSAGE, 'msg')

        self.assertEqual(
            list(session._queue),
            [(protocol.FRAME_MESSAGE, ['msg'])])
        self.assertIsNone(session._waiter)
        self.assertTrue(waiter.done())
示例#3
0
    def test_feed_msg_packing(self):
        session = self.make_session('test')
        session._feed(protocol.FRAME_MESSAGE, 'msg1')
        session._feed(protocol.FRAME_MESSAGE, 'msg2')
        session._feed(protocol.FRAME_CLOSE, (3001, 'reason'))
        session._feed(protocol.FRAME_MESSAGE, 'msg3')

        self.assertEqual(
            list(session._queue),
            [(protocol.FRAME_MESSAGE, ['msg1', 'msg2']),
             (protocol.FRAME_CLOSE, (3001, 'reason')),
             (protocol.FRAME_MESSAGE, ['msg3'])])
示例#4
0
    def test_feed(self):
        session = self.make_session('test')
        session._feed(protocol.FRAME_OPEN, protocol.FRAME_OPEN)
        session._feed(protocol.FRAME_MESSAGE, 'msg')
        session._feed(protocol.FRAME_CLOSE, (3001, 'reason'))

        self.assertEqual(
            list(session._queue),
            [(protocol.FRAME_OPEN, protocol.FRAME_OPEN),
             (protocol.FRAME_MESSAGE, ['msg']),
             (protocol.FRAME_CLOSE, (3001, 'reason'))])