parallelized_specs 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.email = "jake@instructure.com"
13
13
  gem.homepage = "http://github.com/jakesorce/#{gem.name}"
14
14
  gem.authors = "Jake Sorce, Bryan Madsen"
15
- gem.version = "0.1.7"
15
+ gem.version = "0.1.8"
16
16
  end
17
17
 
18
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -2,18 +2,15 @@ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..'))
2
2
  require "parallelized_specs"
3
3
 
4
4
  namespace :parallel do
5
- def run_db_in_parallel(cmd, options={})
6
- ParallelizedSpecs.execute_parallel_db(cmd, options)
7
- end
8
5
 
9
6
  desc "create test databases via db:create --> parallel:create[num_cpus]"
10
7
  task :create, :count do |t, args|
11
- run_db_in_parallel('rake db:create RAILS_ENV=test', args)
8
+ ParallelizedSpecs.execute_parallel_db('rake db:create RAILS_ENV=test', args)
12
9
  end
13
10
 
14
11
  desc "drop test databases via db:drop --> parallel:drop[num_cpus]"
15
12
  task :drop, :count do |t, args|
16
- run_db_in_parallel('rake db:drop RAILS_ENV=test', args)
13
+ ParallelizedSpecs.execute_parallel_db('rake db:drop RAILS_ENV=test', args)
17
14
  end
18
15
 
19
16
  desc "update test databases by dumping and loading --> parallel:prepare[num_cpus]"
@@ -25,27 +22,26 @@ namespace :parallel do
25
22
  else
26
23
  # there is no separate dump / load for schema_format :sql -> do it safe and slow
27
24
  args = args.to_hash.merge(:non_parallel => true) # normal merge returns nil
28
- run_db_in_parallel('rake db:test:prepare --trace', args)
25
+ ParallelizedSpecs.execute_parallel_db('rake db:test:prepare --trace', args)
29
26
  end
30
27
  end
31
28
 
32
29
  # when dumping/resetting takes too long
33
30
  desc "update test databases via db:migrate --> parallel:migrate[num_cpus]"
34
31
  task :migrate, :count do |t, args|
35
- run_db_in_parallel('rake db:migrate RAILS_ENV=test', args)
32
+ ParallelizedSpecs.execute_parallel_db('rake db:migrate RAILS_ENV=test', args)
36
33
  end
37
34
 
38
35
  # just load the schema (good for integration server <-> no development db)
39
36
  desc "load dumped schema for test databases via db:schema:load --> parallel:load_schema[num_cpus]"
40
37
  task :load_schema, :count do |t, args|
41
- run_db_in_parallel('rake db:test:load', args)
38
+ ParallelizedSpecs.execute_parallel_db('rake db:test:load', args)
42
39
  end
43
40
 
44
41
  desc "run spec in parallel with parallel:spec[num_cpus]"
45
42
  task 'spec', :count, :pattern, :options, :arguments do |t, args|
46
43
  count, pattern, options = ParallelizedSpecs.parse_rake_args(args)
47
- #command = "-n #{count} -p '#{pattern}' -r '#{Rails.root}' -o '#{options}' #{args[:arguments]}"
48
- opts = [:count => count, :pattern => pattern, :options => options, :root => Rails.root, :files => args[:arguments]]
44
+ opts = {:count => count, :pattern => pattern, :root => Rails.root, :files => args[:arguments]}
49
45
  ParallelizedSpecs.execute_parallel_specs(opts)
50
46
  end
51
47
  end
@@ -53,7 +53,7 @@ class ParallelizedSpecs
53
53
  end
54
54
 
55
55
  def self.execute_parallel_db(cmd, options={})
56
- count = options[:count].to_i
56
+ count = options[:count].to_i || Parallel.processor_count
57
57
  count = Parallel.processor_count if count == 0
58
58
  runs = (0...count).to_a
59
59
  results = if options[:non_parallel]
@@ -69,19 +69,26 @@ class ParallelizedSpecs
69
69
  end
70
70
 
71
71
  def self.execute_parallel_specs(options)
72
+ if options[:files].to_s.empty?
73
+ tests = find_tests(Rails.root, options)
74
+ run_specs(tests, options)
75
+ else
76
+ run_specs(options[:files], options)
77
+ end
78
+ end
79
+
80
+ def self.run_specs(tests, options)
72
81
  num_processes = options[:count] || Parallel.processor_count
73
- lib, name, task = {
74
- 'spec' => %w(specs spec spec),
75
- }[options[:type]||'spec']
82
+ name = 'spec'
76
83
 
77
84
  start = Time.now
78
85
 
79
- tests_folder = task
86
+ tests_folder = 'spec'
80
87
  tests_folder = File.join(options[:root], tests_folder) unless options[:root].to_s.empty?
81
- if options[:files].is_a?(Array)
82
- groups = tests_in_groups(options[:files] || tests_folder, num_processes, options)
88
+ if tests.is_a?(Array)
89
+ groups = tests_in_groups(tests || tests_folder, num_processes, options)
83
90
  else
84
- files_array = options[:files].split(/ /)
91
+ files_array = tests.split(/ /)
85
92
  groups = tests_in_groups(files_array || tests_folder, num_processes, options)
86
93
  end
87
94
  num_processes = groups.size
@@ -110,7 +117,7 @@ class ParallelizedSpecs
110
117
  abort "#{name.capitalize}s Failed" if failed
111
118
  end
112
119
 
113
- # parallel:spec[:count, :pattern, :options]
120
+ # parallel:spec[:count, :pattern, :options]
114
121
  def self.parse_rake_args(args)
115
122
  # order as given by user
116
123
  args = [args[:count], args[:pattern], args[:options]]
@@ -129,9 +136,8 @@ class ParallelizedSpecs
129
136
  [num_processes.to_i, pattern.to_s, options.to_s]
130
137
  end
131
138
 
132
- # finds all tests and partitions them into groups
133
- def self.tests_in_groups(root, num_groups, options)
134
- tests = find_tests(root, options)
139
+ # finds all tests and partitions them into groups
140
+ def self.tests_in_groups(tests, num_groups, options)
135
141
  if options[:no_sort]
136
142
  Grouper.in_groups(tests, num_groups)
137
143
  else
@@ -176,7 +182,7 @@ class ParallelizedSpecs
176
182
 
177
183
  protected
178
184
 
179
- # read output of the process and print in in chucks
185
+ # read output of the process and print in in chucks
180
186
  def self.fetch_output(process, options)
181
187
  all = ''
182
188
  buffer = ''
@@ -205,7 +211,7 @@ class ParallelizedSpecs
205
211
  all
206
212
  end
207
213
 
208
- # copied from http://github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile
214
+ # copied from http://github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile
209
215
  def self.bundler_enabled?
210
216
  return true if Object.const_defined?(:Bundler)
211
217
 
@@ -243,16 +249,17 @@ class ParallelizedSpecs
243
249
  end
244
250
  end
245
251
 
246
- def self.find_tests(root, options)
252
+ def self.find_tests(root, options={})
247
253
  if root.is_a?(Array)
248
254
  root
249
255
  else
250
256
  # follow one symlink and direct children
251
257
  # http://stackoverflow.com/questions/357754/can-i-traverse-symlinked-directories-in-ruby-with-a-glob
252
- files = Dir["#{Rails.root}/**{,/*/**}/*#{test_suffix}"].uniq
258
+ files = Dir["#{root}/**{,/*/**}/*#{test_suffix}"].uniq
253
259
  files = files.map { |f| f.sub(root+'/', '') }
254
- files = files.grep(/#{options['pattern']}/)
255
- files.map { |f| "#{root}/#{f}" }
260
+ files = files.grep(/#{options[:pattern]}/)
261
+ files.map { |f| "/#{f}" }
256
262
  end
257
263
  end
264
+
258
265
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "parallelized_specs"
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jake Sorce, Bryan Madsen"]
12
- s.date = "2012-05-02"
12
+ s.date = "2012-05-03"
13
13
  s.email = "jake@instructure.com"
14
14
  s.files = [
15
15
  "Gemfile",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallelized_specs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jake Sorce, Bryan Madsen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-02 00:00:00 Z
18
+ date: 2012-05-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: parallel