test_suite_splitter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e8eca9c33b9e9db919f0e2a8a7aa816217e054f17785b22411c0196315591e8
4
+ data.tar.gz: 8618f272307e0b5967c89822f18b3e4f0d6c425cf3011e294b2c4ce634e83ef0
5
+ SHA512:
6
+ metadata.gz: 188817535dd7829b1c2513071165287c76b405100365464744636639af514004f511aa8859da73a302d7b65127784e2a57d14fdc2ece24eeb546e076252b1ee1
7
+ data.tar.gz: 69f7f346e5dc3c6708b58e36ec55ab1d9990745fa5382479611a136318bd5f08008a478a2e47f7033f9545461b7ed61576d9178998f3d6b4779d5cb0dfaf3c18
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rubocop.yml ADDED
@@ -0,0 +1,195 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ NewCops: enable
5
+ TargetRubyVersion: 2.7
6
+
7
+ require:
8
+ - rubocop-performance
9
+ - rubocop-rspec
10
+
11
+ Layout/AccessModifierIndentation:
12
+ EnforcedStyle: outdent
13
+
14
+ Layout/ArgumentAlignment:
15
+ EnforcedStyle: with_fixed_indentation
16
+
17
+ Layout/CaseIndentation:
18
+ EnforcedStyle: end
19
+
20
+ Layout/EmptyLines:
21
+ Enabled: false
22
+
23
+ Layout/EmptyLinesAroundArguments:
24
+ Enabled: false
25
+
26
+ Layout/EmptyLinesAroundAttributeAccessor:
27
+ Enabled: true
28
+
29
+ Layout/EndAlignment:
30
+ EnforcedStyleAlignWith: variable
31
+
32
+ Layout/LineLength:
33
+ Max: 160
34
+
35
+ Layout/MultilineMethodCallIndentation:
36
+ EnforcedStyle: indented
37
+
38
+ Layout/MultilineOperationIndentation:
39
+ EnforcedStyle: indented
40
+
41
+ Layout/ParameterAlignment:
42
+ EnforcedStyle: with_fixed_indentation
43
+
44
+ Layout/RescueEnsureAlignment:
45
+ Enabled: false
46
+
47
+ Layout/SpaceAroundMethodCallOperator:
48
+ Enabled: true
49
+
50
+ Layout/SpaceInsideHashLiteralBraces:
51
+ EnforcedStyle: no_space
52
+
53
+ Lint/DeprecatedOpenSSLConstant:
54
+ Enabled: true
55
+
56
+ Lint/FloatComparison:
57
+ Enabled: false
58
+
59
+ Lint/RaiseException:
60
+ Enabled: true
61
+
62
+ Lint/StructNewOverride:
63
+ Enabled: true
64
+
65
+ # Metrics/AbcSize:
66
+ # Max: 25
67
+
68
+ Metrics/BlockLength:
69
+ Enabled: false
70
+
71
+ Metrics/ClassLength:
72
+ Max: 250
73
+
74
+ Metrics/AbcSize:
75
+ Max: 29
76
+
77
+ Metrics/CyclomaticComplexity:
78
+ Max: 13
79
+
80
+ Metrics/MethodLength:
81
+ Max: 50
82
+
83
+ Metrics/PerceivedComplexity:
84
+ Max: 15
85
+
86
+ RSpec/AnyInstance:
87
+ Enabled: false
88
+
89
+ RSpec/ContextWording:
90
+ Enabled: false
91
+
92
+ RSpec/DescribeClass:
93
+ Enabled: false
94
+
95
+ RSpec/DescribedClass:
96
+ Enabled: false
97
+
98
+ RSpec/ExampleLength:
99
+ Enabled: false
100
+
101
+ Style/FormatStringToken:
102
+ Enabled: false
103
+
104
+ RSpec/LetSetup:
105
+ Enabled: false
106
+
107
+ RSpec/MessageSpies:
108
+ Enabled: false
109
+
110
+ RSpec/MultipleExpectations:
111
+ Enabled: false
112
+
113
+ RSpec/NamedSubject:
114
+ Enabled: false
115
+
116
+ RSpec/NestedGroups:
117
+ Enabled: false
118
+
119
+ # This can make expectaions look weird: Prefer using be_rvm_in_build_config matcher over rvm_in_build_config?
120
+ RSpec/PredicateMatcher:
121
+ Enabled: false
122
+
123
+ RSpec/StubbedMock:
124
+ Enabled: false
125
+
126
+ Style/CaseLikeIf:
127
+ Enabled: false
128
+
129
+ Style/ClassAndModuleChildren:
130
+ EnforcedStyle: compact
131
+
132
+ Style/ConditionalAssignment:
133
+ Enabled: false
134
+
135
+ Style/Documentation:
136
+ Enabled: false
137
+
138
+ Style/ExplicitBlockArgument:
139
+ Enabled: false
140
+
141
+ Style/ExponentialNotation:
142
+ Enabled: true
143
+
144
+ Style/FrozenStringLiteralComment:
145
+ Enabled: false
146
+
147
+ # Will report offences for many places that are much more readable without using a guard clause
148
+ Style/GuardClause:
149
+ Enabled: false
150
+
151
+ Style/HashEachMethods:
152
+ Enabled: true
153
+
154
+ Style/HashTransformKeys:
155
+ Enabled: true
156
+
157
+ Style/HashTransformValues:
158
+ Enabled: true
159
+
160
+ Style/Lambda:
161
+ Enabled: false
162
+
163
+ Style/LambdaCall:
164
+ Enabled: false
165
+
166
+ Style/MultipleComparison:
167
+ Enabled: false
168
+
169
+ Style/RegexpLiteral:
170
+ Enabled: false
171
+
172
+ Style/StringLiterals:
173
+ EnforcedStyle: double_quotes
174
+
175
+ Style/StringLiteralsInInterpolation:
176
+ Enabled: false
177
+
178
+ Style/NilComparison:
179
+ Enabled: false
180
+
181
+ Style/SignalException:
182
+ EnforcedStyle: only_raise
183
+
184
+ Style/SlicingWithRange:
185
+ Enabled: true
186
+
187
+ Style/SymbolArray:
188
+ Enabled: false
189
+
190
+ Style/TrivialAccessors:
191
+ ExactNameMatch: true
192
+ Enabled: true
193
+
194
+ Style/WordArray:
195
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler"
10
+ gem "juwelier"
11
+ end
12
+
13
+ group :development, :test do
14
+ gem "rspec"
15
+ gem "rubocop"
16
+ gem "rubocop-performance"
17
+ gem "rubocop-rspec"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,126 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.8.0)
5
+ public_suffix (>= 2.0.2, < 5.0)
6
+ ast (2.4.2)
7
+ builder (3.2.4)
8
+ descendants_tracker (0.0.4)
9
+ thread_safe (~> 0.3, >= 0.3.1)
10
+ diff-lcs (1.4.4)
11
+ faraday (1.8.0)
12
+ faraday-em_http (~> 1.0)
13
+ faraday-em_synchrony (~> 1.0)
14
+ faraday-excon (~> 1.1)
15
+ faraday-httpclient (~> 1.0.1)
16
+ faraday-net_http (~> 1.0)
17
+ faraday-net_http_persistent (~> 1.1)
18
+ faraday-patron (~> 1.0)
19
+ faraday-rack (~> 1.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-em_http (1.0.0)
23
+ faraday-em_synchrony (1.0.0)
24
+ faraday-excon (1.1.0)
25
+ faraday-httpclient (1.0.1)
26
+ faraday-net_http (1.0.1)
27
+ faraday-net_http_persistent (1.2.0)
28
+ faraday-patron (1.0.0)
29
+ faraday-rack (1.0.0)
30
+ git (1.9.1)
31
+ rchardet (~> 1.8)
32
+ github_api (0.19.0)
33
+ addressable (~> 2.4)
34
+ descendants_tracker (~> 0.0.4)
35
+ faraday (>= 0.8, < 2)
36
+ hashie (~> 3.5, >= 3.5.2)
37
+ oauth2 (~> 1.0)
38
+ hashie (3.6.0)
39
+ highline (2.0.3)
40
+ juwelier (2.4.9)
41
+ builder
42
+ bundler
43
+ git
44
+ github_api
45
+ highline
46
+ kamelcase (~> 0)
47
+ nokogiri
48
+ psych
49
+ rake
50
+ rdoc
51
+ semver2
52
+ jwt (2.3.0)
53
+ kamelcase (0.0.2)
54
+ semver2 (~> 3)
55
+ multi_json (1.15.0)
56
+ multi_xml (0.6.0)
57
+ multipart-post (2.1.1)
58
+ nokogiri (1.12.5-x86_64-linux)
59
+ racc (~> 1.4)
60
+ oauth2 (1.4.7)
61
+ faraday (>= 0.8, < 2.0)
62
+ jwt (>= 1.0, < 3.0)
63
+ multi_json (~> 1.3)
64
+ multi_xml (~> 0.5)
65
+ rack (>= 1.2, < 3)
66
+ parallel (1.21.0)
67
+ parser (3.0.2.0)
68
+ ast (~> 2.4.1)
69
+ psych (4.0.2)
70
+ public_suffix (4.0.6)
71
+ racc (1.6.0)
72
+ rack (2.2.3)
73
+ rainbow (3.0.0)
74
+ rake (13.0.6)
75
+ rchardet (1.8.0)
76
+ rdoc (6.3.3)
77
+ regexp_parser (2.1.1)
78
+ rexml (3.2.5)
79
+ rspec (3.10.0)
80
+ rspec-core (~> 3.10.0)
81
+ rspec-expectations (~> 3.10.0)
82
+ rspec-mocks (~> 3.10.0)
83
+ rspec-core (3.10.1)
84
+ rspec-support (~> 3.10.0)
85
+ rspec-expectations (3.10.1)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.10.0)
88
+ rspec-mocks (3.10.2)
89
+ diff-lcs (>= 1.2.0, < 2.0)
90
+ rspec-support (~> 3.10.0)
91
+ rspec-support (3.10.3)
92
+ rubocop (1.23.0)
93
+ parallel (~> 1.10)
94
+ parser (>= 3.0.0.0)
95
+ rainbow (>= 2.2.2, < 4.0)
96
+ regexp_parser (>= 1.8, < 3.0)
97
+ rexml
98
+ rubocop-ast (>= 1.12.0, < 2.0)
99
+ ruby-progressbar (~> 1.7)
100
+ unicode-display_width (>= 1.4.0, < 3.0)
101
+ rubocop-ast (1.13.0)
102
+ parser (>= 3.0.1.1)
103
+ rubocop-performance (1.12.0)
104
+ rubocop (>= 1.7.0, < 2.0)
105
+ rubocop-ast (>= 0.4.0)
106
+ rubocop-rspec (2.6.0)
107
+ rubocop (~> 1.19)
108
+ ruby-progressbar (1.11.0)
109
+ ruby2_keywords (0.0.5)
110
+ semver2 (3.4.2)
111
+ thread_safe (0.3.6)
112
+ unicode-display_width (2.1.0)
113
+
114
+ PLATFORMS
115
+ x86_64-linux
116
+
117
+ DEPENDENCIES
118
+ bundler
119
+ juwelier
120
+ rspec
121
+ rubocop
122
+ rubocop-performance
123
+ rubocop-rspec
124
+
125
+ BUNDLED WITH
126
+ 2.2.28
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2021 kaspernj
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = test_suite_splitter
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to test_suite_splitter
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2021 kaspernj. See LICENSE.txt for
18
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ warn e.message
7
+ warn "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require "rake"
11
+ require "juwelier"
12
+ Juwelier::Tasks.new do |gem|
13
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
14
+ gem.name = "test_suite_splitter"
15
+ gem.homepage = "http://github.com/kaspernj/test_suite_splitter"
16
+ gem.license = "MIT"
17
+ gem.summary = "Split your RSpec test suite up into several groups and run them in parallel."
18
+ gem.description = "Split your RSpec test suite up into several groups and run them in parallel."
19
+ gem.email = "k@spernj.org"
20
+ gem.authors = ["kaspernj"]
21
+
22
+ # dependencies defined in Gemfile
23
+ end
24
+ Juwelier::RubygemsDotOrgTasks.new
25
+ require "rake/testtask"
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << "lib" << "test"
28
+ test.pattern = "test/**/test_*.rb"
29
+ test.verbose = true
30
+ end
31
+
32
+ desc "Code coverage detail"
33
+ task :simplecov do
34
+ ENV["COVERAGE"] = "true"
35
+ Rake::Task["test"].execute
36
+ end
37
+
38
+ task default: :test
39
+
40
+ require "rdoc/task"
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?("VERSION") ? File.read("VERSION") : ""
43
+
44
+ rdoc.rdoc_dir = "rdoc"
45
+ rdoc.title = "test_suite_splitter #{version}"
46
+ rdoc.rdoc_files.include("README*")
47
+ rdoc.rdoc_files.include("lib/**/*.rb")
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This task detects and prints out the RSpec files for the current build group
4
+
5
+ require "#{__dir__}/../lib/test_suite_splitter"
6
+
7
+ args = {}
8
+ ARGV.each do |arg|
9
+ if (match = arg.match(/\A--(.+?)=(.+)\Z/))
10
+ args[match[1]] = match[2]
11
+ end
12
+ end
13
+
14
+ rspec_helper = ::TestSuiteSplitter::RspecHelper.new(
15
+ groups: args.fetch("groups").to_i,
16
+ group_number: args.fetch("group-number").to_i,
17
+ only_types: args["only-types"]&.split(","),
18
+ tags: args["tags"]&.split(",")
19
+ )
20
+
21
+ print rspec_helper.group_files.map { |group_file| group_file.fetch(:path) }.join(" ")
@@ -0,0 +1,210 @@
1
+ class TestSuiteSplitter::RspecHelper
2
+ attr_reader :only_types, :tags
3
+
4
+ def initialize(groups:, group_number:, only_types: nil, tags: nil)
5
+ @groups = groups
6
+ @group_number = group_number
7
+ @example_data_exists = File.exist?("spec/examples.txt")
8
+ @only_types = only_types
9
+ @tags = tags
10
+ end
11
+
12
+ def example_data_exists?
13
+ @example_data_exists
14
+ end
15
+
16
+ def example_data
17
+ @example_data ||= begin
18
+ raw_data = File.read("spec/examples.txt")
19
+
20
+ result = []
21
+ raw_data.scan(/^\.\/(.+)\[(.+?)\]\s+\|\s+(.+?)\s+\|\s+((.+?) seconds|)\s+\|$/) do |match|
22
+ file_path = match[0]
23
+ spec_result = match[1]
24
+ seconds = match[4]&.to_f
25
+
26
+ spec_data = {
27
+ file_path: file_path,
28
+ spec_result: spec_result,
29
+ seconds: seconds
30
+ }
31
+
32
+ result << spec_data
33
+ end
34
+
35
+ result
36
+ end
37
+ end
38
+
39
+ def example_files
40
+ @example_files ||= begin
41
+ files = {}
42
+ example_data.each do |spec_data|
43
+ file_path = spec_data.fetch(:file_path)
44
+ seconds = spec_data.fetch(:seconds)
45
+
46
+ files[file_path] ||= {examples: 0, seconds: 0.0}
47
+ files[file_path][:examples] += 1
48
+ files[file_path][:seconds] += seconds if seconds
49
+ end
50
+
51
+ files
52
+ end
53
+ end
54
+
55
+ def example_file(path)
56
+ example_files[path]
57
+ end
58
+
59
+ def group_files
60
+ return @group_files if @group_files
61
+
62
+ sorted_files.each do |file|
63
+ file_path = file.fetch(:path)
64
+ file_data = example_file(file_path) if example_data_exists?
65
+
66
+ if file_data
67
+ examples = file_data.fetch(:examples)
68
+ seconds = file_data.fetch(:seconds)
69
+ else
70
+ examples = file.fetch(:examples)
71
+ end
72
+
73
+ group = group_with_least
74
+ group[:examples] += examples
75
+ group[:files] << file
76
+ group[:seconds] += seconds if seconds
77
+ end
78
+
79
+ @group_files = group_orders[@group_number - 1].fetch(:files)
80
+ end
81
+
82
+ def group_orders
83
+ @group_orders ||= begin
84
+ group_orders = []
85
+ @groups.times do
86
+ group_orders << {
87
+ examples: 0,
88
+ files: [],
89
+ seconds: 0.0
90
+ }
91
+ end
92
+ group_orders
93
+ end
94
+ end
95
+
96
+ def group_with_least
97
+ group_orders.min do |group1, group2|
98
+ if example_data_exists? && group1.fetch(:seconds) != 0.0 && group2.fetch(:seconds) != 0.0
99
+ group1.fetch(:seconds) <=> group2.fetch(:seconds)
100
+ else
101
+ group1.fetch(:examples) <=> group2.fetch(:examples)
102
+ end
103
+ end
104
+ end
105
+
106
+ # Sort them so that they are sorted by file path in three groups so each group have an equal amount of controller specs, features specs and so on
107
+ def sorted_files
108
+ files.values.sort do |file1, file2|
109
+ file1_path = file1.fetch(:path)
110
+ file2_path = file2.fetch(:path)
111
+
112
+ file1_data = example_file(file1_path) if example_data_exists?
113
+ file2_data = example_file(file2_path) if example_data_exists?
114
+
115
+ if file1_data && file2_data && file1_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
116
+ value1 = file1_data[:seconds]
117
+ else
118
+ value1 = file1.fetch(:points)
119
+ end
120
+
121
+ if file2_data && file1_data && file2_data.fetch(:seconds) != 0.0 && file2_data.fetch(:seconds) != 0.0
122
+ value2 = file2_data[:seconds]
123
+ else
124
+ value2 = file2.fetch(:points)
125
+ end
126
+
127
+ if value1 == value2
128
+ value2 = file1_path
129
+ value1 = file2_path
130
+ end
131
+
132
+ value2 <=> value1
133
+ end
134
+ end
135
+
136
+ private
137
+
138
+ def dry_result
139
+ @dry_result ||= begin
140
+ require "json"
141
+ require "rspec/core"
142
+ require "stringio"
143
+
144
+ output_capture = StringIO.new
145
+ RSpec::Core::Runner.run(rspec_options, $stderr, output_capture)
146
+
147
+ result = ::JSON.parse(output_capture.string)
148
+
149
+ raise "No examples were found" if result.fetch("examples").empty?
150
+
151
+ result
152
+ end
153
+ end
154
+
155
+ def dry_file(path)
156
+ files.fetch(path)
157
+ end
158
+
159
+ def files
160
+ @files ||= begin
161
+ result = {}
162
+ dry_result.fetch("examples").each do |example|
163
+ file_path = example.fetch("file_path")
164
+ file_path = file_path[2, file_path.length]
165
+ type = type_from_path(file_path)
166
+ points = points_from_type(type)
167
+
168
+ next if ignore_type?(type)
169
+
170
+ result[file_path] = {examples: 0, path: file_path, points: 0, type: type} unless result.key?(file_path)
171
+ result[file_path][:examples] += 1
172
+ result[file_path][:points] += points
173
+ end
174
+
175
+ result
176
+ end
177
+ end
178
+
179
+ def ignore_type?(type)
180
+ only_types && !only_types.include?(type) # rubocop:disable: Style/SafeNavigation
181
+ end
182
+
183
+ def points_from_type(type)
184
+ if type == "feature" || type == "system"
185
+ 10
186
+ elsif type == "controllers"
187
+ 3
188
+ else
189
+ 1
190
+ end
191
+ end
192
+
193
+ def rspec_options
194
+ rspec_options = ["--dry-run", "--format", "json"]
195
+
196
+ tags&.each do |tag|
197
+ rspec_options += ["--tag", tag]
198
+ end
199
+
200
+ # Add the folder with all the specs, which is required when running programmatically
201
+ rspec_options << "spec"
202
+
203
+ rspec_options
204
+ end
205
+
206
+ def type_from_path(file_path)
207
+ match = file_path.match(/^spec\/(.+?)\//)
208
+ match[1] if match
209
+ end
210
+ end
@@ -0,0 +1,5 @@
1
+ module TestSuiteSplitter
2
+ path = "#{__dir__}/test_suite_splitter"
3
+
4
+ autoload :RspecHelper, "#{path}/rspec_helper"
5
+ end
data/peak_flow.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm: true
2
+ script:
3
+ - bundle exec rspec
4
+ - bundle exec rubocop