Ejemplo n.º 1
0
    def test_priority(self):
        self.conn.update_settings({
            SettingCodes.MAX_FRAME_SIZE:
            16384,
            SettingCodes.INITIAL_WINDOW_SIZE:
            16384 * 1024 * 32,
        })
        event = yield from self._expect_events()
        self.assertIsInstance(event[0], SettingsAcknowledged)
        event = yield from self.server.events.get()
        self.assertIsInstance(event, RemoteSettingsChanged)

        stream_1 = yield from self._send_headers()
        yield from self.server.start_response(stream_1, [(':status', '200')])
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], ResponseReceived)

        stream_2 = yield from self._send_headers()
        yield from self.server.start_response(stream_2, [(':status', '200')])
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], ResponseReceived)

        p1 = 32
        p2 = 20

        self.server.reprioritize(stream_1, weight=p1)
        self.server.reprioritize(stream_2, weight=p2)
        self.server.pause_writing()

        running = [True]

        @asyncio.coroutine
        def _write(stream_id):
            count = 0
            while running[0]:
                yield from self.server.send_data(stream_id, b'x')
                count += 1
            yield from self.server.end_stream(stream_id)
            return count

        task_1 = async_task(_write(stream_1))
        task_2 = async_task(_write(stream_2))

        for i in range(1000):
            self.server.resume_writing()
            yield from asyncio.sleep(0.004)
            self.server.pause_writing()
            yield from asyncio.sleep(0.001)

        running[0] = False
        self.server.resume_writing()

        count_1 = yield from task_1
        count_2 = yield from task_2

        self.assertAlmostEqual(count_1 / count_2, p1 / p2, 1)
Ejemplo n.º 2
0
    def test_priority(self):
        self.conn.update_settings({
            MAX_FRAME_SIZE: 16384,
            INITIAL_WINDOW_SIZE: 16384 * 1024 * 32,
        })
        event = yield from self._expect_events()
        self.assertIsInstance(event[0], SettingsAcknowledged)
        event = yield from self.server.events.get()
        self.assertIsInstance(event, RemoteSettingsChanged)

        stream_1 = yield from self._send_headers()
        yield from self.server.start_response(stream_1, {'a': '1'})
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], ResponseReceived)

        stream_2 = yield from self._send_headers()
        yield from self.server.start_response(stream_2, {'a': '2'})
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], ResponseReceived)

        p1 = 32
        p2 = 20

        self.server.reprioritize(stream_1, weight=p1)
        self.server.reprioritize(stream_2, weight=p2)
        self.server.pause_writing()

        running = [True]

        @asyncio.coroutine
        def _write(stream_id):
            count = 0
            while running[0]:
                yield from self.server.send_data(stream_id, b'x')
                count += 1
            yield from self.server.end_stream(stream_id)
            return count

        task_1 = async_task(_write(stream_1))
        task_2 = async_task(_write(stream_2))

        for i in range(1000):
            self.server.resume_writing()
            yield from asyncio.sleep(0.004)
            self.server.pause_writing()
            yield from asyncio.sleep(0.001)

        running[0] = False
        self.server.resume_writing()

        count_1 = yield from task_1
        count_2 = yield from task_2

        self.assertAlmostEqual(count_1 / count_2, p1 / p2, 1)
Ejemplo n.º 3
0
    def test_broken_send(self):
        self.conn.update_settings({SettingCodes.INITIAL_WINDOW_SIZE: 3})
        event = yield from self._expect_events()
        self.assertIsInstance(event[0], SettingsAcknowledged)
        event = yield from self.server.events.get()
        self.assertIsInstance(event, RemoteSettingsChanged)

        stream_id = yield from self._send_headers(end_stream=True)
        yield from self.server.start_response(stream_id, [(':status', '200')])
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], ResponseReceived)

        yield from self.server.send_data(stream_id, b'12')
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], DataReceived)
        self.assertEqual(events[0].data, b'12')

        f = async_task(self.server.send_data(stream_id, b'345678'))
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], DataReceived)
        self.assertEqual(events[0].data, b'3')

        self.conn.reset_stream(stream_id)
        yield from self._expect_events(0)

        try:
            yield from f
        except SendException as e:
            self.assertEqual(e.data, b'45678')
        else:
            self.assertRaises(SendException, lambda: None)
Ejemplo n.º 4
0
    def test_broken_send(self):
        self.conn.update_settings({INITIAL_WINDOW_SIZE: 3})
        event = yield from self._expect_events()
        self.assertIsInstance(event[0], SettingsAcknowledged)
        event = yield from self.server.events.get()
        self.assertIsInstance(event, RemoteSettingsChanged)

        stream_id = yield from self._send_headers(end_stream=True)
        yield from self.server.start_response(stream_id, {'a': '1'})
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], ResponseReceived)

        yield from self.server.send_data(stream_id, b'12')
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], DataReceived)
        self.assertEqual(events[0].data, b'12')

        f = async_task(self.server.send_data(stream_id, b'345678'))
        events = yield from self._expect_events()
        self.assertIsInstance(events[0], DataReceived)
        self.assertEqual(events[0].data, b'3')

        self.conn.reset_stream(stream_id)
        yield from self._expect_events(0)

        try:
            yield from f
        except SendException as e:
            self.assertEqual(e.data, b'45678')
        else:
            self.assertRaises(SendException, lambda: None)