Permalink
Browse files

Initial commit

  • Loading branch information...
lifo committed Jul 15, 2009
0 parents commit 4c6a02b467ef1c534600dc3846c41de7e3b680db
Showing with 152 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +58 −0 README
  3. +44 −0 lib/tickle.rb
  4. +30 −0 tasks/tickle_tasks.rake
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Pratik Naik
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
58 README
@@ -0,0 +1,58 @@
+Tickle
+======
+
+Thanks to http://github.com/jasonm/parallel_test for the concept.
+
+Setup
+=====
+
+To install :
+
+ $ script/plugin install http://github.com/lifo/tickle
+
+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_test1
+ pool: 5
+ username: root
+ password:
+ socket: /tmp/mysql.sock
+
+Example
+=======
+
+To run all tests :
+
+ $ rake tickle # This will use 2 processes by default
+
+To run all tests using 3 processes :
+
+ $ rake tickle[3]
+
+To only run unit tests :
+
+ $ rake tickle:units
+
+To run unit tests in 4 parallel processes :
+
+ $ rake tickle:units[4]
+
+tickle:functionals and tickle:integration should work as expected.
+
+Copyright (c) 2009 Pratik Naik, released under the MIT license
@@ -0,0 +1,44 @@
+module Tickle
+ extend self
+
+ def load_environment
+ return if @loaded
+ puts "Loading Rails.."
+ ENV["RAILS_ENV"] = "test"
+ Object.const_set :RAILS_ENV, "test"
+
+ require(File.join(RAILS_ROOT, 'config', 'environment'))
+ $: << "#{Rails.root}/test"
+ require "#{Rails.root}/test/test_helper"
+
+ @loaded = true
+ end
+
+ 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 = []
+ n.times do |i|
+ pids << Process.fork do
+ prepare_databse(:"test_#{i+1}")
+ groups[i].each {|f| load(f) unless f =~ /^-/ }
+ end
+ end
+
+ Signal.trap 'SIGINT', lambda { pids.each {|p| Process.kill("KILL", p)}; exit 1 }
+
+ # Wait...
+ Process.waitall
+ end
+
+ def prepare_databse(db)
+ ActiveRecord::Base.establish_connection(db)
+ conf = ActiveRecord::Base.configurations
+ ActiveRecord::Base.connection.recreate_database(conf[db.to_s]["database"], conf[db.to_s])
+ ActiveRecord::Base.establish_connection(conf[db.to_s])
+ ActiveRecord::Schema.verbose = false
+ file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
+ load(file)
+ end
+end
@@ -0,0 +1,30 @@
+require File.join(File.dirname(__FILE__), "../lib/tickle")
+
+# Yanked from Rails
+desc 'Run all unit, functional and integration tests'
+task :tickle, :count do |t, args|
+ errors = %w(tickle:units tickle:functionals tickle:integration).collect do |task|
+ begin
+ Rake::Task[task].invoke(args[:count])
+ nil
+ rescue => e
+ task
+ end
+ end.compact
+ abort "Errors running #{errors.to_sentence}!" if errors.any?
+end
+
+namespace :tickle do
+ [:units, :functionals, :integration].each do |t|
+ type = t.to_s.sub(/s$/, '')
+
+ desc "Run #{type} tests"
+ task t, :count do |t, args|
+ Tickle.load_environment
+
+ size = args[:count] ? args[:count].to_i : 2
+ puts "Running #{type} tests using #{size} processes"
+ Tickle.run_tests type, 2
+ end
+ end
+end

0 comments on commit 4c6a02b

Please sign in to comment.