File: concurrency_spec.rb

package info (click to toggle)
ruby-vcr 6.0.0%2Breally5.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,320 kB
  • sloc: ruby: 8,456; sh: 177; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'spec_helper'

describe VCR do
  def recorded_content_for(name)
    VCR.cassette_persisters[:file_system]["#{name}.yml"].to_s
  end

  context 'when used in a multithreaded environment with an around_http_request', :with_monkey_patches => :excon do
    def preload_yaml_serializer_to_avoid_circular_require_warning_race_condition
      VCR.cassette_serializers[:yaml]
    end

    before { preload_yaml_serializer_to_avoid_circular_require_warning_race_condition }

    xit 'can use a cassette in an #around_http_request hook' do
      VCR.configure do |vcr|
        vcr.around_http_request do |req|
          VCR.use_cassette(req.parsed_uri.path, &req)
        end
      end

      threads = 50.times.map do
        Thread.start do
          Excon.get "http://localhost:#{VCR::SinatraApp.port}/search?q=thread"
        end
      end
      Excon.get "http://localhost:#{VCR::SinatraApp.port}/foo"
      threads.each(&:join)

      expect(recorded_content_for("search") +
             recorded_content_for("foo")).to include("query: thread", "FOO!")
    end
  end

  context 'when used in a multithreaded environment with a cassette', :with_monkey_patches => :excon do
    it 'properly stubs threaded requests' do
      VCR.use_cassette('/foo') do
        threads = 50.times.map do
          Thread.start do
            Excon.get "http://localhost:#{VCR::SinatraApp.port}/foo"
          end
        end
        threads.each(&:join)
      end

      expect(
        recorded_content_for("foo")).to include("FOO!")
    end
  end
end