Using Knapsack Pro in Queue Mode with puffing-billy
caution
This is needed only if you are using Knapsack Pro in Queue Mode and legacy versions of knapsack_pro
older than 7.0.
If you use the puffing-billy gem and encounter the crash described in this Github issue, apply the following patch:
# rails_helper.rb or spec_helper.rb
# A patch to `puffing-billy`'s proxy so that it doesn't try to stop eventmachine's reactor if it's not running.
module BillyProxyPatch
def stop
return unless EM.reactor_running?
super
end
end
Billy::Proxy.prepend(BillyProxyPatch)
# A patch to `puffing-billy` to start EM if it has been stopped.
Billy.module_eval do
def self.proxy
if @billy_proxy.nil? || !(EventMachine.reactor_running? && EventMachine.reactor_thread.alive?)
proxy = Billy::Proxy.new
proxy.start
@billy_proxy = proxy
else
@billy_proxy
end
end
end
if ENV["KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC"]
KnapsackPro::Hooks::Queue.before_queue do
Billy.proxy.start
end
KnapsackPro::Hooks::Queue.after_queue do
Billy.proxy.stop
end
end
This problem is caused by how knapsack_pro
in Queue Mode uses RSpec::Core::Runner
.