rspeed 0.3.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -0
- data/README.md +10 -7
- data/lib/generators/rspeed/install_generator.rb +1 -1
- data/lib/rspeed.rb +9 -7
- data/lib/rspeed/database.rb +11 -0
- data/lib/rspeed/differ.rb +55 -0
- data/lib/rspeed/env.rb +39 -0
- data/lib/rspeed/extension.rb +3 -2
- data/lib/rspeed/logger.rb +13 -0
- data/lib/rspeed/observer.rb +21 -6
- data/lib/rspeed/redis.rb +72 -0
- data/lib/rspeed/runner.rb +4 -15
- data/lib/rspeed/splitter.rb +24 -97
- data/lib/rspeed/variable.rb +30 -0
- data/lib/rspeed/version.rb +1 -1
- data/spec/common_helper.rb +10 -0
- data/spec/fixtures/1_spec.rb +9 -0
- data/spec/fixtures/2_spec.rb +5 -0
- data/spec/fixtures/empty.rb +4 -0
- data/spec/models/rspeed/database/result_spec.rb +17 -0
- data/spec/models/rspeed/differ/actual_data_spec.rb +20 -0
- data/spec/models/rspeed/differ/actual_files_spec.rb +20 -0
- data/spec/models/rspeed/differ/added_data_spec.rb +19 -0
- data/spec/models/rspeed/differ/diff_spec.rb +51 -0
- data/spec/models/rspeed/differ/removed_data_spec.rb +20 -0
- data/spec/models/rspeed/differ/removed_time_spec.rb +14 -0
- data/spec/models/rspeed/env/app_spec.rb +17 -0
- data/spec/models/rspeed/env/db_spec.rb +17 -0
- data/spec/models/rspeed/env/host_spec.rb +17 -0
- data/spec/models/rspeed/env/pipe_spec.rb +19 -0
- data/spec/models/rspeed/env/pipes_spec.rb +19 -0
- data/spec/models/rspeed/env/port_spec.rb +17 -0
- data/spec/models/rspeed/env/rspeed_spec.rb +43 -0
- data/spec/models/rspeed/env/spec_path_spec.rb +19 -0
- data/spec/models/rspeed/observer/after_spec.rb +5 -5
- data/spec/models/rspeed/observer/after_suite_spec.rb +35 -0
- data/spec/models/rspeed/observer/before_spec.rb +0 -2
- data/spec/models/rspeed/observer/before_suite_spec.rb +18 -6
- data/spec/models/rspeed/redis/clean_spec.rb +20 -0
- data/spec/models/rspeed/redis/client_spec.rb +7 -0
- data/spec/models/rspeed/redis/destroy_spec.rb +21 -0
- data/spec/models/rspeed/redis/get_spec.rb +11 -0
- data/spec/models/rspeed/redis/keys_spec.rb +13 -0
- data/spec/models/rspeed/redis/list_spec.rb +19 -0
- data/spec/models/rspeed/redis/profiles_content_spec.rb +19 -0
- data/spec/models/rspeed/redis/result_spec.rb +13 -0
- data/spec/models/rspeed/redis/set_spec.rb +11 -0
- data/spec/models/rspeed/redis/specs_finished_spec.rb +19 -0
- data/spec/models/rspeed/redis/specs_initiated_spec.rb +13 -0
- data/spec/models/rspeed/runner/run_spec.rb +73 -0
- data/spec/models/rspeed/splitter/append_spec.rb +8 -28
- data/spec/models/rspeed/splitter/consolidate_spec.rb +23 -0
- data/spec/models/rspeed/splitter/first_pipe_spec.rb +4 -8
- data/spec/models/rspeed/splitter/need_warm_question_spec.rb +35 -0
- data/spec/models/rspeed/splitter/pipe_files_spec.rb +21 -0
- data/spec/models/rspeed/splitter/split_spec.rb +32 -34
- data/spec/models/rspeed/variable/append_app_name_spec.rb +33 -0
- data/spec/models/rspeed/variable/key_spec.rb +15 -0
- data/spec/models/rspeed/variable/pipe_spec.rb +23 -0
- data/spec/models/rspeed/variable/pipes_pattern_spec.rb +5 -0
- data/spec/models/rspeed/variable/profile_pattern_spec.rb +5 -0
- data/spec/models/rspeed/variable/profile_spec.rb +23 -0
- data/spec/models/rspeed/variable/result_spec.rb +19 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/common.rb +13 -0
- data/spec/support/coverage.rb +14 -0
- data/spec/support/env_mock.rb +3 -0
- data/spec/support/fakeredis.rb +3 -0
- metadata +160 -26
- data/spec/models/rspeed/splitter/destroy_spec.rb +0 -33
- data/spec/models/rspeed/splitter/diff_spec.rb +0 -29
- data/spec/models/rspeed/splitter/get_spec.rb +0 -76
- data/spec/models/rspeed/splitter/keys_spec.rb +0 -33
- data/spec/models/rspeed/splitter/last_pipe_spec.rb +0 -21
- data/spec/models/rspeed/splitter/pipe_spec.rb +0 -21
- data/spec/models/rspeed/splitter/pipes_spec.rb +0 -27
- data/spec/models/rspeed/splitter/rename_spec.rb +0 -18
- data/spec/models/rspeed/splitter/result_spec.rb +0 -19
- data/spec/models/rspeed/splitter/save_spec.rb +0 -57
- data/spec/rails_helper.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b8a143543e9f44b4c5641d60642968b7cc4a7ec85953b17f6ef62743e66196e
|
4
|
+
data.tar.gz: f8fc781825804fe67084c08b05164ca8a31fc87e458952ba0ca86e567576e669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b50821b549363010ab566dd5f654a5b2b042e76fd696054b795126b1343ec3a8d73ed1c3a7a08cb63f1eeba38dbbae8922877bb8ec8649bb4601577b75737b0
|
7
|
+
data.tar.gz: 0f74bea31bf0c550ce6f89b8f22e8c0fedb59acfebe6cddf1dc4fc4499b74e7e73505b4a24327948f1330d9ff46b16f70de0855b4178a452149b33d2b5396051
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,53 @@
|
|
1
|
+
## master
|
2
|
+
|
3
|
+
- None;
|
4
|
+
|
5
|
+
## v0.6.0
|
6
|
+
|
7
|
+
#### Break Change
|
8
|
+
|
9
|
+
- Drops `RSPEED_RESULT_KEY` key in favor of `RSPEED_NAME`;
|
10
|
+
- Renames env `RSPEED_NAME` to `RSPEED_APP`;
|
11
|
+
|
12
|
+
#### News
|
13
|
+
|
14
|
+
- Adds env `RSPEED_SPEC_PATH` to indicate the spec folders path;
|
15
|
+
- Saves pipes and profiles with a zero at the beginning;
|
16
|
+
- Makes sure examples is unique;
|
17
|
+
|
18
|
+
## v0.5.2
|
19
|
+
|
20
|
+
#### Fix
|
21
|
+
|
22
|
+
- Avoid duplicate entries in the consolidated result;
|
23
|
+
|
24
|
+
#### Update
|
25
|
+
|
26
|
+
- CSV dependency dropped;
|
27
|
+
- Drops tmp key in favor of profile keys fetch;
|
28
|
+
|
29
|
+
## v0.5.1
|
30
|
+
|
31
|
+
#### Fix
|
32
|
+
|
33
|
+
- Only pipe number 1 will warm up avoiding duplicated spec entries;
|
34
|
+
|
35
|
+
## v0.5.0
|
36
|
+
|
37
|
+
#### Fix
|
38
|
+
|
39
|
+
- Add env `RSPEED_NAME` to specify the application name and avoid result conflicts between multiple runs;
|
40
|
+
- No more depends on pipe sequence to generate ou aggregate the resul;
|
41
|
+
- rake `rspeed:install`;
|
42
|
+
|
43
|
+
#### Update
|
44
|
+
|
45
|
+
- The result of the pipes are no more saved on Redis. It's now calculated based on result key `rspeed`;
|
46
|
+
|
47
|
+
## v0.4.0
|
48
|
+
|
49
|
+
- Now we make diff to discover removed and added examples;
|
50
|
+
|
1
51
|
## v0.3.0
|
2
52
|
|
3
53
|
- Removed and added files now is considered on run;
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# RSpeed
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CI](https://github.com/wbotelhos/rspeed/workflows/CI/badge.svg)](https://github.com/wbotelhos/rspeed/actions)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/rspeed.svg)](https://badge.fury.io/rb/rspeed)
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
6
|
-
[![
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/f312587b4f126bb13e85/maintainability)](https://codeclimate.com/github/wbotelhos/rspeed/maintainability)
|
6
|
+
[![Coverage](https://codecov.io/gh/wbotelhos/rspeed/branch/main/graph/badge.svg)](https://codecov.io/gh/wbotelhos/rspeed)
|
7
|
+
[![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://www.patreon.com/wbotelhos)
|
7
8
|
|
8
9
|
RSpeed splits your specs to you run parallels tests.
|
9
10
|
|
@@ -25,19 +26,21 @@ rake rspeed:install
|
|
25
26
|
|
26
27
|
## Usage
|
27
28
|
|
28
|
-
- `
|
29
|
-
- `RSPEED_PIPES`: Quantity of pipes
|
29
|
+
- `RSPEED_APP`: You app name to avoid data override
|
30
30
|
- `RSPEED_PIPE`: Current pipe
|
31
|
+
- `RSPEED_PIPES`: Quantity of pipes
|
32
|
+
- `RSPEED_SPEC_PATH`: The specs folders path
|
33
|
+
- `RSPEED`: Enables RSpeed
|
31
34
|
|
32
35
|
```sh
|
33
|
-
RSPEED=true
|
36
|
+
RSPEED=true RSPEED_APP=blog RSPEED_PIPE=1 RSPEED_PIPES=3 bundle exec rake rspeed:run
|
34
37
|
```
|
35
38
|
|
36
39
|
## How it Works
|
37
40
|
|
38
41
|
### First run
|
39
42
|
|
40
|
-
1. Since we
|
43
|
+
1. Since we have no statistics on the first time, we run all specs and collect it;
|
41
44
|
|
42
45
|
```json
|
43
46
|
{ "file": "./spec/models/1_spec.rb", "time": 0.01 }
|
data/lib/rspeed.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RSpeed
|
4
|
-
require '
|
5
|
-
require '
|
4
|
+
require 'rspeed/database'
|
5
|
+
require 'rspeed/env'
|
6
|
+
require 'rspeed/extension'
|
7
|
+
require 'rspeed/logger'
|
8
|
+
require 'rspeed/observer'
|
9
|
+
require 'rspeed/redis'
|
10
|
+
require 'rspeed/runner'
|
11
|
+
require 'rspeed/splitter'
|
12
|
+
require 'rspeed/variable'
|
6
13
|
end
|
7
|
-
|
8
|
-
require 'rspeed/extension'
|
9
|
-
require 'rspeed/observer'
|
10
|
-
require 'rspeed/runner'
|
11
|
-
require 'rspeed/splitter'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpeed
|
4
|
+
module Differ
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def actual_files(spec_path: RSpeed::Env.spec_path)
|
8
|
+
[].tap do |data|
|
9
|
+
Dir[spec_path].sort.each do |file|
|
10
|
+
lines = File.open(file).read.split("\n")
|
11
|
+
|
12
|
+
lines&.each&.with_index do |item, index|
|
13
|
+
data << "#{file}:#{index + 1}" if /^it/.match?(item.gsub(/\s+/, ''))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpeed::Logger.log(self, __method__, data)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def actual_data(files:, result:)
|
22
|
+
result
|
23
|
+
.select { |item| files.include?(item[:file]) }
|
24
|
+
.tap { |data| RSpeed::Logger.log(self, __method__, data) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def added_data(files:, result:)
|
28
|
+
(files - result.map { |item| item[:file] })
|
29
|
+
.map { |file| { file: file, time: 0 } }
|
30
|
+
.tap { |data| RSpeed::Logger.log(self, __method__, data) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def diff
|
34
|
+
files = actual_files
|
35
|
+
result = RSpeed::Database.result.uniq { |item| item[:file] }
|
36
|
+
|
37
|
+
removed_data(files: files, result: result) # called just for log purpose
|
38
|
+
|
39
|
+
(actual_data(files: files, result: result) + added_data(files: files, result: result))
|
40
|
+
.tap { |data| RSpeed::Logger.log(self, __method__, data) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def removed_data(files:, result:)
|
44
|
+
result
|
45
|
+
.reject { |item| files.include?(item[:file]) }
|
46
|
+
.tap { |data| RSpeed::Logger.log(self, __method__, data) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def removed_time(data:)
|
50
|
+
data
|
51
|
+
.sum { |item| item[:time].to_f }
|
52
|
+
.tap { |result| RSpeed::Logger.log(self, __method__, result) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/rspeed/env.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpeed
|
4
|
+
module Env
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def app
|
8
|
+
ENV['RSPEED_APP']
|
9
|
+
end
|
10
|
+
|
11
|
+
def db
|
12
|
+
ENV['RSPEED_DB']&.to_i
|
13
|
+
end
|
14
|
+
|
15
|
+
def host
|
16
|
+
ENV['RSPEED_HOST']
|
17
|
+
end
|
18
|
+
|
19
|
+
def pipe
|
20
|
+
ENV.fetch('RSPEED_PIPE', 1).to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def pipes
|
24
|
+
ENV.fetch('RSPEED_PIPES', 1).to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
def port
|
28
|
+
ENV['RSPEED_PORT']&.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def rspeed
|
32
|
+
ENV['RSPEED'] == 'true'
|
33
|
+
end
|
34
|
+
|
35
|
+
def spec_path
|
36
|
+
ENV.fetch('RSPEED_SPEC_PATH', './spec/**/*spec.rb')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/rspeed/extension.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if
|
4
|
-
require 'rspec
|
3
|
+
if RSpeed::Env.rspeed
|
4
|
+
require 'rspec'
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
7
|
config.before(:suite) { RSpeed::Observer.before_suite }
|
8
8
|
config.before { |example| RSpeed::Observer.before(example) }
|
9
9
|
config.after { |example| RSpeed::Observer.after(example) }
|
10
|
+
config.after(:suite) { RSpeed::Observer.after_suite }
|
10
11
|
end
|
11
12
|
end
|
data/lib/rspeed/observer.rb
CHANGED
@@ -9,9 +9,21 @@ module RSpeed
|
|
9
9
|
line_number = example.metadata[:line_number]
|
10
10
|
spent_time = example.clock.now - example.metadata[:start_at]
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
json = { file: "#{file_path}:#{line_number}", time: spent_time }.to_json
|
13
|
+
|
14
|
+
RSpeed::Redis.client.rpush(RSpeed::Variable.profile, json)
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_suite
|
18
|
+
RSpeed::Redis.set(RSpeed::Variable.pipe, true)
|
19
|
+
|
20
|
+
return unless RSpeed::Redis.specs_finished?
|
21
|
+
|
22
|
+
RSpeed::Splitter.consolidate
|
23
|
+
|
24
|
+
RSpeed::Redis.clean
|
25
|
+
|
26
|
+
RSpeed::Logger.log(self, __method__, 'RSpeed finished.')
|
15
27
|
end
|
16
28
|
|
17
29
|
def before(example)
|
@@ -19,11 +31,14 @@ module RSpeed
|
|
19
31
|
end
|
20
32
|
|
21
33
|
def before_suite
|
22
|
-
|
34
|
+
clean_profile
|
23
35
|
end
|
24
36
|
|
25
|
-
def
|
26
|
-
|
37
|
+
def clean_profile
|
38
|
+
RSpeed::Logger.log(self, __method__, 'Cleanning current flag and profile.')
|
39
|
+
|
40
|
+
RSpeed::Redis.destroy(pattern: RSpeed::Variable.pipe)
|
41
|
+
RSpeed::Redis.destroy(pattern: RSpeed::Variable.profile)
|
27
42
|
end
|
28
43
|
end
|
29
44
|
end
|
data/lib/rspeed/redis.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpeed
|
4
|
+
module Redis
|
5
|
+
require 'redis'
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def clean
|
10
|
+
RSpeed::Logger.log(self, __method__, 'Cleaning pipes and profiles.')
|
11
|
+
|
12
|
+
destroy(pattern: RSpeed::Variable::PIPES_PATTERN)
|
13
|
+
destroy(pattern: RSpeed::Variable::PROFILE_PATTERN)
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
@client ||= ::Redis.new(db: RSpeed::Env.db, host: RSpeed::Env.host, port: RSpeed::Env.port)
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy(pattern:)
|
21
|
+
RSpeed::Logger.log(self, __method__, %(Destroying pattern "#{pattern}".))
|
22
|
+
|
23
|
+
keys(pattern: pattern).each { |key| client.del(key) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(key)
|
27
|
+
client.get(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def keys(pattern:)
|
31
|
+
cursor = 0
|
32
|
+
result = []
|
33
|
+
|
34
|
+
loop do
|
35
|
+
cursor, results = client.scan(cursor, match: pattern)
|
36
|
+
result += results
|
37
|
+
|
38
|
+
break if cursor.to_i.zero?
|
39
|
+
end
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
def list(key)
|
45
|
+
client.lrange(key, 0, -1)
|
46
|
+
end
|
47
|
+
|
48
|
+
def profiles_content(pattern: 'rspeed:profile_*')
|
49
|
+
client.keys(pattern).map { |key| list(key) }.flatten
|
50
|
+
end
|
51
|
+
|
52
|
+
def result?
|
53
|
+
keys(pattern: RSpeed::Variable.result).any?
|
54
|
+
end
|
55
|
+
|
56
|
+
def set(key, value)
|
57
|
+
client.set(key, value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def specs_finished?
|
61
|
+
(RSpeed::Redis.keys(pattern: RSpeed::Variable::PIPES_PATTERN).size == RSpeed::Env.pipes).tap do |boo|
|
62
|
+
RSpeed::Logger.log(self, __method__, "Specs #{boo ? 'finished.' : 'not fineshed yet.'}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def specs_initiated?
|
67
|
+
RSpeed::Redis.keys(pattern: RSpeed::Variable::PIPES_PATTERN).any?.tap do |boo|
|
68
|
+
RSpeed::Logger.log(self, __method__, "Specs #{boo ? 'initialized.' : 'not initialized yet.'}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/rspeed/runner.rb
CHANGED
@@ -5,24 +5,13 @@ module RSpeed
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
def run(shell)
|
8
|
-
|
9
|
-
|
10
|
-
if splitter.first_pipe?
|
11
|
-
# splitter.destroy "rspeed_*"
|
12
|
-
splitter.destroy 'rspeed_tmp'
|
8
|
+
if RSpeed::Redis.result? || RSpeed::Splitter.first_pipe?
|
9
|
+
return shell.call(['bundle exec rspec', RSpeed::Splitter.pipe_files].compact.join(' '))
|
13
10
|
end
|
14
11
|
|
15
|
-
|
16
|
-
splitter.save if splitter.first_pipe?
|
17
|
-
|
18
|
-
files = splitter.get("rspeed_#{splitter.pipe}")[0]['files'].map { |item| item['file'] }.join(' ')
|
19
|
-
end
|
20
|
-
|
21
|
-
shell.call ['bundle exec rspec', files].compact.join(' ')
|
22
|
-
|
23
|
-
splitter.append
|
12
|
+
RSpeed::Logger.log(self, __method__, "Skipped! Only Pipe 1 can warm.")
|
24
13
|
|
25
|
-
|
14
|
+
RSpeed::Observer.after_suite
|
26
15
|
end
|
27
16
|
end
|
28
17
|
end
|
data/lib/rspeed/splitter.rb
CHANGED
@@ -1,85 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module RSpeed
|
3
|
-
|
4
|
-
|
4
|
+
module Splitter
|
5
|
+
module_function
|
5
6
|
|
6
|
-
|
7
|
-
files.each do |time, file|
|
8
|
-
redis.lpush('rspeed_tmp', { file: file, time: time.to_f }.to_json)
|
9
|
-
end
|
10
|
-
end
|
7
|
+
require 'json'
|
11
8
|
|
12
|
-
|
13
|
-
keys(pattern).each { |key| redis.del key }
|
14
|
-
end
|
9
|
+
require 'rspeed/differ'
|
15
10
|
|
16
|
-
def
|
17
|
-
|
11
|
+
def append(items:, key:)
|
12
|
+
items.each { |item| RSpeed::Redis.client.rpush(key, item) }
|
18
13
|
end
|
19
14
|
|
20
|
-
def
|
21
|
-
|
22
|
-
end
|
15
|
+
def consolidate
|
16
|
+
RSpeed::Logger.log(self, __method__, 'Consolidating profiles.')
|
23
17
|
|
24
|
-
|
25
|
-
@get ||= begin
|
26
|
-
return redis.lrange(pattern, 0, -1) if %w[rspeed rspeed_tmp].include?(pattern)
|
18
|
+
RSpeed::Redis.destroy(pattern: RSpeed::Variable.result)
|
27
19
|
|
28
|
-
|
29
|
-
end
|
20
|
+
append(items: RSpeed::Redis.profiles_content, key: RSpeed::Variable.result)
|
30
21
|
end
|
31
22
|
|
32
|
-
def
|
33
|
-
|
34
|
-
result = []
|
35
|
-
|
36
|
-
loop do
|
37
|
-
cursor, results = redis.scan(cursor, match: pattern)
|
38
|
-
result += results
|
39
|
-
|
40
|
-
break if cursor.to_i.zero?
|
41
|
-
end
|
42
|
-
|
43
|
-
result
|
23
|
+
def first_pipe?
|
24
|
+
RSpeed::Env.pipe == 1
|
44
25
|
end
|
45
26
|
|
46
|
-
def
|
47
|
-
|
27
|
+
def need_warm?
|
28
|
+
first_pipe? && !RSpeed::Redis.result?
|
48
29
|
end
|
49
30
|
|
50
|
-
def
|
51
|
-
|
52
|
-
end
|
31
|
+
def pipe_files
|
32
|
+
return unless RSpeed::Redis.result?
|
53
33
|
|
54
|
-
|
55
|
-
result? ? ENV.fetch('RSPEED_PIPES') { 1 }.to_i : 1
|
56
|
-
end
|
57
|
-
|
58
|
-
def rename
|
59
|
-
redis.rename('rspeed_tmp', 'rspeed')
|
60
|
-
end
|
34
|
+
splitted = split(data: RSpeed::Differ.diff)
|
61
35
|
|
62
|
-
|
63
|
-
!keys('rspeed').empty?
|
36
|
+
splitted[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].map { |item| item[:file] }.join(' ')
|
64
37
|
end
|
65
38
|
|
66
|
-
def
|
67
|
-
split(data).each { |key, value| redis.set(key, value.to_json) }
|
68
|
-
end
|
69
|
-
|
70
|
-
def split(data)
|
39
|
+
def split(data:)
|
71
40
|
json = {}
|
72
41
|
|
73
|
-
pipes.times do |index|
|
74
|
-
json[
|
75
|
-
json[
|
42
|
+
RSpeed::Env.pipes.times do |index|
|
43
|
+
json[RSpeed::Variable.key(index + 1)] ||= []
|
44
|
+
json[RSpeed::Variable.key(index + 1)] = { total: 0, files: [], number: index + 1 }
|
76
45
|
end
|
77
46
|
|
78
47
|
sorted_data = data.sort_by { |item| item[:time] }.reverse
|
79
48
|
|
80
49
|
sorted_data.each do |record|
|
81
50
|
selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
|
82
|
-
selected_pipe = json[
|
51
|
+
selected_pipe = json[RSpeed::Variable.key(selected_pipe_data[1][:number])]
|
83
52
|
time = record[:time].to_f
|
84
53
|
|
85
54
|
selected_pipe[:total] += time
|
@@ -88,47 +57,5 @@ module RSpeed
|
|
88
57
|
|
89
58
|
json
|
90
59
|
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def actual_data
|
95
|
-
rspeed_data.select { |item| actual_files.include?(item[:file]) }
|
96
|
-
end
|
97
|
-
|
98
|
-
def actual_files
|
99
|
-
@actual_files ||= Dir['./spec/**/*_spec.rb']
|
100
|
-
end
|
101
|
-
|
102
|
-
def added_data
|
103
|
-
added_specs.map { |item| { file: item, time: 0 } }
|
104
|
-
end
|
105
|
-
|
106
|
-
def added_specs
|
107
|
-
actual_files - old_files
|
108
|
-
end
|
109
|
-
|
110
|
-
def file_data
|
111
|
-
CSV.read('rspeed.csv')
|
112
|
-
end
|
113
|
-
|
114
|
-
def old_files
|
115
|
-
rspeed_data.map { |item| item[:file] }
|
116
|
-
end
|
117
|
-
|
118
|
-
def redis
|
119
|
-
@redis ||= ::Redis.new(db: ENV['RSPEED_DB'], host: ENV['RSPEED_HOST'], port: ENV.fetch('RSPEED_PORT') { 6379 })
|
120
|
-
end
|
121
|
-
|
122
|
-
def removed_specs
|
123
|
-
old_files - actual_files
|
124
|
-
end
|
125
|
-
|
126
|
-
def removed_time
|
127
|
-
removed_specs.map { |item| item[0].to_f }.sum
|
128
|
-
end
|
129
|
-
|
130
|
-
def rspeed_data
|
131
|
-
@rspeed_data ||= get('rspeed').map { |item| JSON.parse(item, symbolize_names: true) }
|
132
|
-
end
|
133
60
|
end
|
134
61
|
end
|