Testing Devise sign_in in a multi-threaded environment

35 views Asked by At

I am using the following code to test multi-threading in a Rails app where users are handled by Devise.

  test "multi-threaded sign-in with Devise" do
    user1 = create(:user)
    user2 = create(:user)

    threads = []
    threads << Thread.new do
      sign_in(user1)
      get("/")
      assert_response(:success)
      sign_out(user1)
    end

    threads << Thread.new do
      sign_in(user2)
      get("/")
      assert_response(:success)
      sign_out(user2)
    end

    threads.each(&:join)
  end

If I comment out one of the threads, the assertion passes. With both threads, I get the following error:


Failure:
PoItemDetailsControllerTest#test_multi-threaded_sign-in_with_Devise [/app/test/controllers/po_item_details_controller_test.rb:126]
Minitest::Assertion: Expected response to be a <2XX: success>, but was a <302: Found> redirect to <http://www.example.com/users/sign_in>
Response body: <html><body>You are being <a href="http://www.example.com/users/sign_in">redirected</a>.</body></html>

How can I test controller requests in a multi-threaded environment?

0

There are 0 answers