Skip to content

Instantly share code, notes, and snippets.

@Fryguy
Created November 26, 2012 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Fryguy/4149410 to your computer and use it in GitHub Desktop.
Save Fryguy/4149410 to your computer and use it in GitHub Desktop.
VCR against multithreaded code
require "vcr"
require "net/http"
VCR.configure do |c|
c.cassette_library_dir = '/tmp'
c.hook_into :webmock
c.default_cassette_options = {
record: :once
}
end
# forgive me Google ;)
module ThirdPartyApi
def self.query
threads = []
queries = 200.times.map { |n| "query-#{n}" }
queries.each_slice(5) do |sliced_queries|
threads << Thread.new do
sliced_queries.each do |q|
Net::HTTP.get("google.com", "?q=#{q}")
end
end
end
threads.map(&:join)
end
end
VCR.use_cassette("google_search") do
ThirdPartyApi.query
puts "success!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment