added activerecord concurrency to safe_fork

This commit is contained in:
Nick Gauthier 2010-04-19 10:27:44 -04:00
parent baa666610e
commit a6847107ad
2 changed files with 12 additions and 12 deletions

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Nick Gauthier"]
s.date = %q{2010-04-11}
s.date = %q{2010-04-19}
s.description = %q{Spread your tests over multiple machines to test your code faster.}
s.email = %q{nick@smartlogicsolutions.com}
s.extra_rdoc_files = [
@ -79,18 +79,18 @@ Gem::Specification.new do |s|
s.summary = %q{Distributed testing toolkit}
s.test_files = [
"test/pipe_test.rb",
"test/test_helper.rb",
"test/ssh_test.rb",
"test/message_test.rb",
"test/master_test.rb",
"test/fixtures/write_file.rb",
"test/fixtures/slow.rb",
"test/fixtures/write_file_spec.rb",
"test/fixtures/features/step_definitions.rb",
"test/fixtures/hello_world.rb",
"test/fixtures/write_file_alternate_spec.rb",
"test/fixtures/sync_test.rb",
"test/fixtures/hello_world.rb",
"test/fixtures/features/step_definitions.rb",
"test/fixtures/assert_true.rb",
"test/fixtures/slow.rb",
"test/fixtures/write_file_spec.rb",
"test/fixtures/write_file.rb",
"test/message_test.rb",
"test/test_helper.rb",
"test/master_test.rb",
"test/runner_test.rb",
"test/worker_test.rb"
]

View File

@ -2,13 +2,13 @@ class SafeFork
def self.fork
begin
# remove our connection so it doesn't get cloned
ActiveRecord::Base.remove_connection if defined?(ActiveRecord)
connection = ActiveRecord::Base.remove_connection if defined?(ActiveRecord)
# fork a process
child = Process.fork do
begin
# create a new connection and perform the action
begin
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
ActiveRecord::Base.establish_connection(connection.merge({:allow_concurrency => true})) if defined?(ActiveRecord)
rescue ActiveRecord::AdapterNotSpecified
# AR was defined but we didn't have a connection
end
@ -21,7 +21,7 @@ class SafeFork
ensure
# make sure we re-establish the connection before returning to the main instance
begin
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
ActiveRecord::Base.establish_connection(connection.merge({:allow_concurrency => true})) if defined?(ActiveRecord)
rescue ActiveRecord::AdapterNotSpecified
# AR was defined but we didn't have a connection
end