gpt4 book ai didi

ruby-on-rails - 如何在 cucumber 测试中集成 parallel_test 和 thinking sphinx?

转载 作者:数据小太阳 更新时间:2023-10-29 07:18:28 25 4
gpt4 key购买 nike

我有带有 cucumber 功能的 Rails 4 应用程序。在一些测试中,我考虑了 sphinx 数据,例如:

@javascript @sphinx
Feature: Edit a service
Scenario: Editing
Given I exist as an "individual"
And I have few services as individual user
And Sphinx indexes all models
...
Then I should see I18n translation for key "views.messages.notices.add.updated"

@sphinx 钩子(Hook)包含以下逻辑:

Before('@sphinx') do
self.use_transactional_fixtures = false
ThinkingSphinx::Test.start
sleep 2 # Give some time for sphinx to start.
end

After('@sphinx') do
ThinkingSphinx::Test.stop
self.use_transactional_fixtures = true
end

Sphinx 索引所有模型 包含以下内容:

Given(/^Sphinx indexes all models$/) do
ThinkingSphinx::Test.index
# Wait for Sphinx to finish loading in the new index files.
sleep 0.25 until index_finished?
end

这是database.yml:

development:
adapter: postgresql
database: my-project_development
host: localhost
encoding: UTF8
pool: 5

test: &test
adapter: postgresql
database: my-project_test<%= ENV['TEST_ENV_NUMBER'] %>
username: my-project
password: my-project
host: localhost
encoding: UTF8
pool: 15

当我通过 rake parallel:features(通过 parallel_tests )运行我的规范时,思考 sphinx 的规范总是失败:

Can't connect to MySQL server on '127.0.0.1' (61) (ThinkingSphinx::ConnectionError)
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:90:in `rescue in query'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:93:in `query'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:75:in `query_all'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search/batch_inquirer.rb:17:in `block in results'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:37:in `block in take'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/innertube-1.1.0/lib/innertube.rb:138:in `take'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:35:in `take'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search/batch_inquirer.rb:16:in `results'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/inquirer.rb:9:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search/context.rb:22:in `log'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/inquirer.rb:8:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/geographer.rb:11:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/sphinxql.rb:14:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/middleware-0.1.0/lib/middleware/runner.rb:31:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/middleware-0.1.0/lib/middleware/builder.rb:102:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search.rb:67:in `populate'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search.rb:113:in `method_missing'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:323:in `hash'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:323:in `-'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:323:in `merge_resolving_duplicate_squeel_equalities'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:45:in `merge'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:555:in `with_default_scope'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:582:in `exec_queries'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:471:in `load'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:220:in `to_a'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:565:in `blank?'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/core_ext/object/blank.rb:20:in `present?'
/Users/serj/Projects/my-project/app/controllers/services_controller.rb:90:in `find_services'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:537:in `_run__1953055605195034856__process_action__callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/abstract_controller/base.rb:136:in `process'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:44:in `process'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal.rb:195:in `dispatch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_controller/metal.rb:231:in `block in action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:48:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:71:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `each'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:680:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-pjax-0.7.0/lib/rack/pjax.rb:12:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/request_store-1.0.5/lib/request_store/middleware.rb:9:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/simple_captcha2-0.2.1/lib/simple_captcha/middleware.rb:20:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/flash.rb:241:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/cookies.rb:486:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/query_cache.rb:36:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__4201420912784056511__call__callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/cucumber-rails-1.4.0/lib/cucumber/rails/action_controller.rb:10:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/railties-4.0.3/lib/rails/rack/logger.rb:38:in `call_app'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `block in tagged'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:25:in `tagged'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `tagged'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/activesupport-4.0.3/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/static.rb:64:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/railties-4.0.3/lib/rails/engine.rb:511:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/railties-4.0.3/lib/rails/application.rb:97:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/capybara-2.2.1/lib/capybara/server.rb:19:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353@my-project/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

但是如果我在非并行模式下运行这些失败的测试(我的意思是 cucumber path/to/my/test.rb),它会起作用(是的,parallel_tests适用于其他测试)。我该如何解决这个问题?

最佳答案

您需要配置 config/thinking_sphinx.yml 以在 Sphinx 文件的路径中包含该环境变量 TEST_ENV_NUMBER - deployment page 中列出的设置文档的数量应该是所需要的,加上端口号(mysql41 设置)。也许是这样的?

test:
mysql41: <%= ENV['TEST_ENV_NUMBER'].to_i + 9307 %>
pid_file: /path/to/app/tmp/searchd.<%= ENV['TEST_ENV_NUMBER' %>.pid
indices_location: /path/to/app/db/sphinx/<%= ENV['TEST_ENV_NUMBER' %>
configuration_file: /path/to/app/config/test.<%= ENV['TEST_ENV_NUMBER' %>.sphinx.conf
binlog_path: /path/to/app/db/sphinx/<%= ENV['TEST_ENV_NUMBER' %>/binlog

我自己没有使用过这种方法(或 parallel_test),所以这当然是猜测,但值得一试。

关于ruby-on-rails - 如何在 cucumber 测试中集成 parallel_test 和 thinking sphinx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23339607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com