KnapsackPro / knapsack_pro-ruby

Knapsack Pro gem splits tests across parallel CI nodes and makes sure that tests run in optimal time
https://knapsackpro.com
MIT License
133 stars 28 forks source link

VCR issues when running with knapsack #121

Closed vipulnsward closed 4 years ago

vipulnsward commented 4 years ago

I am facing a strange VCR issue when trying to run knapsack (Regular and queued mode both).

VCR debug logs show that somehow VCR is not picking up/initializing cassettes to replay.

Sample with knapsack: https://gist.github.com/vipulnsward/5d9d616dacb1e0d9b0e5fb4694652f7a Sample without knapsack: https://gist.github.com/vipulnsward/ab1657cbb5ccfd447f541fb8c58785d1

Notice the difference that with knapsack, this line is missing:

Initialized HTTPInteractionList with request matchers ...

This is called from https://github.com/vcr/vcr/blob/33757dfc6cabc1204e7a209676dfee9b098133d3/lib/vcr/cassette.rb#L103, so I am leaning towards this being some mutex/thread context issue?

This happens randomly. Upto a certain point cassettes work properly, suddenly they don't and it continues to fail after that(probably corruption in some config) till the specs are over.

Wondering if someone has faced or seen any similar issues?

ArturT commented 4 years ago

Hi @vipulnsward

Can you ensure you have in Gemfile

group :test do
  gem 'vcr'
  gem 'webmock', require: false # this must be set to false
end

in spec helper or rails helper you must ensure requests to Knapsack Pro API are allowed.

require 'vcr'
VCR.configure do |config|
  config.hook_into :webmock
  config.ignore_hosts('localhost', '127.0.0.1', '0.0.0.0', 'api.knapsackpro.com')
end

# add below when you hook into webmock
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true, allow: ['api.knapsackpro.com'])

This is based on tips in https://docs.knapsackpro.com/knapsack_pro-ruby/guide/

Do you run tests on CI? Are they failing on CI or do you test this locally?

Can you paste the exact error with backtrace returned by RSpec when running knapsack_pro command?

Can you paste your test code, how do you use VCR. How the path to the cassette looks like.

Do you use parallel_tests gem at the same time?

Do you reconfigure VCR somehow during runtime of the tests?

I don't recall any similar issue to yours so I'm wondering if this is something specific to your project and how you setup VCR.

vipulnsward commented 4 years ago

Update:

We had 2 uses of VCR.configuration.ignore_request { true } for some variable request specs. Commenting them out seems to make the CI be stable again.

Will need to figure out why this is though, since we do need them for some valid spec scenarios and it seems to work fine if run without knapsack/threaded mode.

Can close this issue, if you'd like meanwhile.

ArturT commented 4 years ago

It looks like you have to adjust your block VCR.configuration.ignore_request { true } to return false when the request is going to Knapsack Pro API (You should allow a request for api.knapsackpro.com) and otherwise, return true to keep your current behavior. https://relishapp.com/vcr/vcr/v/2-2-5/docs/configuration/ignore-request

If you see any exception or backtrace error please share. You can also send a message to support email https://knapsackpro.com/contact if this contains private data.

For now, I would say it's rather not related to "mutex/thread context issue" because you run knapsack_pro command per CI node in the isolated machine (i.e. docker container in Buildkite I guess). So just 1 test is executed at a time inside of knapsack_pro process using RSpec.