title: RSpec - testing race conditions
body: <p>I'm trying to write a RSpec controller test checking for race conditions based on <a href="http://blog.arkency.com/2015/09/testing-race-conditions/" rel="nofollow noreferrer">this blog post</a>, but created <code>Thread</code>s don't "see" the <code>User</code>s created at the beginning of the test.
  The blog post suggests to change <code>config.use_transactional_fixtures</code> to <code>false</code>, but even with this setting <code>User</code>s aren't visible.</p>
  
  <p>Here's the test:</p>
  
  <pre><code>it "avoids race conditions" do
    u = create(:user, :without_settings)
    u_2 = create(:user, :without_settings)
  
    wait_for_it = true
  
    threads = Array.new(4).map {
      Thread.new do
        true while wait_for_it
        # send the request
        signed_post(
          u,
          api_v1_blockades_path,
          params: {
            blockade: {
              blocked_user_id: u_2.id,
              reason: 11
            }
          }
        )
      end
    }
  
    wait_for_it = false
    threads.map(&amp;:join)
  
    expect(u.blockades.count).to eq(1)
  end
  </code></pre>
  
  <p>For authentication i'm using the <a href="https://github.com/mgomes/api_auth" rel="nofollow noreferrer">ApiAuth gem</a>:</p>
  
  <pre><code>before_action :api_authenticate
  
  private
  
  def current_user
    @current_user ||= User.find_by(id: ApiAuth.access_id(request))
  end
  
  def api_authenticate
    head(:unauthorized) unless current_user &amp;&amp; ApiAuth.authentic?(request, current_user.auth_token)
  end
  </code></pre>