Git Product home page Git Product logo

Comments (19)

jethroo avatar jethroo commented on August 17, 2024 5

I was able to keep my existing Webmock setting and just enabled puffing billy for a test there i needed it as follows:

context 'with proxy', driver: :poltergeist_billy do
  scenario 'the user can share the link via facebook', billy: true do
    #test logic   
  end 
end

my Rspec config

RSpec.configure do |config|  
  config.around(:each, billy: true) do |example|
    WebMock.allow_net_connect!
    example.run
    WebMock.disable_net_connect!(allow_localhost: true)
  end
end

hope this might help others with same issues ;)

from puffing-billy.

korbin avatar korbin commented on August 17, 2024 4

Few years late, but just stumbled across this:

If you're not using EventMachine (or WebMock for any other EM requests):

WebMock::HttpLibAdapters::EmHttpRequestAdapter.disable!

in spec_helper.rb will disable WebMock's interception of EM HTTP requests, allowing upstream proxy requests to go through.

Pretty blunt, but it works.

from puffing-billy.

nullobject avatar nullobject commented on August 17, 2024 1

You can also do:

WebMock.enable!(except: :em_http_request)

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

Just realized in other issues below that there's no need to re-register the :webkit driver. That still hasn't resolved the issue I was seeing, though.

from puffing-billy.

oesmith avatar oesmith commented on August 17, 2024

Have you tried using localhost:8089 (i.e., no http:// prefix) in your whitelist entry? AFAIK, the whitelist only matches host:port, not full urls.

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

Yeah I added that in there too, and a bunch of other variations like this:

Billy.config.whitelist = [/.*/,"#{server.host}:#{server.port}", 'http://localhost:8089', '//localhost:8089/static', 'localhost:8089', 'localhost', server.host]

the /.*/ was attempting to whitelist everything. Is there an option like that?

Basically at this point I want it to only stub external requests if I want it to.

if I do a visit 'http://www.google.com'
in selenium_billy, it tells me that the proxy server is refusing connections.
"Firefox is configured to use a proxy server that is refusing connections."

could that be related also? Do you guys happen to have an IRC channel or something you hang out on? I feel like it's quite difficult to get a hold of you or @ronwsmith unless I'm lucky!

from puffing-billy.

ronwsmith avatar ronwsmith commented on August 17, 2024

Hmm, are you using another proxy server for anything? It sounds like your setup is quite unique.

Try tailing your logs, via tail -f log/* | grep puffing-billy, and see what it outputs for both the assets and your google test. It will help track down where it's being stopped, if it's even getting to the Billy proxy.

What does your Billy.config block look like? Also, do you have any other driver configuration settings in your spec_helper,rb?

Lastly, I don't think you'll get real-time support for any gems :) A day or two response is typical for ones under active development.

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

this is the output i'm getting atm:

puffing-billy: Proxy listening on http://localhost:54085
puffing-billy: STUB GET for 'http://www.google.com/'
puffing-billy: CACHE KEY for 'http://127.0.0.1:54086/' is 'get_127.0.0.1_62fe3d14ea426b905bd8e3e397d976261006bbe8'
puffing-billy: PROXY GET for 'http://127.0.0.1:54086/'
puffing-billy: Received response status code 200 for http://127.0.0.1:54086/
puffing-billy: CACHE KEY for 'http://127.0.0.1:54086/assets/wedding.css' is 'get_127.0.0.1_0cba30f27f30253eb08410bd2920111d18cbc34b'
puffing-billy: PROXY GET for 'http://127.0.0.1:54086/assets/wedding.css'
puffing-billy: CACHE KEY for 'http://127.0.0.1:54086/assets/application.js' is 'get_127.0.0.1_94d99b6a3944dceb9304887e5da3634d7d46bdd6'
puffing-billy: PROXY GET for 'http://127.0.0.1:54086/assets/application.js'
puffing-billy: CACHE KEY for 'http://cdn.optimizely.com/js/29863440.js' is 'get_cdn.optimizely.com_1174e753bd6e7cd3ff0c65340db12368d05234e3'
puffing-billy: PROXY GET for 'http://cdn.optimizely.com/js/29863440.js'
puffing-billy: Request failed: http://127.0.0.1:54086/assets/wedding.css
puffing-billy: Request failed: http://127.0.0.1:54086/assets/application.js

I created a billy.rb file in the features/support/ folder that gets required when I run cucumber.
this is what's in it:

require_relative '../support/webmock' ### I require this because we use WebMock and it doesnt like one of these calls.

server = Capybara.current_session.server

Billy.configure do |c|
c.cache = false
c.cache_request_headers = false
c.ignore_params = ["http://#{server.host}:#{server.port}/assets/application.js", "http://#{server.host}:#{server.port}/assets/wedding.css"]
c.persist_cache = false
c.non_successful_cache_disabled = false
c.non_successful_error_level = :warn
c.non_whitelisted_requests_disabled = false
c.whitelist = ["#{server.host}:#{server.port}", 'localhost:8089']
end

So... right now it seems like the problem lies with these two requests:
puffing-billy: Request failed: http://127.0.0.1:54086/assets/wedding.css
puffing-billy: Request failed: http://127.0.0.1:54086/assets/application.js

as you can see in the config, I tried adding in those links to the c.ignore_params array, but this is still happening.

I did notice however that the log says "Listening on proxy" and the port is different than my capybara server.

Is that just the EM ip?

Any ideas on how to further troubleshoot this? Thx for the quick replies!

from puffing-billy.

ronwsmith avatar ronwsmith commented on August 17, 2024

Yes the different IP is EM and is expected.

I think the root of the issue is the "Firefox is configured to use a proxy server that is refusing connections" error, which is likely outside of puffing-billy. Do you have or require any other proxy servers to hit your web site outside of puffing-billy? It potentially is also webmock blocking requests. I've had to set allow_net_connect! in my spec_helper to get "external" requests to process correctly.

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

Yeah, essentially my require_relative '../support/webmock' basically requires a file which does this:

WebMock.disable_net_connect!(:allow_localhost => true)

Which... afaik shouldn't affect those assets from being loaded.
I don't believe we require any other proxy servers to hit the website, or any proxy settings within the cucumber setup in general, besides webmock / puffing-billy.

Is there any other data I can look into to better troubleshoot this?

from puffing-billy.

oesmith avatar oesmith commented on August 17, 2024

AFAIK, WebMock doesn't play well with Billy. It hooks into the http client
library that billy uses to do upstream proxy requests. Have you tried
disabling WebMock completely to see what effect that has?

Olly

On Wednesday, March 26, 2014, Josiah Anjos [email protected] wrote:

Yeah, essentially my require_relative '../support/webmock' basically
requires a file which does this:

WebMock.disable_net_connect!(:allow_localhost => true)

Which... afaik shouldn't affect those assets from being loaded.
I don't believe we require any other proxy servers to hit the website, or
any proxy settings within the cucumber setup in general, besides webmock /
puffing-billy.

Is there any other data I can look into to better troubleshoot this?

Reply to this email directly or view it on GitHubhttps://github.com//issues/44#issuecomment-38741703
.

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

Ah you guys are right. I did WebMock.allow_net_connect! and everything did render... I would like to keep both though... Do you guys have any experience with using both? Having WebMock allow puffing-billy to do all its magic?

Edit: Also, changed the title to reflect the actual issue!

from puffing-billy.

ronwsmith avatar ronwsmith commented on August 17, 2024

Great, glad we narrowed it down! Unfortunately, I don't think they will ever work together nicely as they are sort of different solutions for the same issue -- both are intercepting requests and performing some action. Perhaps look into using the stubbing feature of puffing-billy to eliminate whatever need you have for webmock.

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

Well, correct me if I'm wrong, but isn't puffing-billy more browser centric, and webmock is more about API calls your app makes?

Can puffing-billy do what webmock does for the API?

from puffing-billy.

ronwsmith avatar ronwsmith commented on August 17, 2024

You are correct but it's not only API calls for webmock, it's anything in the same thread (whereas browsers are running in a different thread). What I do is limit webmock to unit tests and puffing-billy to feature tests and I turn webmock off and on in before and after blocks for type: :feature.

from puffing-billy.

dezmathio avatar dezmathio commented on August 17, 2024

Hmm... Gotcha. I was hoping to make puffing-billy a general thing for our cucumber tests, but it looks like it's going to have to be something more localized/specific for some scenarios. We have some cases where we use webmock to return specific data for our api calls during acceptance/feature tests, so if we can't use both, I may have to come up with a custom way of setting up this data. Maybe even in a Before do, checking if the current driver is :webkit_billy, then to do a WebMock.allow_net_connect! or something of the sorts.
Well, I think this helps me figure all of this out, and will allow me to make an informed decision about which tools to use. Thanks for getting back to me so quickly again, guys.

from puffing-billy.

aivils avatar aivils commented on August 17, 2024

Suggestion does not work in my case. Looks like Webmock kills billy proxy server. I made proxy start/stop for each rspec. proxy runs with fixed TCP port.

module Billy
  class Config
    attr_accessor :port
  end
end

module Billy
  class Proxy
    def stop
      EM.stop_server(@signature) if @signature
      @signature = nil
    end

    def port
      Billy.config.port
    end

    protected

    def main_loop
      EM.run do
        EM.error_handler do |e|
          puts e.class.name, e
          puts e.backtrace.join("\n")
        end

        @signature = EM.start_server('127.0.0.1', port, ProxyConnection) do |p|
          p.handler = self
          p.cache = @cache
        end

        Billy.log(:info, "puffing-billy: Proxy listening on #{url}")
      end
    end
  end
end

Billy.configure do |c|
  c.ignore_cache_port = false
  c.cache = true
  c.cache_path = 'spec/fixtures/billy/'
  c.persist_cache = true
  c.port = 51111
end

def billy_whitelist_capybara
  if server = Capybara.current_session.server
    server_url = "#{server.host}:#{server.port}"
    unless Billy.config.whitelist.include?(server_url)
      Billy.configure do |c|
        c.whitelist << server_url
      end
    end
  end
end

RSpec.configure do |config|
  config.before(:each, billy: true) do
    WebMock.allow_net_connect!
    billy_whitelist_capybara
    proxy.start
    Capybara.current_driver = :selenium_billy
  end

  config.after(:each, billy: true) do
    Capybara.use_default_driver
    Capybara.javascript_driver = :poltergeist
    proxy.stop
    proxy.cache.use_default_scope
    WebMock.disable_net_connect!(allow_localhost: true)
  end
end

from puffing-billy.

ronwsmith avatar ronwsmith commented on August 17, 2024

@aivils, what exactly are you trying to do? Your setup looks overly complicated so my initial assumption is that your test is trying to do too much. Can you provide a (scrubbed) example spec?

from puffing-billy.

aivils avatar aivils commented on August 17, 2024

I try to run multiple tests from a single *.rb file

feature 'as a renter' do
  context 'choose cars from results' do
    scenario 'i can add car to a cart', billy: true do
      proxy.cache.scope_to 'search-empty'
      visit search_page_path(type: 'car-rental')
    end
    scenario 'i can delete car from cart', billy: true  do
      proxy.cache.scope_to 'search-empty'
      visit search_page_path(type: 'car-rental')
    end
  end
end

When i use pure puffing-billy, then both tests run fine. When i use puffing-billy and webmock, then 1st test is ok but 2nd test failed because browser reported "cannot connect to proxy server". Anyway each single test runs fine.
Sorry, i cannot recall what i debug in the webmock, but finaly i decide to start/stop billy proxy server for each test as a simplest solution. I suppose webmock override libraries used by puffing-billy.
Billy configuration read in post above.

from puffing-billy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.