Created
November 14, 2013 19:25
-
-
Save shurab/7472793 to your computer and use it in GitHub Desktop.
Mutex error while using EM.defer with Ruby 2.0.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
failed=0 | |
COUNT=25 | |
for (( i=1; i <= $COUNT; i++ )) | |
do | |
echo "Test # $i:" | |
rspec ./async_spec.rb | |
if (($?)) ; then | |
failed=$((failed+1)) | |
fi | |
sleep 1 | |
done | |
echo | |
echo "total: $COUNT" | |
echo "failed: $failed" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fiber' | |
require 'eventmachine' | |
require 'rspec' | |
module RSpec | |
module Core | |
class ExampleGroup | |
class << self | |
alias_method :run_alias, :run | |
def run(reporter) | |
if EM.reactor_running? | |
run_alias reporter | |
else | |
out = nil | |
EM.run do | |
Fiber.new { | |
out = run_alias reporter | |
EM.stop | |
}.resume | |
end | |
out | |
end | |
end | |
end | |
end | |
end | |
end | |
describe "BasicEventMachineTest with Threads" do | |
it "should run EventMachine gracefully and schedule callback execution in thread" do | |
f = Fiber.current | |
operation = proc { res = 1 } | |
operation_res = 0 | |
callback = proc { |proc_res| operation_res = proc_res; f.resume } | |
EventMachine.defer operation, callback | |
Fiber.yield | |
# this code should be executed only after the thread's return | |
expect(operation_res).to eq(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With ruby-2.0.0-p247
async_loop.sh
sometime fails with error:1 example, 0 failures/usr/local/lib/ruby/2.0.0/thread.rb:188:in
synchronize': Attempt to unlock a mutex which is not locked (ThreadError) from /usr/local/lib/ruby/2.0.0/thread.rb:188:in
block in pop'from /usr/local/lib/ruby/2.0.0/thread.rb:187:in
handle_interrupt' from /usr/local/lib/ruby/2.0.0/thread.rb:187:in
pop'from /usr/local/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1036:in `block in spawn_threadpool'
...