Skip to content
Browse files

No need to create N new databases now. Just install and it's ready to…

… roll
  • Loading branch information...
1 parent cc9625a commit 7ad92905a41527a073625f582fd4a17cf0010129 @lifo committed Sep 21, 2009
Showing with 45 additions and 31 deletions.
  1. +25 −24 README
  2. +20 −7 lib/tickle.rb
View
49 README
@@ -10,30 +10,6 @@ To install :
$ script/plugin install git://github.com/lifo/tickle.git
-Database Setup :
-
-You'll need to create 'N' new databases. Where 'N' is the maximum number of parallel processes you want to run.
-
-Assuming you want to run 2 proccesses, you'll need to provide test_1 and test_2 config settings in database.yml :
-
-test_1:
- adapter: mysql
- encoding: utf8
- database: myapp_test1
- pool: 5
- username: root
- password:
- socket: /tmp/mysql.sock
-
-test_2:
- adapter: mysql
- encoding: utf8
- database: myapp_test2
- pool: 5
- username: root
- password:
- socket: /tmp/mysql.sock
-
Example
=======
@@ -63,4 +39,29 @@ For best results, use tickle with Ruby Enterprise Edition and Twitter's GC setti
- http://www.rubyenterpriseedition.com/
- http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-tuning/
+Database Setup
+==============
+
+If you're NOT USING transactional fixtures, you'll need to create 'N' new databases. Where 'N' is the maximum number of parallel processes you want to run.
+
+Assuming you want to run 2 proccesses, you'll need to provide test_1 and test_2 config settings in database.yml :
+
+test_1:
+ adapter: mysql
+ encoding: utf8
+ database: myapp_test1
+ pool: 5
+ username: root
+ password:
+ socket: /tmp/mysql.sock
+
+test_2:
+ adapter: mysql
+ encoding: utf8
+ database: myapp_test2
+ pool: 5
+ username: root
+ password:
+ socket: /tmp/mysql.sock
+
Copyright (c) 2009 Pratik Naik, released under the MIT license
View
27 lib/tickle.rb
@@ -18,18 +18,31 @@ def run_tests(dir, n = 2)
dir = "#{Rails.root}/test/#{dir}/**/*_test.rb" unless dir.index(Rails.root)
groups = Dir[dir].sort.in_groups(n, false)
+ pids = fork_tests(groups)
+
+ Signal.trap 'SIGINT', lambda { pids.each {|p| Process.kill("KILL", p)}; exit 1 }
+ Process.waitall
+ end
+
+ def fork_tests(groups)
pids = []
- n.times do |i|
+
+ unless config['test_1']
+ prepare_databse(:test)
+ prepared = true
+ end
+
+ GC.start
+
+ groups.each_with_index do |group, i|
pids << Process.fork do
- prepare_databse(:"test_#{i+1}")
- groups[i].each {|f| load(f) unless f =~ /^-/ }
+ # If already prepared, reconnect. Else prepare.
+ prepared ? ActiveRecord::Base.establish_connection : prepare_databse(:"test_#{i+1}")
+ group.each {|f| load(f) unless f =~ /^-/ }
end
end
- Signal.trap 'SIGINT', lambda { pids.each {|p| Process.kill("KILL", p)}; exit 1 }
-
- # Wait...
- Process.waitall
+ pids
end
def prepare_databse(db)

0 comments on commit 7ad9290

Please sign in to comment.
Something went wrong with that request. Please try again.