Skip to content

Run actionview tests in parallel #36422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions actionview/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def stderr_logger
end

class ActiveSupport::TestCase
parallelize

include ActiveSupport::Testing::MethodCallAssertions

private
Expand Down
10 changes: 10 additions & 0 deletions actionview/test/active_record_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def setup
self.able_to_connect = false
end

def reconnect
return unless able_to_connect
ActiveRecord::Base.connection.reconnect!
load_schema
end

private
def setup_connection
if Object.const_defined?(:ActiveRecord)
Expand Down Expand Up @@ -102,3 +108,7 @@ def run(*args)
end

ActiveRecordTestConnector.setup

ActiveSupport::Testing::Parallelization.after_fork_hook do
ActiveRecordTestConnector.reconnect
end
40 changes: 1 addition & 39 deletions actionview/test/template/compiled_templates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,46 +60,8 @@ def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
assert_equal "two", render(template: "test/render_file_with_locals_and_default", locals: { secret: "two" })
end

def test_template_changes_are_not_reflected_with_cached_templates
assert_equal "Hello world!", render(template: "test/hello_world")
modify_template "test/hello_world.erb", "Goodbye world!" do
assert_equal "Hello world!", render(template: "test/hello_world")
end
assert_equal "Hello world!", render(template: "test/hello_world")
end

def test_template_changes_are_reflected_with_uncached_templates
assert_equal "Hello world!", render_without_cache(template: "test/hello_world")
modify_template "test/hello_world.erb", "Goodbye world!" do
assert_equal "Goodbye world!", render_without_cache(template: "test/hello_world")
end
assert_equal "Hello world!", render_without_cache(template: "test/hello_world")
end

private
def render(*args)
render_with_cache(*args)
end

def render_with_cache(*args)
view_paths = ActionController::Base.view_paths
view_class.with_view_paths(view_paths, {}).render(*args)
end

def render_without_cache(*args)
path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
view_paths = ActionView::PathSet.new([path])
view_class.with_view_paths(view_paths, {}).render(*args)
end

def modify_template(template, content)
filename = "#{FIXTURE_LOAD_PATH}/#{template}"
old_content = File.read(filename)
begin
File.open(filename, "wb+") { |f| f.write(content) }
yield
ensure
File.open(filename, "wb+") { |f| f.write(old_content) }
end
ActionController::Base.render(*args)
end
end