'Data in responses is interleaved according to HTTP/2 priorities.'

def test_sendAccordingToPriority(self):

    f = FrameFactory()
    b = StringTransport()
    a = H2Connection()
    a.requestFactory = ChunkedHTTPHandlerProxy
    getRequestHeaders = self.getRequestHeaders
    getRequestHeaders[2] = (':path', '/chunked/4')
    frames = [buildRequestFrames(getRequestHeaders, [], f, streamID) for streamID in [1, 3, 5]]
    frames[0][0].flags.add('PRIORITY')
    frames[0][0].stream_weight = 64
    frames[1][0].flags.add('PRIORITY')
    frames[1][0].stream_weight = 32
    priorityFrame = f.buildPriorityFrame(streamID=5, weight=16, dependsOn=1, exclusive=True)
    frames[2].insert(0, priorityFrame)
    frames = itertools.chain.from_iterable(frames)
    requestBytes = f.clientConnectionPreface()
    requestBytes += ''.join((frame.serialize() for frame in frames))
    a.makeConnection(b)
    for byte in iterbytes(requestBytes):
        a.dataReceived(byte)
    def validate(results):
        frames = framesFromBytes(b.value())
        self.assertEqual(len(frames), 19)
        streamIDs = [f.stream_id for f in frames if isinstance(f, hyperframe.frame.DataFrame)]
        expectedOrder = [1, 3, 1, 1, 3, 1, 1, 3, 5, 3, 5, 3, 5, 5, 5]
        self.assertEqual(streamIDs, expectedOrder)
    return defer.DeferredList(list(a._streamCleanupCallbacks.values())).addCallback(validate)
