Ejemplo n.º 1
0
    def test_duplicate(self):
        stream = InboundStream()

        # feed first chunk
        stream.add_chunk(self.fragmented[0])
        self.assertEqual(stream.reassembly, [self.fragmented[0]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [])

        # feed first chunk again
        stream.add_chunk(self.fragmented[0])
        self.assertEqual(stream.reassembly, [self.fragmented[0]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [])
Ejemplo n.º 2
0
    def test_duplicate(self):
        stream = InboundStream()

        # feed first chunk
        stream.add_chunk(self.fragmented[0])
        self.assertEqual(stream.reassembly, [self.fragmented[0]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [])

        # feed first chunk again
        with self.assertRaises(AssertionError) as cm:
            stream.add_chunk(self.fragmented[0])
        self.assertEqual(str(cm.exception), '')
Ejemplo n.º 3
0
    def test_whole_in_order(self):
        stream = InboundStream()

        # feed first unfragmented
        stream.add_chunk(self.whole[0])
        self.assertEqual(stream.reassembly, [self.whole[0]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [
            (456, 123, b'foo'),
        ])
        self.assertEqual(stream.reassembly, [])
        self.assertEqual(stream.sequence_number, 1)

        # feed second unfragmented
        stream.add_chunk(self.whole[1])
        self.assertEqual(stream.reassembly, [self.whole[1]])
        self.assertEqual(stream.sequence_number, 1)

        self.assertEqual(list(stream.pop_messages()), [
            (456, 123, b'bar'),
        ])
        self.assertEqual(stream.reassembly, [])
        self.assertEqual(stream.sequence_number, 2)
Ejemplo n.º 4
0
    def test_fragments_out_of_order(self):
        stream = InboundStream()

        # feed third chunk
        stream.add_chunk(self.fragmented[2])
        self.assertEqual(stream.reassembly, [self.fragmented[2]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [])

        # feed first chunk
        stream.add_chunk(self.fragmented[0])
        self.assertEqual(stream.reassembly,
                         [self.fragmented[0], self.fragmented[2]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [])

        # feed second chunk
        stream.add_chunk(self.fragmented[1])
        self.assertEqual(
            stream.reassembly,
            [self.fragmented[0], self.fragmented[1], self.fragmented[2]])
        self.assertEqual(stream.sequence_number, 0)

        self.assertEqual(list(stream.pop_messages()), [
            (456, 123, b'foobarbaz'),
        ])
        self.assertEqual(stream.reassembly, [])
        self.assertEqual(stream.sequence_number, 1)