rspec-core-parallel 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e45d853c91a7618f7d3e2610761a0a7271ade685db327199de1b3a045ed9609
4
- data.tar.gz: f652d5b00ce96ef27afbab7d064caaf8ed9cc5541c5fa739708bdd24cf08c5ef
3
+ metadata.gz: 959cdd2e6744a83648486825d673ea9164f39f2aa0fbafafd2f4b49eda5163ae
4
+ data.tar.gz: 8657334668c6e6aaeb8ceca2fabf5c413d1860f19379e34d463a26b01bcdb837
5
5
  SHA512:
6
- metadata.gz: ce28c54e6b455f78bed2682ce55ddc7c79b53ee3913a9ea3c5e91ed13f2b0507baa56130a494feb1bd913a3c05ea30819eb29608ee2aa82b9b314ab5335b6a1b
7
- data.tar.gz: 2db7c74933f5f617e44027b3687b473395d2c4d93e8277ac13b172e558b6c3304a572ef5f5c81c77acbf26c85e4802b3d1aa3ea9b811b2c67b1c6b20c7cadd4e
6
+ metadata.gz: d12df7ed1e4abe97795bc1643779d16dd9c348458121952733e974340ae5024abe3e7b18840c308294b8955b5294cb77353506276e0428dc5dfd6775f9080430
7
+ data.tar.gz: '02925aa2a3aff6acbe74d6c499802d247942cbc83336cba8dce061cba2d41fe73a62d230cac84f26e1b2e70ed73f94414a5c264cd509735fa1226644c6816b2e'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ * In Rails apps every worker writes to its own log file (`log/test-1.log`,
6
+ `log/test-2.log`...) instead of `log/test.log`.
7
+
3
8
  ## 0.3.0
4
9
 
5
10
  * `before(:run)` and `after(:run)` hooks, which run once per run: in the main
data/README.md CHANGED
@@ -68,6 +68,9 @@ loaded from the schema when needed, like `rails test` does in parallel. Set
68
68
  (`maintain_test_schema!` runs before the workers are forked), so on CI create it as usual, e.g. with
69
69
  `bin/rails db:create db:schema:load`, rather than with `parallel:create`.
70
70
 
71
+ **Logs.** In Rails apps every worker writes to its own log file (`log/test-1.log`, `log/test-2.log`, ...), so that the
72
+ lines of the workers don't mix in `log/test.log`, which keeps the lines of the main process.
73
+
71
74
  **Other resources.** Each worker gets a `TEST_ENV_NUMBER` environment variable (`""`, `"2"`, `"3"`, ...) as with
72
75
  parallel_tests, and runs the `parallel_worker_setup` hooks. Workers are forked after the suite is loaded, so anything
73
76
  set up while loading, like a constant with a directory or a Redis client, is the same in all of them. This also applies
@@ -11,6 +11,8 @@ module RSpec
11
11
  # `ActiveSupport.parallelize_test_databases` to `false` to opt out.
12
12
  # Workers are numbered from 0 for these hooks, as in Rails. Rails
13
13
  # versions before 8.1 have no hooks to run before forking.
14
+ # * gives every worker its own log file (`log/test-1.log`, `log/test-2.log`...),
15
+ # rather than mixing the lines of all the workers in `log/test.log`.
14
16
  # * loads the translations before forking, as Rails does when eager
15
17
  # loading, rather than in every worker.
16
18
  #
@@ -22,9 +24,39 @@ module RSpec
22
24
  end
23
25
 
24
26
  def self.after_fork(worker_number)
27
+ split_log(worker_number)
25
28
  hooks(:after_fork_hooks).each { |hook| hook.call(worker_number - 1) }
26
29
  end
27
30
 
31
+ # Rails opens the log file itself and hands the open file to its
32
+ # logger, so the path comes from the file the logger writes to.
33
+ # Loggers writing elsewhere, like to STDOUT, are left as they are.
34
+ def self.split_log(worker_number)
35
+ return unless defined?(::Rails.logger) && ::Rails.logger
36
+
37
+ loggers = ::Rails.logger.respond_to?(:broadcasts) ? ::Rails.logger.broadcasts : [::Rails.logger]
38
+ loggers.each do |logger|
39
+ device = logger.instance_variable_get(:@logdev)&.dev
40
+ next unless device.is_a?(::File)
41
+
42
+ logger.reopen(open_log_file(worker_log_path(device.path, worker_number)))
43
+ end
44
+ end
45
+
46
+ def self.worker_log_path(path, worker_number)
47
+ extension = ::File.extname(path)
48
+ "#{path.delete_suffix(extension)}-#{worker_number}#{extension}"
49
+ end
50
+
51
+ # As Rails opens its own log file: in binary mode, so that lines in
52
+ # any encoding can be written, and without buffering.
53
+ def self.open_log_file(path)
54
+ file = ::File.open(path, 'a')
55
+ file.binmode
56
+ file.sync = true
57
+ file
58
+ end
59
+
28
60
  def self.run_cleanup(worker_number)
29
61
  hooks(:run_cleanup_hooks).each { |hook| hook.call(worker_number - 1) }
30
62
  end
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Parallel
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core-parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi