Пример #1
0
 def test_ipv6_interface_address(self):
     config = recv.UdpIbvConfig(endpoints=[('239.255.88.88', 8888)],
                                interface_address='::1')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(ValueError, match='interface address'):
         stream.add_udp_ibv_reader(config)
Пример #2
0
 def test_ipv6_endpoints(self):
     config = recv.UdpIbvConfig(endpoints=[('::1', 8888)],
                                interface_address='10.0.0.1')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(ValueError,
                        match='endpoint is not an IPv4 address'):
         stream.add_udp_ibv_reader(config)
Пример #3
0
 def test_bad_interface_address(self):
     config = recv.UdpIbvConfig(
         endpoints=[('239.255.88.88', 8888)],
         interface_address='this is not an interface address')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(RuntimeError, match='Host not found'):
         stream.add_udp_ibv_reader(config)
Пример #4
0
 def test_set_get(self):
     config = recv.RingStreamConfig()
     config.heaps = 5
     config.contiguous_only = False
     config.incomplete_keep_payload_ranges = True
     assert config.heaps == 5
     assert config.contiguous_only is False
     assert config.incomplete_keep_payload_ranges is True
Пример #5
0
    def data_to_heaps(self, data, **kwargs):
        """Take some data and pass it through the receiver to obtain a set of heaps.

        Keyword arguments are passed to the receiver constructor.
        """
        thread_pool = spead2.ThreadPool()
        config = recv.StreamConfig(bug_compat=self.flavour.bug_compat)
        ring_config = recv.RingStreamConfig()
        for key in [
                'stop_on_stop_item', 'allow_unsized_heaps',
                'allow_out_of_order'
        ]:
            if key in kwargs:
                setattr(config, key, kwargs.pop(key))
        for key in ['contiguous_only', 'incomplete_keep_payload_ranges']:
            if key in kwargs:
                setattr(ring_config, key, kwargs.pop(key))
        if kwargs:
            raise ValueError(f'Unexpected keyword arguments ({kwargs})')
        stream = recv.Stream(thread_pool, config, ring_config)
        stream.add_buffer_reader(data)
        return list(stream)
Пример #6
0
    def test_full_stop(self):
        """Must be able to stop even if the consumer is not consuming
        anything."""
        thread_pool = spead2.ThreadPool(1)
        sender = send.BytesStream(thread_pool)
        ig = send.ItemGroup()
        data = np.array([[6, 7, 8], [10, 11, 12000]], dtype=np.uint16)
        ig.add_item(id=0x2345,
                    name='name',
                    description='description',
                    shape=data.shape,
                    dtype=data.dtype,
                    value=data)
        gen = send.HeapGenerator(ig)
        for i in range(10):
            sender.send_heap(gen.get_heap(data='all'))
        recv_ring_config = recv.RingStreamConfig(heaps=4)
        receiver = recv.Stream(thread_pool, ring_config=recv_ring_config)
        receiver.add_buffer_reader(sender.getvalue())
        # Wait for the ring buffer to block
        while receiver.stats.worker_blocked == 0:
            time.sleep(0.0)
        # Can't usefully check the stats here, because they're only
        # updated at the end of a batch.
        assert receiver.ringbuffer.capacity() == 4
        assert receiver.ringbuffer.size() == 4

        receiver.stop()  # This unblocks all remaining heaps
        stats = receiver.stats
        assert stats.heaps == 10
        assert stats.packets == 10
        assert stats.incomplete_heaps_evicted == 0
        assert stats.incomplete_heaps_flushed == 0
        assert stats.worker_blocked == 1
        assert receiver.ringbuffer.capacity() == 4
        assert receiver.ringbuffer.size() == 4
Пример #7
0
 def test_no_endpoints(self):
     config = recv.UdpIbvConfig(interface_address='10.0.0.1')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(ValueError, match='endpoints is empty'):
         stream.add_udp_ibv_reader(config)
Пример #8
0
 def test_heaps_zero(self):
     """Constructing a config with heaps=0 raises ValueError"""
     with pytest.raises(ValueError):
         recv.RingStreamConfig(heaps=0)
Пример #9
0
 def test_default_construct(self):
     config = recv.RingStreamConfig()
     assert config.heaps == recv.RingStreamConfig.DEFAULT_HEAPS
     assert config.contiguous_only is True
     assert config.incomplete_keep_payload_ranges is False