Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1e8c12fddbf8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5504629cce5a
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 17, 2014

  1. Copy the full SHA
    84e4130 View commit details
  2. Copy the full SHA
    5504629 View commit details
Showing with 63 additions and 30 deletions.
  1. +61 −28 spec/regression/JRUBY-5122_nonblocking_io_spec.rb
  2. +2 −2 test/mri/ruby/test_readpartial.rb
89 changes: 61 additions & 28 deletions spec/regression/JRUBY-5122_nonblocking_io_spec.rb
Original file line number Diff line number Diff line change
@@ -196,45 +196,78 @@
value.should == "baz"
end

# WRITE BLOCKAGE:
#
# We try to pick a suitably large value such that potentially-blocking
# writes are more likely to reach buffer limits and actually block.
#
# On an Ubuntu 10.10(64) box:
# Packaged OpenJDK6 block with > 152606 (?)
# Oracle's build block with > 131072 (2**17)
# On a Windows 7(64) box:
# Oracle's build does not block (use memory till OOMException)
SOCKET_CHANNEL_MIGHT_BLOCK = "a" * (219463 * 4)

# This spec does not appear to test anything meaningful and occasionally
# failed due to several inherent races. I improved the race situation
# somewhat, but it's unclear whether this spec can ever fail since it
# appears to accept both blocking and nonblocking write.
#
# I believe the spec originally expected small writes not to block, which
# is reasonable, but at some point it mutated into a test that write
# *does* block under certain circumstances, making the original assertions
# meaningless.
#
# See jruby/jruby#2332

=begin
it "should not block for write" do
100.times do # for acceleration; it failed w/o wait_for_accepted call
server = TCPServer.new(0)
value = nil
t = Thread.new {
sock = accept(server)
begin
value = 1
# this could block; [ruby-dev:26405] But it doesn't block on Windows.
sock.write(SOCKET_CHANNEL_MIGHT_BLOCK)
value = 2
rescue RuntimeError
value = 3
end
}
s = connect(server)
type = nil
wait_for_sleep_and_terminate(t) do
if value == 1
type = :blocked
t.raise # help thread termination
else
value.should == 2
t.status.should == false
100.times do # for acceleration; it failed w/o wait_for_accepted call
server = TCPServer.new(0)
value = nil
t = Thread.new {
sock = accept(server)
begin
value = 1
# this could block; [ruby-dev:26405] But it doesn't block on Windows.
sock.write(SOCKET_CHANNEL_MIGHT_BLOCK)
value = 2
rescue RuntimeError
value = 3
end
}
s = connect(server)
# Whether write blocks or not, read will block until data is available
IO.select([s], nil, nil, 2)
# If write did not block, give thread some time to advance
100.times { Thread.pass }
# Now check where we are
wait_for_sleep_and_terminate(t) do
if value == 1
# Write blocked [ruby-dev:26405], see WRITE BLOCKAGE above
type = :blocked
t.raise # help thread termination
t.join
if RbConfig::CONFIG['host_os'] !~ /mingw|mswin/
value.should == 3
t.status.should == false
end
else
# Write did not block
value.should == 2
t.status.should == false
end
end
end
if type == :blocked && RbConfig::CONFIG['host_os'] !~ /mingw|mswin/
value.should == 3
t.status.should == false
end
end
end
=end

it "should not block for write_nonblock" do
server = TCPServer.new(0)
4 changes: 2 additions & 2 deletions test/mri/ruby/test_readpartial.rb
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ def make_pipe
begin
yield r, w
ensure
r.close unless r.closed?
w.close unless w.closed?
r.close rescue nil unless r.closed?
w.close rescue nil unless w.closed?
end
end