Skip to content

Instantly share code, notes, and snippets.

@khellan
Created June 7, 2012 15:19
Show Gist options
  • Save khellan/2889369 to your computer and use it in GitHub Desktop.
Save khellan/2889369 to your computer and use it in GitHub Desktop.
Double resume in JRuby. Note that the result in JRuby varies so it seems to be time sensitive.
require "minitest/autorun"
describe "Resuming Fiber" do
it "should raise double resume" do
data = [:a, :b, :c]
active = true
fiber = Fiber.new do
while active do
data.each {|item| sleep(0.1); Fiber.yield(item)}
end
end
fiber.resume.must_equal :a
third = nil
first = Thread.new do
Thread.stop
fiber.resume.must_equal :b
end
second = Thread.new do
Thread.stop
fiber.resume.must_equal :c
end
third = Thread.new do
first.wakeup
second.wakeup
end
first.join
second.join
active = false
end
end
ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
ruby test/double_resume.rb
Run options: --seed 62571
# Running tests:
E
Finished tests in 0.102593s, 9.7472 tests/s, 19.4944 assertions/s.
1) Error:
test_0001_should_raise_double_resume(Resuming Fiber):
FiberError: fiber called across threads
test/double_resume.rb:27:in `resume'
test/double_resume.rb:27:in `block (3 levels) in <main>'
1 tests, 2 assertions, 0 failures, 1 errors, 0 skips
ruby -v
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_01) [linux-amd64-java]
ruby test/double_resume.rb
Loaded suite test/double_resume
Started
E
Finished in 0.157000 seconds.
1) Error:
test_0001_should_raise_double_resume(ResumingFiberSpec):
FiberError: double resume
org/jruby/ext/fiber/Fiber.java:64:in `resume'
test/double_resume.rb:27:in `__file__'
1 tests, 1 assertions, 0 failures, 1 errors, 0 skips
Test run options: --seed 40834
ruby -v
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_01) [linux-amd64-java]
ruby test/double_resume.rb
Loaded suite test/double_resume
Started
F
Finished in 0.270000 seconds.
1) Failure:
test_0001_should_raise_double_resume(ResumingFiberSpec) [test/double_resume.rb:31]:
Expected :c, not nil.
1 tests, 3 assertions, 1 failures, 0 errors, 0 skips
Test run options: --seed 2096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment