turbo_tests 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90e474a8156b2c560bca5ee96efb75dd9d124a97e7a088bcc8b92223f0dd7580
4
+ data.tar.gz: 73a47005dbc152492b6ef7e7f4d3c80cfdd958d755f998db453bc1f2cf7f48a8
5
+ SHA512:
6
+ metadata.gz: 9956bf53df8328cff65ef313397f358607ea359d23d086a07389c9fdc673169919220273cfcf77df267f72d45774524ded5318720fd23c59962fcb62d7eb0c68
7
+ data.tar.gz: dcacad7897a69b0701993256fa2185454639c91c71810938e9cab574d0d1e601dacb74fe46b68930ddeaf8deba7a40fbc1a95b95b1fff055cffc894a191bf9e8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at zaoooza92@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in turbo_tests.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ turbo_tests (0.1.0)
5
+ optparse
6
+ parallel_tests
7
+ rspec
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ coderay (1.1.3)
13
+ diff-lcs (1.4.4)
14
+ method_source (1.0.0)
15
+ optparse (0.1.0)
16
+ parallel (1.19.2)
17
+ parallel_tests (3.3.0)
18
+ parallel
19
+ pry (0.13.1)
20
+ coderay (~> 1.1)
21
+ method_source (~> 1.0)
22
+ rake (12.3.3)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.3)
28
+ rspec-support (~> 3.9.3)
29
+ rspec-expectations (3.9.3)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.4)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ pry
42
+ rake (~> 12.0)
43
+ turbo_tests!
44
+
45
+ BUNDLED WITH
46
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Ilya Zub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # TurboTests
2
+
3
+ Runner for [`grosser/parallel_tests`](https://github.com/grosser/parallel_tests) with incremental summarized output. Based on [Discourse](https://github.com/discourse/discourse/blob/6b9784cf8a18636bce281a7e4d18e65a0cbc6290/lib/turbo_tests.rb) and [RubyGems](https://github.com/rubygems/rubygems/tree/390335ceb351668cd433bd5bb9823dd021f82533/bundler/tool) work in this area.
4
+
5
+ This feature [doesn't fit vision of `parallel_tests` author](https://github.com/grosser/parallel_tests/issues/708) and [RSpec doesn't support built-in parallel testing yet](https://github.com/rspec/rspec-rails/issues/2104#issuecomment-658474900). This gem would not be useful once one of the issues above will be implemented.
6
+
7
+ ## Why incremental output?
8
+
9
+ `parallel_tests` is great, but it messes output:
10
+
11
+ ```bash
12
+
13
+ $ bundle exec rake parallel_tests:spec[^spec/search]
14
+ ...........................................................................................................................................................................................
15
+ ...........................................................................................................................................................................................
16
+ ...........................................................................................................................................................................................
17
+
18
+ Finished in 1 minute 6.92 seconds (files took 6.95 seconds to load)
19
+ 2616 examples, 0 failures
20
+
21
+ .........................................................................................................................................F.................................................
22
+ .......................................................................................F...................................................................................................
23
+ ...........................................................................................................................................................................................
24
+
25
+ Finished in 1 minute 35.05 seconds (files took 6.26 seconds to load)
26
+ 2158 examples, 2 failures
27
+
28
+ ...........................................................................................................................................................................................
29
+ ...........................................................................................................................................................................................
30
+ ...........................................................................................................................................................................................
31
+
32
+ Finished in 1 minute 35.05 seconds (files took 6.26 seconds to load)
33
+ 2158 examples, 0 failures
34
+ ```
35
+
36
+ `turbo_tests` output looks like regular `rspec`:
37
+
38
+ ```bash
39
+ $ bundle exec turbo_spec
40
+ ...........................................................................................................................................................................................
41
+ ...........................................................................................................................................................................................
42
+ ...........................................................................................................................................................................................
43
+ .........................................................................................................................................F.................................................
44
+ .......................................................................................F...................................................................................................
45
+ ...........................................................................................................................................................................................
46
+ ...........................................................................................................................................................................................
47
+ ...........................................................................................................................................................................................
48
+ ...........................................................................................................................................................................................
49
+
50
+ Finished in 2 minute 25.15 seconds (files took 0 seconds to load)
51
+ 6873 examples, 2 failures
52
+ ```
53
+
54
+ ## Installation
55
+
56
+ Add this line to your application's `Gemfile`:
57
+
58
+ ```ruby
59
+ gem 'turbo_tests'
60
+ ```
61
+
62
+ And then execute:
63
+
64
+ $ bundle install
65
+
66
+ Or install it yourself as:
67
+
68
+ $ gem install turbo_tests
69
+
70
+ ## Usage
71
+
72
+ Execute tests:
73
+
74
+ ```bash
75
+ $ bundle exec turbo_tests
76
+ ```
77
+
78
+ Show help:
79
+
80
+ ```bash
81
+ $ bundle exec turbo_tests -h
82
+ Usage: turbo_tests [options]
83
+ -r, --require PATH Require a file.
84
+ -f, --format FORMATTER Choose a formatter.
85
+ -t, --tag TAG Run examples with the specified tag.
86
+ -o, --out FILE Write output to a file instead of $stdout
87
+ -v, --verbose More output
88
+ --fail-fast=[N]
89
+ ```
90
+
91
+ ## Roadmap
92
+ - [ ] Capture time to load files #1
93
+
94
+ ## Development
95
+
96
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
97
+
98
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
99
+
100
+ ## Contributing
101
+
102
+ Bug reports and pull requests are welcome on GitHub at https://github.com/serpapi/turbo_tests. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/serpapi/turbo_tests/blob/master/CODE_OF_CONDUCT.md).
103
+
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
108
+
109
+ ## Code of Conduct
110
+
111
+ Everyone interacting in the TurboTests project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serpapi/turbo_tests/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "turbo_tests"
5
+
6
+ require "pry"
7
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "turbo_tests/cli"
6
+
7
+ TurboTests::CLI.new(ARGV).run
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "turbo_tests/version"
4
+ require "bundler/setup"
5
+
6
+ require "open3"
7
+ require "fileutils"
8
+ require "json"
9
+ require "rspec"
10
+
11
+ require "parallel_tests"
12
+ require "parallel_tests/rspec/runner"
13
+
14
+ require "turbo_tests/reporter"
15
+ require "turbo_tests/runner"
16
+ require "turbo_tests/json_rows_formatter"
17
+
18
+ module TurboTests
19
+ FakeException = Struct.new(:backtrace, :message, :cause)
20
+ class FakeException
21
+ def self.from_obj(obj)
22
+ if obj
23
+ klass =
24
+ Class.new(FakeException) {
25
+ define_singleton_method(:name) do
26
+ obj["class_name"]
27
+ end
28
+ }
29
+
30
+ klass.new(
31
+ obj["backtrace"],
32
+ obj["message"],
33
+ FakeException.from_obj(obj["cause"])
34
+ )
35
+ end
36
+ end
37
+ end
38
+
39
+ FakeExecutionResult = Struct.new(:example_skipped?, :pending_message, :status, :pending_fixed?, :exception)
40
+ class FakeExecutionResult
41
+ def self.from_obj(obj)
42
+ new(
43
+ obj["example_skipped?"],
44
+ obj["pending_message"],
45
+ obj["status"].to_sym,
46
+ obj["pending_fixed?"],
47
+ FakeException.from_obj(obj["exception"])
48
+ )
49
+ end
50
+ end
51
+
52
+ FakeExample = Struct.new(:execution_result, :location, :description, :full_description, :metadata, :location_rerun_argument)
53
+ class FakeExample
54
+ def self.from_obj(obj)
55
+ metadata = obj["metadata"]
56
+
57
+ metadata["shared_group_inclusion_backtrace"].map! do |frame|
58
+ RSpec::Core::SharedExampleGroupInclusionStackFrame.new(
59
+ frame["shared_group_name"],
60
+ frame["inclusion_location"]
61
+ )
62
+ end
63
+
64
+ metadata[:shared_group_inclusion_backtrace] = metadata.delete("shared_group_inclusion_backtrace")
65
+
66
+ new(
67
+ FakeExecutionResult.from_obj(obj["execution_result"]),
68
+ obj["location"],
69
+ obj["description"],
70
+ obj["full_description"],
71
+ metadata,
72
+ obj["location_rerun_argument"]
73
+ )
74
+ end
75
+
76
+ def notification
77
+ RSpec::Core::Notifications::ExampleNotification.for(
78
+ self
79
+ )
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "turbo_tests"
4
+ require "optparse"
5
+
6
+ module TurboTests
7
+ class CLI
8
+ def initialize(argv)
9
+ @argv = argv
10
+ end
11
+
12
+ def run
13
+ requires = []
14
+ formatters = []
15
+ tags = []
16
+ verbose = false
17
+ fail_fast = nil
18
+
19
+ OptionParser.new { |opts|
20
+ opts.on("-r", "--require PATH", "Require a file.") do |filename|
21
+ requires << filename
22
+ end
23
+
24
+ opts.on("-f", "--format FORMATTER", "Choose a formatter.") do |name|
25
+ formatters << {
26
+ name: name,
27
+ outputs: []
28
+ }
29
+ end
30
+
31
+ opts.on("-t", "--tag TAG", "Run examples with the specified tag.") do |tag|
32
+ tags << tag
33
+ end
34
+
35
+ opts.on("-o", "--out FILE", "Write output to a file instead of $stdout") do |filename|
36
+ if formatters.empty?
37
+ formatters << {
38
+ name: "progress",
39
+ outputs: []
40
+ }
41
+ end
42
+ formatters.last[:outputs] << filename
43
+ end
44
+
45
+ opts.on("-v", "--verbose", "More output") do
46
+ verbose = true
47
+ end
48
+
49
+ opts.on("--fail-fast=[N]") do |n|
50
+ n = begin
51
+ Integer(n)
52
+ rescue
53
+ nil
54
+ end
55
+ fail_fast = n.nil? || n < 1 ? 1 : n
56
+ end
57
+ }.parse!(@argv)
58
+
59
+ requires.each { |f| require(f) }
60
+
61
+ if formatters.empty?
62
+ formatters << {
63
+ name: "progress",
64
+ outputs: []
65
+ }
66
+ end
67
+
68
+ formatters.each do |formatter|
69
+ if formatter[:outputs].empty?
70
+ formatter[:outputs] << "-"
71
+ end
72
+ end
73
+
74
+ exit TurboTests::Runner.run(
75
+ formatters: formatters,
76
+ tags: tags,
77
+ files: @argv.empty? ? ["spec"] : @argv,
78
+ verbose: verbose,
79
+ fail_fast: fail_fast
80
+ )
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "rspec/core"
5
+ require "rspec/core/formatters"
6
+ require "rspec/core/notifications"
7
+
8
+ module RSpecExt
9
+ def handle_interrupt
10
+ if RSpec.world.wants_to_quit
11
+ exit!(1)
12
+ else
13
+ RSpec.world.wants_to_quit = true
14
+ end
15
+ end
16
+ end
17
+
18
+ RSpec::Core::Runner.singleton_class.prepend(RSpecExt)
19
+
20
+ module TurboTests
21
+ # An RSpec formatter used for each subprocess during parallel test execution
22
+ class JsonRowsFormatter
23
+ RSpec::Core::Formatters.register(
24
+ self,
25
+ :close,
26
+ :example_failed,
27
+ :example_passed,
28
+ :example_pending,
29
+ :seed
30
+ )
31
+
32
+ attr_reader :output
33
+
34
+ def initialize(output)
35
+ @output = output
36
+ end
37
+
38
+ def example_passed(notification)
39
+ output_row(
40
+ "type" => :example_passed,
41
+ "example" => example_to_json(notification.example)
42
+ )
43
+ end
44
+
45
+ def example_pending(notification)
46
+ output_row(
47
+ "type" => :example_pending,
48
+ "example" => example_to_json(notification.example)
49
+ )
50
+ end
51
+
52
+ def example_failed(notification)
53
+ output_row(
54
+ "type" => :example_failed,
55
+ "example" => example_to_json(notification.example)
56
+ )
57
+ end
58
+
59
+ def seed(notification)
60
+ output_row(
61
+ "type" => :seed,
62
+ "seed" => notification.seed
63
+ )
64
+ end
65
+
66
+ def close(notification)
67
+ output_row(
68
+ "type" => :close
69
+ )
70
+ end
71
+
72
+ private
73
+
74
+ def exception_to_json(exception)
75
+ if exception
76
+ {
77
+ "class_name" => exception.class.name.to_s,
78
+ "backtrace" => exception.backtrace,
79
+ "message" => exception.message,
80
+ "cause" => exception_to_json(exception.cause)
81
+ }
82
+ end
83
+ end
84
+
85
+ def execution_result_to_json(result)
86
+ {
87
+ "example_skipped?" => result.example_skipped?,
88
+ "pending_message" => result.pending_message,
89
+ "status" => result.status,
90
+ "pending_fixed?" => result.pending_fixed?,
91
+ "exception" => exception_to_json(result.exception)
92
+ }
93
+ end
94
+
95
+ def stack_frame_to_json(frame)
96
+ {
97
+ "shared_group_name" => frame.shared_group_name,
98
+ "inclusion_location" => frame.inclusion_location
99
+ }
100
+ end
101
+
102
+ def example_to_json(example)
103
+ {
104
+ "execution_result" => execution_result_to_json(example.execution_result),
105
+ "location" => example.location,
106
+ "description" => example.description,
107
+ "full_description" => example.full_description,
108
+ "metadata" => {
109
+ "shared_group_inclusion_backtrace" =>
110
+ example.metadata[:shared_group_inclusion_backtrace].map { |frame| stack_frame_to_json(frame) }
111
+ },
112
+ "location_rerun_argument" => example.location_rerun_argument
113
+ }
114
+ end
115
+
116
+ def output_row(obj)
117
+ output.puts ENV["RSPEC_FORMATTER_OUTPUT_ID"] + obj.to_json
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurboTests
4
+ class Reporter
5
+ def self.from_config(formatter_config, start_time)
6
+ reporter = new(start_time)
7
+
8
+ formatter_config.each do |config|
9
+ name, outputs = config.values_at(:name, :outputs)
10
+
11
+ outputs.map! do |filename|
12
+ filename == "-" ? STDOUT : File.open(filename, "w")
13
+ end
14
+
15
+ reporter.add(name, outputs)
16
+ end
17
+
18
+ reporter
19
+ end
20
+
21
+ attr_reader :pending_examples
22
+ attr_reader :failed_examples
23
+
24
+ def initialize(start_time)
25
+ @formatters = []
26
+ @pending_examples = []
27
+ @failed_examples = []
28
+ @all_examples = []
29
+ @start_time = start_time
30
+ end
31
+
32
+ def add(name, outputs)
33
+ outputs.each do |output|
34
+ formatter_class =
35
+ case name
36
+ when "p", "progress"
37
+ RSpec::Core::Formatters::ProgressFormatter
38
+ when "d", "documentation"
39
+ RSpec::Core::Formatters::DocumentationFormatter
40
+ else
41
+ Kernel.const_get(name)
42
+ end
43
+
44
+ @formatters << formatter_class.new(output)
45
+ end
46
+ end
47
+
48
+ def example_passed(example)
49
+ delegate_to_formatters(:example_passed, example.notification)
50
+
51
+ @all_examples << example
52
+ end
53
+
54
+ def example_pending(example)
55
+ delegate_to_formatters(:example_pending, example.notification)
56
+
57
+ @all_examples << example
58
+ @pending_examples << example
59
+ end
60
+
61
+ def example_failed(example)
62
+ delegate_to_formatters(:example_failed, example.notification)
63
+
64
+ @all_examples << example
65
+ @failed_examples << example
66
+ end
67
+
68
+ def finish
69
+ end_time = Time.now
70
+
71
+ delegate_to_formatters(:start_dump,
72
+ RSpec::Core::Notifications::NullNotification)
73
+ delegate_to_formatters(:dump_pending,
74
+ RSpec::Core::Notifications::ExamplesNotification.new(
75
+ self
76
+ ))
77
+ delegate_to_formatters(:dump_failures,
78
+ RSpec::Core::Notifications::ExamplesNotification.new(
79
+ self
80
+ ))
81
+ delegate_to_formatters(:dump_summary,
82
+ RSpec::Core::Notifications::SummaryNotification.new(
83
+ end_time - @start_time,
84
+ @all_examples,
85
+ @failed_examples,
86
+ @pending_examples,
87
+ 0,
88
+ 0
89
+ ))
90
+ delegate_to_formatters(:close,
91
+ RSpec::Core::Notifications::NullNotification)
92
+ end
93
+
94
+ protected
95
+
96
+ def delegate_to_formatters(method, *args)
97
+ @formatters.each do |formatter|
98
+ formatter.send(method, *args) if formatter.respond_to?(method)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ require "parallel_tests/rspec/runner"
6
+
7
+ module TurboTests
8
+ class Runner
9
+ def self.run(opts = {})
10
+ files = opts[:files]
11
+ formatters = opts[:formatters]
12
+ tags = opts[:tags]
13
+ start_time = opts.fetch(:start_time) { Time.now }
14
+ verbose = opts.fetch(:verbose, false)
15
+ fail_fast = opts.fetch(:fail_fast, nil)
16
+
17
+ reporter = Reporter.from_config(formatters, start_time)
18
+
19
+ new(
20
+ reporter: reporter,
21
+ files: files,
22
+ tags: tags,
23
+ verbose: verbose,
24
+ fail_fast: fail_fast
25
+ ).run
26
+ end
27
+
28
+ def initialize(opts)
29
+ @reporter = opts[:reporter]
30
+ @files = opts[:files]
31
+ @tags = opts[:tags]
32
+ @verbose = opts[:verbose]
33
+ @fail_fast = opts[:fail_fast]
34
+ @failure_count = 0
35
+ @runtime_log = "tmp/parallel_runtime_rspec.log"
36
+
37
+ @messages = Queue.new
38
+ @threads = []
39
+ end
40
+
41
+ def run
42
+ @num_processes = ParallelTests.determine_number_of_processes(nil)
43
+
44
+ tests_in_groups =
45
+ ParallelTests::RSpec::Runner.tests_in_groups(
46
+ @files,
47
+ @num_processes,
48
+ runtime_log: @runtime_log
49
+ )
50
+
51
+ tests_in_groups.each_with_index do |tests, process_id|
52
+ start_regular_subprocess(tests, process_id + 1)
53
+ end
54
+
55
+ handle_messages
56
+
57
+ @reporter.finish
58
+
59
+ @threads.each(&:join)
60
+
61
+ @reporter.failed_examples.empty?
62
+ end
63
+
64
+ protected
65
+
66
+ def start_regular_subprocess(tests, process_id)
67
+ start_subprocess(
68
+ {"TEST_ENV_NUMBER" => process_id.to_s},
69
+ @tags.map { |tag| "--tag=#{tag}" },
70
+ tests,
71
+ process_id
72
+ )
73
+ end
74
+
75
+ def start_subprocess(env, extra_args, tests, process_id)
76
+ if tests.empty?
77
+ @messages << {
78
+ "type" => "exit",
79
+ "process_id" => process_id
80
+ }
81
+ else
82
+ require "securerandom"
83
+ env["RSPEC_FORMATTER_OUTPUT_ID"] = SecureRandom.uuid
84
+ env["RUBYOPT"] = "-I#{File.expand_path("..", __dir__)}"
85
+
86
+ command = [
87
+ "bundle", "exec", "rspec",
88
+ *extra_args,
89
+ "--format", "ParallelTests::RSpec::RuntimeLogger",
90
+ "--out", @runtime_log,
91
+ "--format", "TurboTests::JsonRowsFormatter",
92
+ *tests
93
+ ]
94
+
95
+ if @verbose
96
+ command_str = [
97
+ env.map { |k, v| "#{k}=#{v}" }.join(" "),
98
+ command.join(" ")
99
+ ].select { |x| x.size > 0 }.join(" ")
100
+
101
+ STDERR.puts "Process #{process_id}: #{command_str}"
102
+ end
103
+
104
+ _stdin, stdout, stderr, _wait_thr = Open3.popen3(env, *command)
105
+
106
+ @threads <<
107
+ Thread.new {
108
+ require "json"
109
+ stdout.each_line do |line|
110
+ result = line.split(env["RSPEC_FORMATTER_OUTPUT_ID"])
111
+
112
+ output = result.shift
113
+ STDOUT.print(output) unless output.empty?
114
+
115
+ message = result.shift
116
+ next unless message
117
+
118
+ message = JSON.parse(message)
119
+ message["process_id"] = process_id
120
+ @messages << message
121
+ end
122
+
123
+ @messages << {"type" => "exit", "process_id" => process_id}
124
+ }
125
+
126
+ @threads << start_copy_thread(stderr, STDERR)
127
+ end
128
+ end
129
+
130
+ def start_copy_thread(src, dst)
131
+ Thread.new do
132
+ loop do
133
+ msg = src.readpartial(4096)
134
+ rescue EOFError
135
+ break
136
+ else
137
+ dst.write(msg)
138
+ end
139
+ end
140
+ end
141
+
142
+ def handle_messages
143
+ exited = 0
144
+
145
+ loop do
146
+ message = @messages.pop
147
+ case message["type"]
148
+ when "example_passed"
149
+ example = FakeExample.from_obj(message["example"])
150
+ @reporter.example_passed(example)
151
+ when "example_pending"
152
+ example = FakeExample.from_obj(message["example"])
153
+ @reporter.example_pending(example)
154
+ when "example_failed"
155
+ example = FakeExample.from_obj(message["example"])
156
+ @reporter.example_failed(example)
157
+ @failure_count += 1
158
+ if fail_fast_met
159
+ @threads.each(&:kill)
160
+ break
161
+ end
162
+ when "seed"
163
+ when "close"
164
+ when "exit"
165
+ exited += 1
166
+ if exited == @num_processes
167
+ break
168
+ end
169
+ else
170
+ warn("Unhandled message in main process: #{message}")
171
+ end
172
+ end
173
+ rescue Interrupt
174
+ end
175
+
176
+ def fail_fast_met
177
+ !@fail_fast.nil? && @fail_fast >= @failure_count
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,3 @@
1
+ module TurboTests
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "lib/turbo_tests/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "turbo_tests"
5
+ spec.version = TurboTests::VERSION
6
+ spec.authors = ["Ilya Zub"]
7
+ spec.email = ["ilya@serpapi.com"]
8
+
9
+ spec.summary = "Runner for grosser/parallel_tests with incremental summarized output. Based on Discourse and Rubygems work in this area."
10
+ spec.homepage = "https://github.com/serpapi/turbo_tests"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/serpapi/turbo_tests"
16
+ spec.metadata["changelog_uri"] = "https://github.com/serpapi/turbo_tests/releases"
17
+
18
+ spec.add_dependency "rspec"
19
+ spec.add_dependency "parallel_tests"
20
+ spec.add_dependency "optparse"
21
+
22
+ spec.add_development_dependency "pry"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turbo_tests
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Zub
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parallel_tests
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: optparse
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - ilya@serpapi.com
72
+ executables:
73
+ - turbo_tests
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - exe/turbo_tests
89
+ - lib/turbo_tests.rb
90
+ - lib/turbo_tests/cli.rb
91
+ - lib/turbo_tests/json_rows_formatter.rb
92
+ - lib/turbo_tests/reporter.rb
93
+ - lib/turbo_tests/runner.rb
94
+ - lib/turbo_tests/version.rb
95
+ - turbo_tests.gemspec
96
+ homepage: https://github.com/serpapi/turbo_tests
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://github.com/serpapi/turbo_tests
101
+ source_code_uri: https://github.com/serpapi/turbo_tests
102
+ changelog_uri: https://github.com/serpapi/turbo_tests/releases
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.3.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.1.4
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Runner for grosser/parallel_tests with incremental summarized output. Based
122
+ on Discourse and Rubygems work in this area.
123
+ test_files: []