This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 38c12865ae GH-44337: [CI][GLib] Fix a flaky StreamDecoder and Buffer 
test (#44341)
38c12865ae is described below

commit 38c12865ae17b4b4f1c9d5f0789acbf3ca38a243
Author: Sutou Kouhei <[email protected]>
AuthorDate: Wed Oct 9 09:25:44 2024 +0900

    GH-44337: [CI][GLib] Fix a flaky StreamDecoder and Buffer test (#44341)
    
    ### Rationale for this change
    
    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.
    
    ### What changes are included in this PR?
    
    Refer unprocessed data until they are processed.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    No.
    * GitHub Issue: #44337
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 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 108e687e3a..ef669a61f0 100644
--- a/c_glib/test/test-stream-decoder.rb
+++ b/c_glib/test/test-stream-decoder.rb
@@ -79,8 +79,15 @@ class TestStreamDecoder < Test::Unit::TestCase
   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],

Reply via email to