-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eventmachine not initialized - proxy isn't working #253
Comments
@knagode I tried but it didn't help. Other ideas maybe? |
Looks like someone had a similar issue a couple years ago: #43 (comment) |
this seems to be related to #239 but I can't understand how exactly |
I tried to install it in clean project on same machine and it worked.. Apparently there is a conflict with another gem/configuration. I removed all the spec configuration in problematic project (in files I noticed that proxy started working but still there is an error
|
I found that problem is happening due to WebMock which we heavily use. I think that both gems are super useful and they should work together. Example controller method:
Is there no way to make those two gems work together? |
In this example, what do you expect WebMock to do and what do you expect PuffingBilly to do? |
@ronwsmith Thnx for question. I would like to stub both Rails&browser based requests: Browser specific stub (via Puffing Billy proxy):
Ruby/Rails specific stub (via WebMock) :
I would like to block all network requests inside tests and wherever they occur by default(either on Rails or browser side). I would then whitelist/handle some specific requests via PuffiingBilly/WebMock. |
@knagode so it seems to work now but you still get an error in the |
@ronwsmith I was slowly removing gems from my repo and managed to fix In my case problem was: |
Puffing-billy is a proxy itself. If you use it as the proxy in Chrome, it will work just fine. Not sure what other proxy settings you're using in Chrome or why, but as far as I know you can only use one proxy in any browser. |
dSure. PuffingBilly is proxy for browser based requests. But if you are building app which is also making requests to external servers (e.g. requests to Stripe, Facebook Graph, etc ...) you sooner or later need something for stubbing those requests. That is why we use WebMock. I would expect that those 2 gems would work together because they are solving 2 problems. I saw that I am not the only one who expected that this to work out of the box. |
Have you tried the suggestions in that linked issue? Happy to accept a PR with README changes that document it better. |
I saw the same error( My current workaround is: # rails_helper.rb
...
module BillyProxyPatch
# @see https://github.com/oesmith/puffing-billy/blob/v1.1.2/lib/billy/proxy.rb#L26
def stop
super
@signature = nil
end
end
Billy::Proxy.prepend(BillyProxyPatch) |
Just updated eventmachine in 1.1.3. Please try it out and see if this issue persists. |
This issue persists on puffing-billy v1.1.3 with knapsack_pro queue mode.
|
@AlanFoster can you take a look at this issue? Seems to be introduced by your PR #239 . Thanks! |
I don't want to add much noise, but we've been looking into an issue similar to this one today. Seems like eventmachine's reactor is a singleton, right? So other gems that use it could theoretically stop it before |
@knagode is this still an issue for you? @julioolvr how did that workaround work? If it works, can you submit a PR with it? Thanks! |
We haven’t had issues in a while to the point I had completely forgot about this, so I guess the workaround was a success. I’ll see if I have time to send a PR during the week, but in the meantime this is the whole code for the patch (we have it in our # Patch `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) |
I looked a bit into opening a PR but I'm not sure how I'd write a test for it. Additionally, I had some issues |
@julioolvr thanks for your patch, which apparently removes the error in my case too. |
@fukayatsu You asked about the case when puffing-billy gem fails when using knapsack_pro gem in Queue Mode to run your tests in parallel on CI server. I got patch fix from one of users that was helpful: # 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
# executes before Queue Mode starts work
Billy.proxy.start
end
KnapsackPro::Hooks::Queue.after_queue do
# executes after Queue Mode finishes work
Billy.proxy.stop
end
end I've updated FAQ in my docs https://github.com/KnapsackPro/knapsack_pro-ruby#how-to-configure-puffing-billy-gem-with-knapsack-pro-queue-mode |
Happy to accept a PR with that patch (and tests) if someone wants to put one up. |
I am also having the this issue when I switch to unicorn as Capybara rack server. In addition to @ArturT patch I needed to patch I use both puffing-billy and webmock module BillyProxyPatch
def stop
return unless EM.reactor_running?
super
end
def port_in_use?(port)
return unless EM.reactor_running?
super
end
end |
I have a similar problem but none of above fixes didn't work for me following works for me module BillyProxyPatch
protected
def port_in_use?(port)
Timeout::timeout(1) do
super
end
rescue Timeout::Error
false
end
end
Billy::Proxy.prepend(BillyProxyPatch) because in my case PS |
I am getting this error
Anyone has idea why?
My setup in rails_helper.rb:
When I run test chrome looks like this:
The text was updated successfully, but these errors were encountered: