我在 Rails 应用程序(3.2.8)的测试中遇到了 JRuby 和垃圾收集的问题。当我运行我的单元测试时,我很好,但是当我同时运行单元和功能或只是功能时,它往往会出现如下奇怪的堆栈跟踪。
我不知道发生了什么。这只是在我升级 Rails 并将 JRuby 从 1.6.3 升级到 1.6.7.2 时才开始发生的。
/home/mbridges/.rbenv/versions/jruby-1.6.7.2/bin/jruby -I"lib:test" -I"/home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib" "/home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb"
* WARNING: 'test: #channel_id should return the correct channel id. ' is already defined
Loaded suite /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
...............................................................................
...............................................................................
...............................................................................
...............................................................................
...............................................................................
...............................................................................
...........................................................
Finished in 156.993 seconds.
533 tests, 1030 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
3.40 tests/s, 6.56 assertions/s
/home/mbridges/.rbenv/versions/jruby-1.6.7.2/bin/jruby -I"lib:test" -I"/home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib" "/home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/functional/**/*_test.rb"
LoadError: No such file to load -- java.lang.OutOfMemoryError: GC overhead limit exceeded
depend_on at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:317
depend_on at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:313
require_dependency at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:225
eager_load! at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:439
each at org/jruby/RubyArray.java:1615
eager_load! at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:438
each at org/jruby/RubyArray.java:1615
eager_load! at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/engine.rb:436
Finisher at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/application/finisher.rb:53
instance_exec at org/jruby/RubyBasicObject.java:1757
run at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:30
run_initializers at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:55
each at org/jruby/RubyArray.java:1615
run_initializers at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/initializable.rb:54
initialize! at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/application.rb:136
__send__ at org/jruby/RubyBasicObject.java:1698
send at org/jruby/RubyKernel.java:2097
method_missing at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30
(root) at /home/mbridges/admin_tools/mbridges_dev/customer_service_tool/config/environment.rb:12
require at org/jruby/RubyKernel.java:1042
(root) at /home/mbridges/admin_tools/mbridges_dev/customer_service_tool/config/environment.rb:2
require at org/jruby/RubyKernel.java:1042
(root) at /home/mbridges/admin_tools/mbridges_dev/customer_service_tool/test/test_helper.rb:1
require at org/jruby/RubyKernel.java:1042
__file__ at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10
each at org/jruby/RubyArray.java:1615
__file__ at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9
select at org/jruby/RubyArray.java:2395
(root) at /home/mbridges/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4
rake aborted!
Command failed with status (1): [/home/mbridges/.rbenv/versions/jruby-1.6.7...]
Tasks: TOP => without_schema_dump:functionals
(See full trace by running task with --trace)
Rakefile 有点不同,因为我们实际上并不控制数据库。我们必须跳过迁移。
# 在 lib/tasks 中以 .rake 结尾的文件中添加您自己的任务,# 例如 lib/tasks/capistrano.rake,它们将自动可供 Rake 使用。
require File.expand_path('../config/application', __FILE__)
require 'rake'
CustomerService::Application.load_tasks
namespace :without_schema_dump do
Rake::TestTask.new(:units) do |t|
t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb'
t.verbose = true
end
Rake::TestTask.new(:functionals) do |t|
t.libs << "test"
t.pattern = 'test/functional/**/*_test.rb'
t.verbose = true
end
task :run_tests => :environment do
Rake::Task['without_schema_dump:units'].invoke
Rake::Task['without_schema_dump:functionals'].invoke
end
end
Rake::Task[:default].prerequisites.clear
Rake::Task[:default].actions.clear
task :default do
puts 'WARNING: Default rake overwritten because of foreign key constraints (see Rakefile)'
Rake::Task['without_schema_dump:run_tests'].invoke
end
帮助?任何帮助,将不胜感激!