parallel_split_test 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parallel_split_test (0.1.1)
4
+ parallel_split_test (0.1.2)
5
5
  parallel (>= 0.5.12)
6
6
  rspec (>= 2)
7
7
 
data/Readme.md CHANGED
@@ -9,21 +9,30 @@ Or
9
9
 
10
10
  Usage
11
11
  =====
12
+
13
+ ### 1: prepare your databases
14
+ To use 1 database per test-process, add this to your `config/database.yml`<br/>
15
+
16
+ test:
17
+ database: yourproject_test<%= ENV['TEST_ENV_NUMBER'] %>
18
+
19
+
20
+ - `TEST_ENV_NUMBER` is '' for the first process and 2 for the 2nd, it reuses your normal test database
21
+ - Optionally install [parallel_tests](https://github.com/grosser/parallel_tests) to get database helper tasks like `rake parallel:prepare`
22
+
23
+
24
+ ### 2: find a slow/big test file
25
+
12
26
  # spec/xxx_spec.rb
13
27
  require "spec_helper"
14
28
 
15
29
  describe "X" do
16
30
  it {sleep 5}
17
- end
18
-
19
- describe "Y" do
20
31
  it {sleep 5}
21
- end
22
-
23
- describe "Z" do
24
32
  it {sleep 5}
25
33
  end
26
34
 
35
+ ### 3: run
27
36
  parallel_split_test spec/xxx_spec.rb [regular rspec options]
28
37
 
29
38
  Output
@@ -51,9 +60,9 @@ TIPS
51
60
  TODO
52
61
  ====
53
62
  - combine exit status (1 + 0 == 1)
54
- - support a single group with multiple sub-groups
55
- - Test::Unit support
63
+ - re-print summary of all test results
56
64
  - Cucumber support
65
+ - Test::Unit support
57
66
 
58
67
  Author
59
68
  ======
@@ -1,2 +1,10 @@
1
1
  module ParallelSplitTest
2
+ class << self
3
+ attr_accessor :example_counter, :process_count, :process_number
4
+ end
5
+
6
+ def self.run_example?
7
+ self.example_counter += 1
8
+ (example_counter - 1) % process_count == process_number
9
+ end
2
10
  end
@@ -1,5 +1,7 @@
1
+ require 'parallel_split_test'
1
2
  require 'parallel'
2
3
  require 'rspec/core/command_line'
4
+ require 'parallel_split_test/core_ext/rspec_example'
3
5
 
4
6
  module ParallelSplitTest
5
7
  class CommandLine < RSpec::Core::CommandLine
@@ -8,20 +10,24 @@ module ParallelSplitTest
8
10
  processes = (ENV['PARALLEL_SPLIT_TEST_PROCESSES'] || Parallel.processor_count).to_i
9
11
 
10
12
  Parallel.in_processes(processes) do |process_number|
13
+ ParallelSplitTest.example_counter = 0
14
+ ParallelSplitTest.process_count = processes
15
+ ParallelSplitTest.process_number = process_number
16
+
11
17
  ENV['TEST_ENV_NUMBER'] = (process_number == 0 ? '' : (process_number + 1).to_s)
12
- run_group_of_tests(processes, process_number)
18
+ run_group_of_tests(processes)
13
19
  end
14
20
  end
15
21
 
16
22
  private
17
23
 
18
- def run_group_of_tests(processes, process_number)
24
+ def run_group_of_tests(processes)
19
25
  example_count = @world.example_count / processes
20
26
 
21
27
  @configuration.reporter.report(example_count, seed) do |reporter|
22
28
  begin
23
29
  @configuration.run_hook(:before, :suite)
24
- groups = groups_for_this_process(@world.example_groups.ordered, process_number, processes)
30
+ groups = @world.example_groups.ordered
25
31
  groups.map {|g| g.run(reporter)}.all? ? 0 : @configuration.failure_exit_code
26
32
  ensure
27
33
  @configuration.run_hook(:after, :suite)
@@ -33,14 +39,6 @@ module ParallelSplitTest
33
39
  @configuration.randomize? ? @configuration.seed : nil
34
40
  end
35
41
 
36
- def groups_for_this_process(groups, number, count)
37
- selected = []
38
- groups.each_with_index do |group, i|
39
- selected << group if i % count == number
40
- end
41
- selected
42
- end
43
-
44
42
  def setup_copied_from_rspec(err, out)
45
43
  @configuration.error_stream = err
46
44
  @configuration.output_stream ||= out
@@ -0,0 +1,11 @@
1
+ require 'parallel_split_test'
2
+ require 'rspec/core/example'
3
+
4
+ RSpec::Core::Example.class_eval do
5
+ alias :run_without_parallel_split_test :run
6
+ def run(*args, &block)
7
+ if ParallelSplitTest.run_example?
8
+ run_without_parallel_split_test(*args, &block)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ParallelSplitTest
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -80,6 +80,7 @@ describe ParallelSplitTest do
80
80
  end
81
81
  RUBY
82
82
  result = parallel_split_test "xxx_spec.rb"
83
+ result.scan('1 example, 0 failures').size.should == 2
83
84
 
84
85
  processes = ["a","b"].map do |process|
85
86
  rex = /it-ran-#{process}-in-(\d)-/
@@ -103,6 +104,21 @@ describe ParallelSplitTest do
103
104
 
104
105
  time{ parallel_split_test "xxx_spec.rb" }.should < 2
105
106
  end
107
+
108
+ it "splits based on examples" do
109
+ write "xxx_spec.rb", <<-RUBY
110
+ describe "X" do
111
+ describe "Y" do
112
+ it { sleep 1 }
113
+ it { sleep 1 }
114
+ end
115
+ end
116
+ RUBY
117
+
118
+ result = nil
119
+ time{ result = parallel_split_test "xxx_spec.rb" }.should < 2
120
+ result.scan('1 example, 0 failures').size.should == 2
121
+ end
106
122
  end
107
123
  end
108
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_split_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &82916840 !ruby/object:Gem::Requirement
16
+ requirement: &83628200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *82916840
24
+ version_requirements: *83628200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: parallel
27
- requirement: &82916590 !ruby/object:Gem::Requirement
27
+ requirement: &83627950 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.5.12
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *82916590
35
+ version_requirements: *83627950
36
36
  description:
37
37
  email: michael@grosser.it
38
38
  executables:
@@ -48,6 +48,7 @@ files:
48
48
  - bin/parallel_split_test
49
49
  - lib/parallel_split_test.rb
50
50
  - lib/parallel_split_test/command_line.rb
51
+ - lib/parallel_split_test/core_ext/rspec_example.rb
51
52
  - lib/parallel_split_test/runner.rb
52
53
  - lib/parallel_split_test/version.rb
53
54
  - parallel_split_test.gemspec
@@ -68,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
69
  version: '0'
69
70
  segments:
70
71
  - 0
71
- hash: -1019850003
72
+ hash: 40026127
72
73
  required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  none: false
74
75
  requirements:
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  segments:
79
80
  - 0
80
- hash: -1019850003
81
+ hash: 40026127
81
82
  requirements: []
82
83
  rubyforge_project:
83
84
  rubygems_version: 1.8.10