diff options
author | Eric Wong <e@80x24.org> | 2017-01-27 02:53:41 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-01-27 03:41:52 +0000 |
commit | 42402dbe14f54220ffd208e935b33c997feacd24 (patch) | |
tree | 20846bb60d20051c3f64a7a131b9cfd8524a75b8 /test/test_cmogstored.rb | |
parent | dd53d097384154b9d2d100a9079f4dbf681a0925 (diff) | |
download | mogilefs-client-42402dbe14f54220ffd208e935b33c997feacd24.tar.gz |
This is a workaround for <https://bugs.ruby-lang.org/issues/13085> since we use non-blocking sockets anyways.
Diffstat (limited to 'test/test_cmogstored.rb')
-rw-r--r-- | test/test_cmogstored.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/test_cmogstored.rb b/test/test_cmogstored.rb index 586000b..0dd920a 100644 --- a/test/test_cmogstored.rb +++ b/test/test_cmogstored.rb @@ -27,6 +27,25 @@ class Test_cmogstored < Test::Unit::TestCase assert_equal "a\nb\nc\nd\ne\n", client.get_file_data("puts") end + def test_garbage + add_host_device_domain + client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain, + :timeout => 60 + nr = 1024 * 1024 * 1024 + client.new_file('giant', :largefile => :stream, + :content_length => nr) do |io| + assert_instance_of MogileFS::NewFile::Stream, io + zero = Zero.new + before = GC.count + wr = IO.copy_stream(zero, io, nr) + after = GC.count + assert_equal nr, wr + assert_in_delta before, after, 1 + end + end if IO.respond_to?(:copy_stream) && defined?(Zero) && + GC.respond_to?(:count) && defined?(RUBY_ENGINE) && + RUBY_ENGINE == 'ruby' && ENV['TEST_EXPENSIVE'].to_i != 0 + def test_stream_new_file add_host_device_domain client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain @@ -146,3 +165,17 @@ class Test_cmogstored < Test::Unit::TestCase end end end if `which cmogstored`.chomp.size > 0 + +# The goal of this is to use a synthetic (non-IO) reader +# to trigger the read/write loop of IO.copy_stream, +# bypassing in-kernel mechanisms like sendfile for zero copy, +# so we wrap the /dev/zero IO object: +class Zero + def initialize + @in = File.open('/dev/zero', 'rb') + end + + def read(len, buf) + @in.read(len, buf) + end +end if File.readable?('/dev/zero') |