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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -0
- data/lib/rspec/core/parallel/rails_integration.rb +32 -0
- data/lib/rspec/core/parallel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 959cdd2e6744a83648486825d673ea9164f39f2aa0fbafafd2f4b49eda5163ae
|
|
4
|
+
data.tar.gz: 8657334668c6e6aaeb8ceca2fabf5c413d1860f19379e34d463a26b01bcdb837
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d12df7ed1e4abe97795bc1643779d16dd9c348458121952733e974340ae5024abe3e7b18840c308294b8955b5294cb77353506276e0428dc5dfd6775f9080430
|
|
7
|
+
data.tar.gz: '02925aa2a3aff6acbe74d6c499802d247942cbc83336cba8dce061cba2d41fe73a62d230cac84f26e1b2e70ed73f94414a5c264cd509735fa1226644c6816b2e'
|
data/CHANGELOG.md
CHANGED
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
|