【问题标题】:Why does my session expire when using PerformanceTest and not IntegrationTest?为什么我的会话在使用 PerformanceTest 而不是 IntegrationTest 时会过期?
【发布时间】:2010-12-15 19:48:48
【问题描述】:

好的,我正在编写性能测试,但无法让会话像在集成测试中那样持续存在。据我了解,PerformanceTest 是 IntegrationTest 的子项,任何集成测试都应该与性能测试一起使用。但是,当我进行集成测试并将其复制到性能时,将 ActionController::IntegrationTest 更改为 ActionController::PerformanceTest 然后运行测试,它会失败。

我正在使用 Authlogic,并且没有遇到集成测试会话持续存在的问题。通过性能测试,虽然看起来会话已正确创建,但是当我访问“/reports”页面(这是一个受保护的页面)时,它会将我重定向到登录页面,就像根本没有用户会话一样。

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

这里发生了什么?我尝试了多种方法来获取用户会话(创建、发布等),但似乎没有任何效果。这是我第一次编写性能测试,所以我可能在做一些愚蠢的事情......

顺便说一句:我在 Debian Squeeze 上运行 Ruby 1.8.7、Rails 2.2.2。

【问题讨论】:

  • 我也遇到了同样的问题,当然希望得到任何指点...您自己解决了问题吗?
  • 叫我 AOLer。我也是!有什么办法吗?

标签: ruby-on-rails integration-testing authlogic performance-testing


【解决方案1】:

您必须像集成测试一样设置性能测试。

尝试使用帖子登录:

post "user_session", :user_session => {:login => "user", :password => "password"}

【讨论】:

  • 是的,您必须发布到登录才能登录,因为测试中的uses_session成为局部变量,而不是应用程序范围的变量。
【解决方案2】:

不确定您的设置中有什么,但您也缺少require 'test_helper'。如果此方法在其中,或者在 Authlogic 测试助手中,您可能必须确保它被包含在内。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-26
    • 2012-10-02
    • 2023-04-07
    • 1970-01-01
    • 2013-09-18
    • 2012-07-22
    • 1970-01-01
    • 2013-03-23
    相关资源
    最近更新 更多