6

OK, I am writing performance tests and am having trouble getting my session to persist like it does in integration tests. As I understand it, PerformanceTest is a child of IntegrationTest and any integration tests should work with performance test. However, when I take a integration test and copy it over to performance, change the ActionController::IntegrationTest to ActionController::PerformanceTest and then run the test, it fails.

I am using Authlogic and have not had a problem with the integration test sessions sticking around. With the performance tests though it looks like the session gets created properly but when I visit the "/reports" page (which is a protected page) it redirects me to the login page like there is no user session at all.

require 'performance_test_help'

class SimpleTest < ActionController::PerformanceTest
  setup :activate_authlogic

  test "login" do
    assert user_session = UserSession.create!(User.find_by_login("admin"))

    get "/reports"
    assert_response :success
  end
end

What's going on here? I've tried multiple ways to get a user session (create, post, etc.) and nothing seems to work. This is the first time I've written performance tests so I'm probably doing something stupid...

BTW: I am running Ruby 1.8.7, Rails 2.2.2 on Debian Squeeze.

Richard Hurt
  • 2,049
  • 24
  • 32

2 Answers2

1

You have to setup your performance tests like your integration tests.

Try to login using post:

post "user_session", :user_session => {:login => "user", :password => "password"}
leaber
  • 168
  • 5
  • Yes, you must post to login to get logged in, because the uses_session in the test becomes a local variable, not an application-scoped variable. – Gabor Garami Jul 26 '11 at 17:00
0

not sure what is in your setup there, but you are missing require 'test_helper' as well. If this method is in there, or in an Authlogic test helper, you may have to make sure it's included.

pjammer
  • 9,489
  • 5
  • 46
  • 56