summaryrefslogtreecommitdiff
path: root/spec/ruby/library/fiber/transfer_spec.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-10-21 16:54:58 -0700
committerGitHub <noreply@github.com>2019-10-21 16:54:58 -0700
commitfa8ac91e957a076f6df1adaecad7896817138009 (patch)
treec8871b6dd46412100ba615b99860bd5c081eacaa /spec/ruby/library/fiber/transfer_spec.rb
parentf37cc1c719f12d2cad6032aa4e6f4236f0604992 (diff)
Fix Fiber#transfer
Fiber#transfer previously made it impossible to resume the fiber if it was transferred to (no resuming the target of Fiber#transfer). However, the documentation specifies that you cannot resume a fiber that has transferred to another fiber (no resuming the source of Fiber#transfer), unless control is transferred back. Fix the code by setting the transferred flag on the current/source fiber, and unsetting the transferred flag on the target fiber. Fixes [Bug #9664] Fixes [Bug #12555]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2588 Merged-By: jeremyevans <code@jeremyevans.net>
Diffstat (limited to 'spec/ruby/library/fiber/transfer_spec.rb')
-rw-r--r--spec/ruby/library/fiber/transfer_spec.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/spec/ruby/library/fiber/transfer_spec.rb b/spec/ruby/library/fiber/transfer_spec.rb
index d13053666c..fa094a022d 100644
--- a/spec/ruby/library/fiber/transfer_spec.rb
+++ b/spec/ruby/library/fiber/transfer_spec.rb
@@ -42,9 +42,18 @@ describe "Fiber#transfer" do
fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end]
end
- it "raises a FiberError when transferring to a Fiber which resumes itself" do
- fiber = Fiber.new { fiber.resume }
- -> { fiber.transfer }.should raise_error(FiberError)
+ ruby_version_is ''...'2.7' do
+ it "raises a FiberError when transferring to a Fiber which resumes itself" do
+ fiber = Fiber.new { fiber.resume }
+ -> { fiber.transfer }.should raise_error(FiberError)
+ end
+ end
+
+ ruby_version_is '2.7' do
+ it "allows transferring to a Fiber which resumes itself" do
+ fiber = Fiber.new { fiber.resume 1 }
+ fiber.transfer.should == 1
+ end
end
it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do