1

我有这个痕迹,不知道如何追查这个原因。这是在测试运行期间弹出的。关于如何进行的任何想法?

DEPRECATION WARNING: Database connections will not be closed automatically, please close your
database connection at the end of the thread by calling `close` on your
connection.  For example: ActiveRecord::Base.connection.close
. (called from mon_synchronize at /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211)
/home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:212:in `block in clear_stale_cached_connections!'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:210:in `each'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:210:in `clear_stale_cached_connections!'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:274:in `block (2 levels) in checkout'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/query_cache.rb:61:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `_run__1441209721629762293__call__222931449678172199__callbacks'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:32:in `call_app'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:16:in `block in call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/tagged_logging.rb:22:in `tagged'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:16:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/request_id.rb:22:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/static.rb:62:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/airbrake-3.1.6/lib/airbrake/rack.rb:41:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/airbrake-3.1.6/lib/airbrake/user_informer.rb:12:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:479:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:223:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:134:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:64:in `block in call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in `each'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capybara-1.1.3/lib/capybara/server.rb:17:in `call'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
4

3 回答 3

3

那么工作解决方案是:

after do
  ActiveRecord::Base.connection.close
end

你可以看看这个问题

ActiveRecord 连接警告。(数据库连接不会自动关闭)

于 2013-04-22T19:25:33.147 回答
1

不确定这是否适合遇到此问题的任何人,但我相信我在自己的应用程序中找到了解决方案。

场景:一些功能测试(使用 rspec 和 capybara)导致出现此警告,尽管测试通过了。

问题:测试正在加载一个页面,该页面然后使用 ajax 调用控制器,并使用几个部分 render_to_string 渲染回来。其中一个部分抛出了错误,但测试只是寻找其他东西的外观,这不是该部分的一部分。所以测试通过了。

我们需要对这种特定方法进行更好的测试,而且它应该做的事情更少。但这是我的问题的原因,我只是在运行测试时通过跟踪 test.log 才看到它。

于 2014-07-15T22:46:23.743 回答
0

我和 Dominik 有同样的问题,但我无法解决。

以下是一些想法:

  • 首先,我没有在我的代码中使用任何线程。
  • 我责怪 VanityUrls 因为一旦页面加载,我一直在寻找 log/test.log 并且有一堆图像调用落入 Vanity 路线。我的猜测是每个请求都会产生一个线程?我没有任何论据来验证这种情况正在发生。
  • 考虑到这一点,我摆脱了一些图像和一些工作。我不断收到数据库警告,但以下测试运行良好。过去,以下测试会失败,因为 AR 无法为测试生成新连接:(

  • 我以为是 New Relic、Capybara、Capybara Webkit、AirBrake。我更新了那些。仍然收到警告。

  • 不知道还能做什么。

于 2013-06-14T23:19:25.227 回答