parallel_rspec 0.4.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 773680cd7ac7cc86421fc4511597b488293aa9b0
4
- data.tar.gz: 420dff9c171a05bf34e3013c8cb8c0aed377bf0e
2
+ SHA256:
3
+ metadata.gz: 2d143dce3b81dac87bf01778c952ad87821de77b440e11fc5d24e270a932331e
4
+ data.tar.gz: f1ca46d4effc92cd59613f44dc4bf55015a3b8c70a025211dbd5a19421337730
5
5
  SHA512:
6
- metadata.gz: 5b347907242eed08bc9edef8f2d59f221519d74d9f30ff6fa8fdb81edac1c7cdfc1df2b1c38566a20aa6a137618909a5a6c539d6f7c5d9ff6dcb92760c8815be
7
- data.tar.gz: cbe1cf67c4deab173e1668dae741f555d8b930872a558f08d6d3d71925d06d0c4c38f2f1d5266f2d8cc8a0af8e02c05ba10f0768e39fa493cbf81e1a604f57df
6
+ metadata.gz: d72eae09b94e9d243f99ffd7c7d3ff8f97e2c77a6905cba37a738d66002ba298ff86990cb6069cbb323a9758b2bbd5b3c4ab09db8ee42a1dbd2d0a3b76243242
7
+ data.tar.gz: 486f0adb28955ae1f5f2c972ac26b0748d2691a9205b9c82a1c7b686a88c0a59deddfd9c85b5be92a98bd45ed9fe2ef616a80ea971143d86f0170bfdec97cc0b
data/README.md CHANGED
@@ -24,7 +24,7 @@ And then execute:
24
24
 
25
25
  $ bundle
26
26
 
27
- This version of ParallelRSpec has been tested with RSpec 3.3.
27
+ This version of ParallelRSpec has been tested with RSpec 3.10.
28
28
 
29
29
  ## Usage
30
30
 
@@ -34,7 +34,7 @@ By default, ParallelRSpec will use two workers. If you would like to use more,
34
34
 
35
35
  ParallelRSpec runs each worker with its own copy of the test database to avoid locking and deadlocking problems. To create these and populate them with your schema, run:
36
36
 
37
- $ bundle exec db:parallel:create db:parallel:prepare
37
+ $ bundle exec rake db:parallel:create db:parallel:prepare
38
38
 
39
39
  ParallelRSpec will automatically make the database name for each worker based on the name you used for the `test` environment in `config/database.yml`. For example, if your normal `test` database is `foo_test`, worker 1 will keep using `foo_test` but worker 2's database will be `foo_test2`.
40
40
 
@@ -53,11 +53,46 @@ You may like to make an alias:
53
53
 
54
54
  When you change WORKERS, don't forget to restart Spring and re-run the create and populate steps above if necessary.
55
55
 
56
+ By default, there's a task called `parallel_rspec` which will run all specs. To make a custom rake task which uses parallel_rspec with different options, inherit from ParallelRSpec::RakeTask, for example:
57
+
58
+ ```ruby
59
+ require 'parallel_rspec'
60
+
61
+ ParallelRSpec::RakeTask.new(:prspec) do |t|
62
+ ENV['WORKERS'] = '4'
63
+ t.pattern = "spec/**/*_spec.rb"
64
+ t.rspec_opts = "--tag parallel"
65
+ # etc...
66
+ end
67
+ ```
68
+
69
+ If you'd like code to run after parallel_rspec has created each worker, you can specify a block to run:
70
+
71
+ ```ruby
72
+ ParallelRSpec.configure do |config|
73
+ config.after_fork do |worker_number|
74
+ puts "I am worker #{worker_number}"
75
+ end
76
+ end
77
+ ```
78
+
79
+ You might also want to detect whether your spec suite is running under ParallelRSpec or not:
80
+
81
+ ```ruby
82
+ do_something unless ParallelRSpec.running?
83
+ ```
84
+
56
85
  ## Contributing
57
86
 
58
87
  Bug reports and pull requests are welcome on GitHub at https://github.com/willbryant/parallel_rspec.
59
88
 
60
89
 
90
+ ## Thanks
91
+
92
+ * Charles Horn (@hornc)
93
+ * Roger Nesbitt (@mogest)
94
+
95
+
61
96
  ## License
62
97
 
63
98
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -26,6 +26,10 @@ module ParallelRSpec
26
26
  channel_to_server.write([:example_failed, serialize_example(example)])
27
27
  end
28
28
 
29
+ def example_finished(example)
30
+ channel_to_server.write([:example_finished, serialize_example(example)])
31
+ end
32
+
29
33
  def example_pending(example)
30
34
  channel_to_server.write([:example_pending, serialize_example(example)])
31
35
  end
@@ -40,6 +44,7 @@ module ParallelRSpec
40
44
  example.description,
41
45
  example.exception,
42
46
  example.location_rerun_argument,
47
+ ExampleGroup.new([]),
43
48
  example.metadata.slice(
44
49
  :absolute_file_path,
45
50
  :described_class,
@@ -0,0 +1,13 @@
1
+ module ParallelRSpec
2
+ module Config
3
+ @after_fork = []
4
+
5
+ def self.after_fork(&block)
6
+ if block
7
+ @after_fork << block
8
+ else
9
+ @after_fork
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,9 @@
1
1
  module ParallelRSpec
2
+ ExampleGroup = Struct.new(:parent_groups)
3
+
2
4
  # only the good bits of RSpec's Example class, those needed by the reporters and formatters and
3
5
  # marshallable.
4
- Example = Struct.new(:id, :description, :exception, :location_rerun_argument, :metadata) do
6
+ Example = Struct.new(:id, :description, :exception, :location_rerun_argument, :example_group, :metadata) do
5
7
  def self.delegate_to_metadata(key)
6
8
  define_method(key) { metadata[key] }
7
9
  end
@@ -13,4 +15,4 @@ module ParallelRSpec
13
15
  delegate_to_metadata :pending
14
16
  delegate_to_metadata :skip
15
17
  end
16
- end
18
+ end
@@ -1,11 +1,14 @@
1
- require 'rails'
1
+ begin
2
+ require 'rails'
2
3
 
3
- module ParallelRSpec
4
- class Railtie < Rails::Railtie
5
- railtie_name :parallel_rspec
4
+ module ParallelRSpec
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :parallel_rspec
6
7
 
7
- rake_tasks do
8
- load "parallel_rspec/tasks.rake"
8
+ rake_tasks do
9
+ load "parallel_rspec/tasks.rake"
10
+ end
9
11
  end
10
12
  end
13
+ rescue LoadError
11
14
  end
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ module ParallelRSpec
4
+ class RakeTask < RSpec::Core::RakeTask
5
+ def initialize(*args, &task_block)
6
+ super
7
+ self.rspec_path = File.expand_path('../../../exe/prspec', __FILE__)
8
+ end
9
+ end
10
+ end
@@ -16,6 +16,12 @@ end
16
16
 
17
17
  module ParallelRSpec
18
18
  class Runner < RSpec::Core::Runner
19
+ @@running = false
20
+
21
+ def self.running?
22
+ @@running
23
+ end
24
+
19
25
  # Runs the suite of specs and exits the process with an appropriate exit
20
26
  # code.
21
27
  def self.invoke
@@ -39,6 +45,7 @@ module ParallelRSpec
39
45
  # or the configured failure exit code (1 by default) if specs
40
46
  # failed.
41
47
  def self.run(args, err=$stderr, out=$stdout)
48
+ @@running = true
42
49
  RSpec::Core::Runner.trap_interrupt
43
50
  options = RSpec::Core::ConfigurationOptions.new(args)
44
51
  new(options).run(err, out)
@@ -22,6 +22,10 @@ module ParallelRSpec
22
22
  reporter.example_failed(example)
23
23
  end
24
24
 
25
+ def example_finished(example, channel_to_client)
26
+ reporter.example_finished(example)
27
+ end
28
+
25
29
  def example_pending(example, channel_to_client)
26
30
  reporter.example_pending(example)
27
31
  end
@@ -2,27 +2,31 @@ require 'parallel_rspec/workers.rb'
2
2
 
3
3
  db_namespace = namespace :db do
4
4
  namespace :parallel do
5
- # desc "Creates the test database"
5
+ desc "Creates the test databases"
6
6
  task :create => [:load_config] do
7
7
  ParallelRSpec::Workers.new.run_test_workers do |worker|
8
8
  ActiveRecord::Tasks::DatabaseTasks.create ActiveRecord::Base.configurations['test']
9
9
  end
10
10
  end
11
11
 
12
- # desc "Empty the test database"
12
+ desc "Empty the test databases"
13
13
  task :purge => %w(environment load_config) do
14
14
  ParallelRSpec::Workers.new.run_test_workers do |worker|
15
15
  ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations['test']
16
16
  end
17
17
  end
18
18
 
19
- # desc "Recreate the test database from an existent schema.rb file"
19
+ desc "Recreate the test databases from an existent schema.rb file"
20
20
  task :load_schema => %w(db:parallel:purge) do
21
21
  should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
22
22
  begin
23
23
  ParallelRSpec::Workers.new.run_test_workers do |worker|
24
24
  ActiveRecord::Schema.verbose = false
25
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
25
+ if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:load_schema_current)
26
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_current :ruby, ENV['SCHEMA'], 'test'
27
+ else
28
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
29
+ end
26
30
  end
27
31
  ensure
28
32
  if should_reconnect
@@ -31,25 +35,29 @@ db_namespace = namespace :db do
31
35
  end
32
36
  end
33
37
 
34
- # desc "Recreate the test database from an existent structure.sql file"
38
+ desc "Recreate the test databases from an existent structure.sql file"
35
39
  task :load_structure => %w(db:parallel:purge) do
36
40
  ParallelRSpec::Workers.new.run_test_workers do |worker|
37
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
41
+ if ActiveRecord::Tasks::DatabaseTasks.respond_to?(:load_schema_current)
42
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_current :sql, ENV['SCHEMA'], 'test'
43
+ else
44
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
45
+ end
38
46
  end
39
47
  end
40
48
 
41
- # desc "Recreate the test database from the current schema"
49
+ desc "Recreate the test databases from the current schema"
42
50
  task :load do
43
- db_namespace["db:parallel:purge"].invoke
51
+ db_namespace["parallel:purge"].invoke
44
52
  case ActiveRecord::Base.schema_format
45
- when :ruby
46
- db_namespace["parallel:load_schema"].invoke
47
- when :sql
48
- db_namespace["parallel:load_structure"].invoke
53
+ when :ruby
54
+ db_namespace["parallel:load_schema"].invoke
55
+ when :sql
56
+ db_namespace["parallel:load_structure"].invoke
49
57
  end
50
58
  end
51
59
 
52
- # desc "Check for pending migrations and load the test schema"
60
+ desc "Check for pending migrations and load the test schema"
53
61
  task :prepare => %w(environment load_config) do
54
62
  unless ActiveRecord::Base.configurations.blank?
55
63
  db_namespace['parallel:load'].invoke
@@ -57,3 +65,7 @@ db_namespace = namespace :db do
57
65
  end
58
66
  end
59
67
  end
68
+
69
+ ParallelRSpec::RakeTask.new(:parallel_rspec) do |t|
70
+ t.pattern = "spec/**/*_spec.rb"
71
+ end
@@ -1,3 +1,3 @@
1
1
  module ParallelRSpec
2
- VERSION = "0.4.1"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -30,6 +30,11 @@ module ParallelRSpec
30
30
  pid = fork do
31
31
  channel_to_client.close
32
32
  establish_test_database_connection(worker)
33
+
34
+ Config.after_fork.each do |proc|
35
+ proc.call(worker)
36
+ end
37
+
33
38
  yield worker, channel_to_server
34
39
  end
35
40
 
@@ -56,8 +61,18 @@ module ParallelRSpec
56
61
 
57
62
  def establish_test_database_connection(worker)
58
63
  ENV['TEST_ENV_NUMBER'] = worker.to_s
59
- ActiveRecord::Base.configurations['test']['database'] << worker.to_s unless worker == 1
60
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
64
+ if defined?(ActiveRecord)
65
+ if ActiveRecord::Base.configurations.respond_to?(:configs_for)
66
+ ActiveRecord::Base.configurations.configs_for(env_name: 'test').each do |configuration|
67
+ configuration.database << worker.to_s unless worker == 1
68
+ ActiveRecord::Base.establish_connection(configuration)
69
+ end
70
+ else
71
+ configuration = ActiveRecord::Base.configurations['test']
72
+ configuration.with_indifferent_access['database'] << worker.to_s unless worker == 1
73
+ ActiveRecord::Base.establish_connection(configuration)
74
+ end
75
+ end
61
76
  end
62
77
 
63
78
  def verify_children(child_pids)
@@ -1,8 +1,20 @@
1
1
  require "parallel_rspec/version"
2
+ require "parallel_rspec/config"
2
3
  require "parallel_rspec/channel"
3
4
  require "parallel_rspec/workers"
4
5
  require "parallel_rspec/example"
5
6
  require "parallel_rspec/server"
6
7
  require "parallel_rspec/client"
8
+ require "parallel_rspec/rake_task"
7
9
  require "parallel_rspec/runner"
8
10
  require "parallel_rspec/railtie"
11
+
12
+ module ParallelRSpec
13
+ def self.configure
14
+ yield Config
15
+ end
16
+
17
+ def self.running?
18
+ Runner.running?
19
+ end
20
+ end
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_dependency "rake", "> 10.0"
23
+ spec.add_dependency "rspec"
24
24
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Bryant, Powershop New Zealand Ltd
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-27 00:00:00.000000000 Z
11
+ date: 2022-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
20
- type: :development
19
+ version: '10.0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '10.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
33
+ version: '0'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  description: This gem lets you run your RSpec examples in parallel across across your
42
42
  CPUs. Each worker automatically gets its own database to avoid conflicts. The
43
43
  optional spring-prspec gem adds support for running under Spring.
@@ -58,8 +58,10 @@ files:
58
58
  - lib/parallel_rspec.rb
59
59
  - lib/parallel_rspec/channel.rb
60
60
  - lib/parallel_rspec/client.rb
61
+ - lib/parallel_rspec/config.rb
61
62
  - lib/parallel_rspec/example.rb
62
63
  - lib/parallel_rspec/railtie.rb
64
+ - lib/parallel_rspec/rake_task.rb
63
65
  - lib/parallel_rspec/runner.rb
64
66
  - lib/parallel_rspec/server.rb
65
67
  - lib/parallel_rspec/tasks.rake
@@ -70,7 +72,7 @@ homepage: https://github.com/willbryant/parallel_rspec
70
72
  licenses:
71
73
  - MIT
72
74
  metadata: {}
73
- post_install_message:
75
+ post_install_message:
74
76
  rdoc_options: []
75
77
  require_paths:
76
78
  - lib
@@ -85,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  - !ruby/object:Gem::Version
86
88
  version: '0'
87
89
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.2.2
90
- signing_key:
90
+ rubygems_version: 3.0.3
91
+ signing_key:
91
92
  specification_version: 4
92
93
  summary: This gem lets you run your RSpec examples in parallel across across your
93
94
  CPUs.