summaryrefslogtreecommitdiff
path: root/spec/ruby/core/thread/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/thread/shared')
-rw-r--r--spec/ruby/core/thread/shared/exit.rb47
-rw-r--r--spec/ruby/core/thread/shared/start.rb8
-rw-r--r--spec/ruby/core/thread/shared/to_s.rb24
-rw-r--r--spec/ruby/core/thread/shared/wakeup.rb5
4 files changed, 61 insertions, 23 deletions
diff --git a/spec/ruby/core/thread/shared/exit.rb b/spec/ruby/core/thread/shared/exit.rb
index 40dc478947..a294c3a4d6 100644
--- a/spec/ruby/core/thread/shared/exit.rb
+++ b/spec/ruby/core/thread/shared/exit.rb
@@ -56,8 +56,8 @@ describe :thread_exit, shared: true do
Thread.pass while @inner.status and @inner.status != "sleep"
@outer.send(@method)
@outer.join
- ScratchPad.recorded.should include(:inner_ensure_clause)
- ScratchPad.recorded.should include(:outer_ensure_clause)
+ ScratchPad.recorded.should.include?(:inner_ensure_clause)
+ ScratchPad.recorded.should.include?(:outer_ensure_clause)
end
it "does not set $!" do
@@ -66,6 +66,26 @@ describe :thread_exit, shared: true do
ScratchPad.recorded.should == nil
end
+ it "does not reset $!" do
+ ScratchPad.record []
+
+ exc = RuntimeError.new("foo")
+ thread = Thread.new do
+ begin
+ raise exc
+ ensure
+ ScratchPad << $!
+ begin
+ Thread.current.send(@method)
+ ensure
+ ScratchPad << $!
+ end
+ end
+ end
+ thread.join
+ ScratchPad.recorded.should == [exc, exc]
+ end
+
it "cannot be rescued" do
thread = Thread.new do
begin
@@ -73,7 +93,7 @@ describe :thread_exit, shared: true do
rescue Exception
ScratchPad.record :in_rescue
end
- ScratchPad.record :end_of_thread_block
+ ScratchPad.record :end_of_thread_block
end
thread.join
@@ -93,6 +113,25 @@ describe :thread_exit, shared: true do
ScratchPad.recorded.should == nil
end
+ it "kills other fibers of that thread without running their ensure clauses" do
+ t = Thread.new do
+ f = Fiber.new do
+ ScratchPad.record :fiber_resumed
+ begin
+ Fiber.yield
+ ensure
+ ScratchPad.record :fiber_ensure
+ end
+ end
+ f.resume
+ sleep
+ end
+ Thread.pass until t.stop?
+ t.send(@method)
+ t.join
+ ScratchPad.recorded.should == :fiber_resumed
+ end
+
# This spec is a mess. It fails randomly, it hangs on MRI, it needs to be removed
quarantine! do
it "killing dying running does nothing" do
@@ -116,7 +155,7 @@ describe :thread_exit, shared: true do
it "propagates inner exception to Thread.join if there is an outer ensure clause" do
thread = ThreadSpecs.dying_thread_with_outer_ensure(@method) { }
- -> { thread.join }.should raise_error(RuntimeError, "In dying thread")
+ -> { thread.join }.should.raise(RuntimeError, "In dying thread")
end
it "runs all outer ensure clauses even if inner ensure clause raises exception" do
diff --git a/spec/ruby/core/thread/shared/start.rb b/spec/ruby/core/thread/shared/start.rb
index 2ba926bf00..c5d62ab098 100644
--- a/spec/ruby/core/thread/shared/start.rb
+++ b/spec/ruby/core/thread/shared/start.rb
@@ -6,22 +6,22 @@ describe :thread_start, shared: true do
it "raises an ArgumentError if not passed a block" do
-> {
Thread.send(@method)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "spawns a new Thread running the block" do
run = false
t = Thread.send(@method) { run = true }
- t.should be_kind_of(Thread)
+ t.should.is_a?(Thread)
t.join
- run.should be_true
+ run.should == true
end
it "respects Thread subclasses" do
c = Class.new(Thread)
t = c.send(@method) { }
- t.should be_kind_of(c)
+ t.should.is_a?(c)
t.join
end
diff --git a/spec/ruby/core/thread/shared/to_s.rb b/spec/ruby/core/thread/shared/to_s.rb
index 45c04af627..27e53ba4b8 100644
--- a/spec/ruby/core/thread/shared/to_s.rb
+++ b/spec/ruby/core/thread/shared/to_s.rb
@@ -1,12 +1,10 @@
require_relative '../fixtures/classes'
describe :thread_to_s, shared: true do
- sep = ruby_version_is("2.7") ? " " : "@"
-
it "returns a description including file and line number" do
thread, line = Thread.new { "hello" }, __LINE__
thread.join
- thread.send(@method).should =~ /^#<Thread:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{line} \w+>$/
+ thread.send(@method).should =~ /^#<Thread:([^ ]*?) #{Regexp.escape __FILE__}:#{line} \w+>$/
end
it "has a binary encoding" do
@@ -14,42 +12,42 @@ describe :thread_to_s, shared: true do
end
it "can check it's own status" do
- ThreadSpecs.status_of_current_thread.send(@method).should include('run')
+ ThreadSpecs.status_of_current_thread.send(@method).should.include?('run')
end
it "describes a running thread" do
- ThreadSpecs.status_of_running_thread.send(@method).should include('run')
+ ThreadSpecs.status_of_running_thread.send(@method).should.include?('run')
end
it "describes a sleeping thread" do
- ThreadSpecs.status_of_sleeping_thread.send(@method).should include('sleep')
+ ThreadSpecs.status_of_sleeping_thread.send(@method).should.include?('sleep')
end
it "describes a blocked thread" do
- ThreadSpecs.status_of_blocked_thread.send(@method).should include('sleep')
+ ThreadSpecs.status_of_blocked_thread.send(@method).should.include?('sleep')
end
it "describes a completed thread" do
- ThreadSpecs.status_of_completed_thread.send(@method).should include('dead')
+ ThreadSpecs.status_of_completed_thread.send(@method).should.include?('dead')
end
it "describes a killed thread" do
- ThreadSpecs.status_of_killed_thread.send(@method).should include('dead')
+ ThreadSpecs.status_of_killed_thread.send(@method).should.include?('dead')
end
it "describes a thread with an uncaught exception" do
- ThreadSpecs.status_of_thread_with_uncaught_exception.send(@method).should include('dead')
+ ThreadSpecs.status_of_thread_with_uncaught_exception.send(@method).should.include?('dead')
end
it "describes a dying sleeping thread" do
- ThreadSpecs.status_of_dying_sleeping_thread.send(@method).should include('sleep')
+ ThreadSpecs.status_of_dying_sleeping_thread.send(@method).should.include?('sleep')
end
it "reports aborting on a killed thread" do
- ThreadSpecs.status_of_dying_running_thread.send(@method).should include('aborting')
+ ThreadSpecs.status_of_dying_running_thread.send(@method).should.include?('aborting')
end
it "reports aborting on a killed thread after sleep" do
- ThreadSpecs.status_of_dying_thread_after_sleep.send(@method).should include('aborting')
+ ThreadSpecs.status_of_dying_thread_after_sleep.send(@method).should.include?('aborting')
end
end
diff --git a/spec/ruby/core/thread/shared/wakeup.rb b/spec/ruby/core/thread/shared/wakeup.rb
index f111edf0fd..c89235ba60 100644
--- a/spec/ruby/core/thread/shared/wakeup.rb
+++ b/spec/ruby/core/thread/shared/wakeup.rb
@@ -36,7 +36,7 @@ describe :thread_wakeup, shared: true do
it "does not result in a deadlock" do
t = Thread.new do
- 100.times { Thread.stop }
+ 10.times { Thread.stop }
end
while t.status
@@ -47,6 +47,7 @@ describe :thread_wakeup, shared: true do
t.status.should == false
end
Thread.pass
+ sleep 0.001
end
t.status.should == false
@@ -56,6 +57,6 @@ describe :thread_wakeup, shared: true do
it "raises a ThreadError when trying to wake up a dead thread" do
t = Thread.new { 1 }
t.join
- -> { t.send @method }.should raise_error(ThreadError)
+ -> { t.send @method }.should.raise(ThreadError)
end
end