split-test-rb 1.0.4 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffaee1d0d9211e912e20044c5fbf90b4d6c2ad643321d3c5dc94f2cbf5a8921f
4
- data.tar.gz: bae21fcdfab3ff5d94e96a1bfa8d00e391ff5387b20e51570ee1bfe3f169ae83
3
+ metadata.gz: f765610ad0a575e0bb582ea31ae9ed544382fed7d4ef63d2f9f396460a19c821
4
+ data.tar.gz: 65061f28e3bf6f0f9882b4d6f4e110c23eadd7146cb5bc0e3dfec608c2a49022
5
5
  SHA512:
6
- metadata.gz: 56d1f3f3ddaa7e24be47904d499e01d4aac169f4fdfde9678a7c72644d2a5ac065d1bb990e44a1e579c6ff402f469fd9f2867eedbf92f68289b9b88c9deccd50
7
- data.tar.gz: 365fbe88adab8a447848389ec8039521d7488a974079fb2ed91086f35d111ce8a74bd465a5b4835a631edd64650396800dcd8828250e0a4c6970b2d3257bd0d7
6
+ metadata.gz: '034288dce122aa532fb53ede46a67af4d05bad5d84163e54fee77e4eee067828f7aed2dd21fd88f870c99170ab19836895ebfc10669ae32a33fcdd4f0698a3f2'
7
+ data.tar.gz: 9808a967a1c9e7f96ff87fedbe9ddef03808a4455987ac0750709a840c8d42e6003dfad2cd5ab28fdf6318236b2c43dcbae2237feb2fc4ecb247ce3b6f20cb1c
data/README.md CHANGED
@@ -87,12 +87,16 @@ The test directory and pattern options are useful for:
87
87
  When you have test files that take significantly longer than others, you can use `--split-by-example-threshold` to automatically split them into individual RSpec examples. This enables finer-grained load balancing across CI nodes.
88
88
 
89
89
  ```bash
90
+ bundle exec rspec --dry-run --format json --out tmp/dry-run.json
90
91
  split-test-rb --json-path tmp/test-results \
91
92
  --node-index $CI_NODE_INDEX \
92
93
  --node-total $CI_NODE_TOTAL \
93
- --split-by-example-threshold 10.0
94
+ --split-by-example-threshold 10.0 \
95
+ --dry-run-json tmp/dry-run.json
94
96
  ```
95
97
 
98
+ `--dry-run-json` is recommended together with this option. Without it, examples missing from the cached JSON are not run (see [Keeping heavy files up to date with `--dry-run-json`](#keeping-heavy-files-up-to-date-with---dry-run-json)).
99
+
96
100
  With this option:
97
101
  - Files with execution time **below** the threshold are distributed as whole files (e.g., `spec/fast_spec.rb`)
98
102
  - Files with execution time **at or above** the threshold are split into individual examples (e.g., `spec/slow_spec.rb[1:1]`, `spec/slow_spec.rb[1:2]`)
@@ -106,21 +110,14 @@ This is useful when:
106
110
 
107
111
  #### Keeping heavy files up to date with `--dry-run-json`
108
112
 
109
- By default, heavy files are assigned only by the example IDs found in the cached JSON reports. Examples that are not in the cache are not assigned to any node:
113
+ Without `--dry-run-json`, heavy files are assigned only by the example IDs found in the cached JSON reports, and a warning is printed. Examples that are not in the cache are not assigned to any node:
110
114
 
111
115
  - Examples newly added to a heavy file
112
116
  - Examples whose IDs shifted because other examples were inserted or moved (RSpec example IDs are position based, e.g. `[1:2:1]`)
113
117
 
114
- Pass the output of `rspec --dry-run --format json` to use the examples that currently exist:
118
+ Pass the output of `rspec --dry-run --format json` to use the examples that currently exist (see the example above).
115
119
 
116
- ```bash
117
- bundle exec rspec --dry-run --format json --out tmp/dry-run.json
118
- split-test-rb --json-path tmp/test-results \
119
- --node-index $CI_NODE_INDEX \
120
- --node-total $CI_NODE_TOTAL \
121
- --split-by-example-threshold 10.0 \
122
- --dry-run-json tmp/dry-run.json
123
- ```
120
+ Every node must use a dry-run JSON with the same examples, or the nodes compute different splits and some tests are run on no node. Generating it once (e.g. in a setup job) and sharing it with all nodes as a CI artifact guarantees this, and boots the app only once instead of on every node.
124
121
 
125
122
  With this option, for each heavy file:
126
123
  - Examples in the dry-run JSON are assigned, using cached timings when available and the default timing (1.0s) otherwise
@@ -1,3 +1,3 @@
1
1
  module SplitTestRb
2
- VERSION = '1.0.4'.freeze
2
+ VERSION = '1.0.5'.freeze
3
3
  end
data/lib/split_test_rb.rb CHANGED
@@ -241,6 +241,7 @@ module SplitTestRb
241
241
  threshold = options[:split_by_example_threshold]
242
242
  timings = if threshold
243
243
  current_example_ids = load_current_example_ids(options[:dry_run_json])
244
+ warn_cached_examples_only(file_timings, threshold) unless current_example_ids
244
245
  apply_example_splitting(file_timings, json_files, threshold,
245
246
  current_example_ids: current_example_ids, default_files: default_files)
246
247
  else
@@ -256,6 +257,15 @@ module SplitTestRb
256
257
  .split(file_timings, threshold)
257
258
  end
258
259
 
260
+ # Warns that heavy files are assigned only by the cached example IDs when --dry-run-json is not given,
261
+ # because examples missing from the cache (new or shifted IDs) are then not run on any node
262
+ def self.warn_cached_examples_only(file_timings, threshold)
263
+ return unless file_timings.any? { |_file, time| time >= threshold }
264
+
265
+ warn 'Warning: --dry-run-json is not given, so examples of heavy files that are not in the cached JSON ' \
266
+ 'will not be run. Pass the output of `rspec --dry-run --format json` with --dry-run-json'
267
+ end
268
+
259
269
  # Loads example IDs from an RSpec dry-run JSON report, or returns nil when no path is given
260
270
  def self.load_current_example_ids(dry_run_json)
261
271
  return nil unless dry_run_json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split-test-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naofumi Fujii