Skip to content

Commit

Permalink
Clean up this spec and handle some edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Apr 12, 2018
1 parent fda229c commit 79e9b26
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions spec/regression/JRUBY-5238_thread_state.rb
Expand Up @@ -14,6 +14,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking gets(rs)" do
Expand All @@ -22,6 +23,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking eof?" do
Expand All @@ -30,6 +32,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking getc" do
Expand All @@ -38,6 +41,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking readlines" do
Expand All @@ -46,6 +50,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking read" do
Expand All @@ -54,6 +59,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking read(n)" do
Expand All @@ -62,6 +68,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking readpartial" do
Expand All @@ -70,6 +77,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

it "should be 'sleep' while blocking sysread" do
Expand All @@ -78,6 +86,7 @@
}
wait_block(thread)
expect(thread.status).to eq('sleep')
thread.kill rescue nil
end

# See JRUBY-5122 spec for the reason of this value
Expand All @@ -94,9 +103,11 @@
if blocked
expect(thread.status).to eq('sleep')
else
# it's OK since write is not blocked. we cannot test this behavior for such case.
expect(thread.status).to eq(false)
# It's OK since write is not blocked. we cannot test this behavior for such case.
# Thread may be dying and report status dead.
expect([false, "dead"]).to include(thread.status)
end
thread.kill rescue nil
end

it "should be 'sleep' while blocking syswrite" do
Expand All @@ -110,14 +121,16 @@
if blocked
expect(thread.status).to eq('sleep')
else
# it's OK since write is not blocked. we cannot test this behavior for such case.
expect(thread.status).to eq(false)
# It's OK since write is not blocked. we cannot test this behavior for such case.
# Thread may be dying and report status dead.
expect([false, "dead"]).to include(thread.status)
end
thread.kill rescue nil
end

def wait_block(thread)
begin
timeout(2) do
Timeout.timeout(2) do
sleep 0.1 while (thread.status != false && thread.status != 'sleep')
end
rescue Timeout::Error
Expand Down

0 comments on commit 79e9b26

Please sign in to comment.