From 29edcd1c0b578c20bebd02e4fd47961dc4970a72 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Wed, 9 Oct 2024 06:24:48 +0900 Subject: [PATCH] GH-44337: [CI][GLib] Fix a flaky StreamDecoder and Buffer test It's related to GC. StreamDecoder accepts incomplete data. They are kept until enough data are provided. A caller must not release the incomplete data before they are processed. If they are released, StreamDecoder may touch unexpected data. --- c_glib/test/test-stream-decoder.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/c_glib/test/test-stream-decoder.rb b/c_glib/test/test-stream-decoder.rb index 108e687e3aa6b..ef669a61f0eaf 100644 --- a/c_glib/test/test-stream-decoder.rb +++ b/c_glib/test/test-stream-decoder.rb @@ -79,8 +79,15 @@ def test_consume_bytes end def test_consume_buffer + # We need to keep data that aren't processed yet. + data = [] @buffer.data.to_s.each_byte do |byte| - @decoder.consume_buffer(Arrow::Buffer.new(byte.chr)) + data << byte.chr + can_clear = (@decoder.next_required_size == 1) + @decoder.consume_buffer(Arrow::Buffer.new(data.last)) + # We can release a reference for kept data after they are + # processed. + data.clear if can_clear end assert_equal([ [:schema_decoded, @schema, @schema],