Capybara慢速测试,视图渲染需要大量时间
Capybara slow test, view rendering takes a lot of time
使用最新的水豚 Rails 4.2 时问题仍然存在。
我认为这不是特定于驱动程序的问题,因为它在 rack_test、capybara-webkit 甚至 poltgeist 下运行缓慢。
渲染大约需要。 78086 毫秒。
示例日志输出:
(6.5ms) COMMIT
Started GET "/coming-soon" for 127.0.0.1 at 2015-08-07 11:53:27 +0200
Processing by FeaturesController#index as HTML
TranslationKey Load (10.0ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "features.page-description"]]
Feature Load (0.5ms) SELECT "features".* FROM "features"
TranslationKey Load (0.5ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "features.see_preview"]]
TranslationKey Load (0.4ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "features.form-description"]]
Rendered features/index.html.haml within layouts/application (67.2ms)
TranslationKey Load (0.4ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "meta.title"]]
TranslationKey Load (0.4ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "meta.description"]]
TranslationKey Load (0.3ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "meta.keywords"]]
MenuItem Load (6.1ms) SELECT "menu_items".* FROM "menu_items" WHERE "menu_items"."menu_category" = ORDER BY position ASC [["menu_category", "3"]]
TranslationKey Load (0.2ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "page.instagram_url"]]
TranslationKey Load (0.2ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "page.pinterest_url"]]
Rendered shared/_header.html.haml (416.5ms)
MenuItem Load (0.2ms) SELECT "menu_items".* FROM "menu_items" WHERE "menu_items"."menu_category" = ORDER BY position ASC [["menu_category", "1"]]
Rendered shared/_flash_messages.html.haml (5.4ms)
Rendered shared/_analytics.html.erb (0.5ms)
Completed 200 OK in 78086ms (Views: 78046.3ms | ActiveRecord: 21.5ms)
TransitionKeys 是 fast_gettext 的东西。
MenuItems 是一个单元格 (cells gem).
我使用以下 gem 进行测试:
group :test do
gem 'factory_girl_rails'
gem 'mocha'
gem 'shoulda'
gem 'database_cleaner'
gem "minitest-rails-capybara"
gem 'capybara-email'
gem 'capybara-webkit'
gem 'poltergeist'
gem 'cucumber-rails', :require => false
end
我也试过改变事务和截断策略。
怎么了?
编辑:
当我启动本地服务器时:
RAILS_ENV=测试包执行 rails c
即使 config.assets.debug = false
也非常慢
确保在您的相关 config/environments/*.rb
文件中设置了 config.assets.debug = false
(也许只是 test.rb
)。
如果这仅发生在 运行 的第一个测试中,那么这与 Capybara 无关,很可能是编译资产的资产管道。您可以在 运行 测试之前尝试在测试环境中预编译它们,看看是否可以加快速度。
使用最新的水豚 Rails 4.2 时问题仍然存在。
我认为这不是特定于驱动程序的问题,因为它在 rack_test、capybara-webkit 甚至 poltgeist 下运行缓慢。
渲染大约需要。 78086 毫秒。
示例日志输出:
(6.5ms) COMMIT
Started GET "/coming-soon" for 127.0.0.1 at 2015-08-07 11:53:27 +0200
Processing by FeaturesController#index as HTML
TranslationKey Load (10.0ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "features.page-description"]]
Feature Load (0.5ms) SELECT "features".* FROM "features"
TranslationKey Load (0.5ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "features.see_preview"]]
TranslationKey Load (0.4ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "features.form-description"]]
Rendered features/index.html.haml within layouts/application (67.2ms)
TranslationKey Load (0.4ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "meta.title"]]
TranslationKey Load (0.4ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "meta.description"]]
TranslationKey Load (0.3ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "meta.keywords"]]
MenuItem Load (6.1ms) SELECT "menu_items".* FROM "menu_items" WHERE "menu_items"."menu_category" = ORDER BY position ASC [["menu_category", "3"]]
TranslationKey Load (0.2ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "page.instagram_url"]]
TranslationKey Load (0.2ms) SELECT "translation_keys".* FROM "translation_keys" WHERE "translation_keys"."key" = LIMIT 1 [["key", "page.pinterest_url"]]
Rendered shared/_header.html.haml (416.5ms)
MenuItem Load (0.2ms) SELECT "menu_items".* FROM "menu_items" WHERE "menu_items"."menu_category" = ORDER BY position ASC [["menu_category", "1"]]
Rendered shared/_flash_messages.html.haml (5.4ms)
Rendered shared/_analytics.html.erb (0.5ms)
Completed 200 OK in 78086ms (Views: 78046.3ms | ActiveRecord: 21.5ms)
TransitionKeys 是 fast_gettext 的东西。 MenuItems 是一个单元格 (cells gem).
我使用以下 gem 进行测试:
group :test do
gem 'factory_girl_rails'
gem 'mocha'
gem 'shoulda'
gem 'database_cleaner'
gem "minitest-rails-capybara"
gem 'capybara-email'
gem 'capybara-webkit'
gem 'poltergeist'
gem 'cucumber-rails', :require => false
end
我也试过改变事务和截断策略。
怎么了?
编辑:
当我启动本地服务器时:
RAILS_ENV=测试包执行 rails c
即使 config.assets.debug = false
确保在您的相关 config/environments/*.rb
文件中设置了 config.assets.debug = false
(也许只是 test.rb
)。
如果这仅发生在 运行 的第一个测试中,那么这与 Capybara 无关,很可能是编译资产的资产管道。您可以在 运行 测试之前尝试在测试环境中预编译它们,看看是否可以加快速度。