Esempio n. 1
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'))
        receiver = spead2.recv.Stream(thread_pool, ring_heaps=4)
        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_equal(4, receiver.ringbuffer.capacity())
        assert_equal(4, receiver.ringbuffer.size())

        receiver.stop()  # This unblocks all remaining heaps
        stats = receiver.stats
        assert_equal(10, stats.heaps)
        assert_equal(10, stats.packets)
        assert_equal(0, stats.incomplete_heaps_evicted)
        assert_equal(0, stats.incomplete_heaps_flushed)
        assert_equal(1, stats.worker_blocked)
        assert_equal(4, receiver.ringbuffer.capacity())
        assert_equal(4, receiver.ringbuffer.size())
Esempio n. 2
0
    def test_no_stop_heap(self):
        """A heap containing a stop is not passed to the ring"""
        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)
        sender.send_heap(gen.get_heap(data='all'))
        sender.send_heap(gen.get_end())
        receiver = spead2.recv.Stream(thread_pool)
        receiver.add_buffer_reader(sender.getvalue())
        heaps = list(receiver)
        assert_equal(1, len(heaps))

        stats = receiver.stats
        assert_equal(1, stats.heaps)
        assert_equal(2, stats.packets)
        assert_equal(0, stats.incomplete_heaps_evicted)
        assert_equal(0, stats.incomplete_heaps_flushed)
        assert_equal(0, stats.worker_blocked)
Esempio n. 3
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'))
     receiver = spead2.recv.Stream(thread_pool)
     receiver.add_buffer_reader(sender.getvalue())
     receiver.stop()