2011-02-15 86 views
2

我試圖在新的Rails 3應用程序中使用AB進行性能記錄/跟蹤。 由於應用程序總是需要登錄,我不得不做POST請求登錄。 我能夠將憑證放在一些文本文件中,如下所示,但AuthenticityToken提供了該問題。Rails3的ApacheBenchmark ab問題authenticity_token

#login_data.txt

user_account%5Busername%5D=admin&user_account%5Bpassword%5D=adminhr 

#AB command

ab -v4 -n100 -t5 -T 'application/x-www-form-urlencoded' -p login_data.txt http://nhc.lvh.me:3000/ 

#The log

Started POST "/" for 127.0.0.1 at 2011-02-15 11:13:37 +0545 
    Processing by CompaniesController#index as */* 
    Parameters: {"user_account"=>{"username"=>"admin", "password"=>"[FILTERED]"}} 
Completed in 1ms 

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): 


Rendered /Users/millisami/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms) 
Rendered /Users/millisami/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1194.0ms) 
Rendered /Users/millisami/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (1291.3ms) 

的問題是如何通過或忽略AuthenticityToken使用ab時? 由於它是動態生成的,我可以存儲在某個地方還是有其他更好的解決方案?

回答

0

你可以做的是建立一個環境,除了測試和開發。您可以放置​​一個development.rb環境的副本並將其命名爲benchmark.rb。

還爲基準環境放置了database.yml條目。你可以複製開發條目的內容。

然後在代碼中,如果環境是基準測試,則可以跳過驗證真實性令牌。現在啓動rails s -e基準測試並針對該服務器執行基準測試。