Created
November 26, 2012 17:10
VCR against multithreaded code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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