parallel_rspec 0.4.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +37 -2
- data/lib/parallel_rspec/client.rb +5 -0
- data/lib/parallel_rspec/config.rb +13 -0
- data/lib/parallel_rspec/example.rb +4 -2
- data/lib/parallel_rspec/railtie.rb +9 -6
- data/lib/parallel_rspec/rake_task.rb +10 -0
- data/lib/parallel_rspec/runner.rb +7 -0
- data/lib/parallel_rspec/server.rb +4 -0
- data/lib/parallel_rspec/tasks.rake +25 -13
- data/lib/parallel_rspec/version.rb +1 -1
- data/lib/parallel_rspec/workers.rb +17 -2
- data/lib/parallel_rspec.rb +12 -0
- data/parallel_rspec.gemspec +2 -2
- metadata +20 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2d143dce3b81dac87bf01778c952ad87821de77b440e11fc5d24e270a932331e
|
|
4
|
+
data.tar.gz: f1ca46d4effc92cd59613f44dc4bf55015a3b8c70a025211dbd5a19421337730
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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,
|
|
@@ -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
|
-
|
|
1
|
+
begin
|
|
2
|
+
require 'rails'
|
|
2
3
|
|
|
3
|
-
module ParallelRSpec
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
module ParallelRSpec
|
|
5
|
+
class Railtie < Rails::Railtie
|
|
6
|
+
railtie_name :parallel_rspec
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
rake_tasks do
|
|
9
|
+
load "parallel_rspec/tasks.rake"
|
|
10
|
+
end
|
|
9
11
|
end
|
|
10
12
|
end
|
|
13
|
+
rescue LoadError
|
|
11
14
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
49
|
+
desc "Recreate the test databases from the current schema"
|
|
42
50
|
task :load do
|
|
43
|
-
db_namespace["
|
|
51
|
+
db_namespace["parallel:purge"].invoke
|
|
44
52
|
case ActiveRecord::Base.schema_format
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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
|
|
60
|
-
|
|
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)
|
data/lib/parallel_rspec.rb
CHANGED
|
@@ -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
|
data/parallel_rspec.gemspec
CHANGED
|
@@ -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.
|
|
23
|
-
spec.
|
|
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:
|
|
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:
|
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: rake
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
type: :
|
|
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: '
|
|
26
|
+
version: '10.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: rspec
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
34
|
-
type: :
|
|
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: '
|
|
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
|
-
|
|
89
|
-
|
|
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.
|