Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

barfing when threadsafe! is enabled #102

Closed
blahed opened this Issue · 3 comments

2 participants

@blahed

Problems when config.threadsafe! is enabled. I created an empty rails app to to test it and it is reproducible with the following:

Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.11'
gem 'jquery-rails'
gem 'sqlite3'

group :development, :test do
  gem 'minitest-rails', '~> 0.5.2'
end

application.rb

require File.expand_path('../boot', __FILE__)

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require "minitest/rails/railtie"

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module ExampleApp
  class Application < Rails::Application
    config.generators do |g|
      g.test_framework :mini_test, spec: true, fixture: false
    end

    config.encoding = "utf-8"
    config.assets.enabled = true
    config.assets.version = '1.0'

    config.threadsafe!
  end
end

minitest_helper.rb

ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)

require 'minitest/autorun'
require 'minitest/rails'
require 'minitest/pride'

Error

/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/minitest-rails-0.5.2/lib/minitest/rails.rb:34:in `<class:TestCase>': undefined method `register_spec_type' for ActionController::TestCase:Class (NoMethodError)
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/minitest-rails-0.5.2/lib/minitest/rails.rb:32:in `<top (required)>'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
    from /private/tmp/minitest-threadsafe/test/minitest_helper.rb:5:in `<top (required)>'
    from /private/tmp/minitest-threadsafe/test/models/user_test.rb:1:in `require'
    from /private/tmp/minitest-threadsafe/test/models/user_test.rb:1:in `<top (required)>'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib:test" -I"/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib" "/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "test/models/**/*_test.rb" ]
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/testtask.rb:104:in `block (3 levels) in define'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:82:in `ruby'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/testtask.rb:100:in `block (2 levels) in define'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:61:in `verbose'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/testtask.rb:98:in `block in define'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/blahed/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/blahed/.rbenv/versions/1.9.3-p374/bin/rake:23:in `load'
/Users/blahed/.rbenv/versions/1.9.3-p374/bin/rake:23:in `<main>'
@blowmage blowmage was assigned
@blowmage
Owner

This is due to some deep voodoo within Rails 3 and threadsafe!. Currently minitest-rails injects itself into rails during load, and replaces the ActiveSupport::TestCase constant with one that inherits from MiniTest. But for some reason when threadsafe! is called the testing classes get loaded differently and replacing the AS::TC constant no longer works. I couldn't figure out where the different load happens.

Basically, minitest-rails works by being a giant hack and threadsafe! complicates the hack. But the good news is we'll be able to use a much less hacky approach very soon. And this new approach should solve the theadsafe! issue.

@blahed

Right now I'm just disabling threadsafe in test and it seems to be working out. This is the first project that I've actually "needed" threadsafe enabled.

@blowmage
Owner

This should be resolved as of the 0.9.0 release. Please let me know if this is not the case.

@blowmage blowmage closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.