about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-02 20:37:38 +0000
committerEric Wong <e@80x24.org>2019-01-02 20:37:38 +0000
commit44baf906e73c13577186e3135be4356b33b8be43 (patch)
treeea17d5da3893b176c637927388659b526c44bb8e /test
parent8f8140f68ff2daab5feeb134d1f4e77f4329fa0f (diff)
downloaddtas-44baf906e73c13577186e3135be4356b33b8be43.tar.gz
Eliminate loading of the io_splice RubyGem to reduce memory overhead.
Extra DSOs are wasteful and io_splice is being phased oiut for
sleepy_penguin, which encapsulates more Linux-specific functionality
anyways.

cf. https://udrepper.livejournal.com/8790.html
Diffstat (limited to 'test')
-rw-r--r--test/test_buffer.rb22
-rw-r--r--test/test_sink_pipe_size.rb4
2 files changed, 15 insertions, 11 deletions
diff --git a/test/test_buffer.rb b/test/test_buffer.rb
index 0fb4fba..b21a69f 100644
--- a/test/test_buffer.rb
+++ b/test/test_buffer.rb
@@ -49,14 +49,14 @@ class TestBuffer < Testcase
     buf = new_buffer
     buf.buffer_size = @@max_size
     assert_equal @@max_size, buf.buffer_size
-  end if @@max_size
+  end if defined?(SleepyPenguin::F_GETPIPE_SZ)
 
   def test_buffer_size
     buf = new_buffer
     assert_operator buf.buffer_size, :>, 128
     buf.buffer_size = @@max_size
     assert_equal @@max_size, buf.buffer_size
-  end if @@max_size
+  end if defined?(SleepyPenguin::F_GETPIPE_SZ)
 
   def test_broadcast_1
     buf = new_buffer
@@ -87,9 +87,9 @@ class TestBuffer < Testcase
     assert_empty blocked
     assert_equal "HELLO", a[0].read(5)
     assert_equal "HELLO", b[0].read(5)
-    max = '*' * a[0].pipe_size
+    max = '*' * pipe_size(a[0])
     assert_equal max.size, a[1].write(max)
-    assert_equal a[0].nread, a[0].pipe_size
+    assert_equal a[0].nread, pipe_size(a[0])
     a[1].nonblock = true
     assert_equal 5, buf.__broadcast_tee(blocked, [a[1], b[1]], 5)
     assert_equal [a[1]], blocked
@@ -108,10 +108,10 @@ class TestBuffer < Testcase
     assert_equal "HELLO", a[0].read(5)
     assert_equal "HELLO", b[0].read(5)
 
-    return unless b[1].respond_to?(:pipe_size)
+    return unless defined?(SleepyPenguin::F_GETPIPE_SZ)
 
     b[1].nonblock = true
-    b[1].write('*' * b[1].pipe_size)
+    b[1].write('*' * pipe_size(b[1]))
     buf.wr.write "BYE"
     assert_equal :wait_readable, buf.broadcast([a[1], b[1]])
     assert_equal 8, buf.bytes_xfer
@@ -157,8 +157,8 @@ class TestBuffer < Testcase
     a = pipe
     b = pipe
     buf = new_buffer
-    a[1].write('*' * a[1].pipe_size)
-    b[1].write('*' * b[1].pipe_size)
+    a[1].write('*' * pipe_size(a[1]))
+    b[1].write('*' * pipe_size(b[1]))
 
     a[1].nonblock = true
     b[1].nonblock = true
@@ -167,7 +167,7 @@ class TestBuffer < Testcase
     buf.wr.write "HELLO"
     assert_equal tmp, buf.broadcast(tmp)
     assert_equal [a[1], b[1]], tmp
-  end if IO.method_defined?(:pipe_size)
+  end if defined?(SleepyPenguin::F_GETPIPE_SZ)
 
   def test_serialize
     buf = new_buffer
@@ -204,4 +204,8 @@ class TestBuffer < Testcase
     assert_equal 4096, buf.buffer_size
     buf.close!
   end
+
+  def pipe_size(io)
+    io.fcntl(SleepyPenguin::F_GETPIPE_SZ)
+  end
 end
diff --git a/test/test_sink_pipe_size.rb b/test/test_sink_pipe_size.rb
index 645084a..1ca3108 100644
--- a/test/test_sink_pipe_size.rb
+++ b/test/test_sink_pipe_size.rb
@@ -2,7 +2,7 @@
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 begin
-  require 'io/splice'
+  require 'sleepy_penguin'
   require './test/player_integration'
   class TestSinkPipeSizeIntegration < Testcase
     include PlayerIntegration
@@ -14,7 +14,7 @@ begin
       s.req_ok("sink ed default pipe_size=0x10000")
       s.req_ok("sink ed default pipe_size=")
       s.req_ok("sink ed default pipe_size=4096")
-    end if IO.method_defined?(:pipe_size=)
+    end if SleepyPenguin.const_defined?(:F_SETPIPE_SZ)
   end
 rescue LoadError
 end