rspeed 0.1.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/README.md +11 -7
- data/lib/generators/rspeed/install_generator.rb +1 -1
- data/lib/rspeed.rb +9 -5
- data/lib/rspeed/env.rb +43 -0
- data/lib/rspeed/extension.rb +6 -37
- data/lib/rspeed/logger.rb +11 -0
- data/lib/rspeed/observer.rb +43 -0
- data/lib/rspeed/redis.rb +55 -0
- data/lib/rspeed/runner.rb +4 -17
- data/lib/rspeed/splitter.rb +65 -73
- data/lib/rspeed/variable.rb +31 -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/fixtures/new_spec.rb.csv +1 -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/name_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/result_key_spec.rb +19 -0
- data/spec/models/rspeed/env/rspeed_spec.rb +43 -0
- data/spec/models/rspeed/env/tmp_spec.rb +19 -0
- data/spec/models/rspeed/observer/after_spec.rb +16 -0
- data/spec/models/rspeed/observer/after_suite_spec.rb +70 -0
- data/spec/models/rspeed/observer/before_spec.rb +15 -0
- data/spec/models/rspeed/observer/before_suite_spec.rb +37 -0
- data/spec/models/rspeed/redis/clean_spec.rb +12 -0
- data/spec/models/rspeed/redis/client_spec.rb +7 -0
- data/spec/models/rspeed/redis/destroy_spec.rb +29 -0
- data/spec/models/rspeed/redis/get_spec.rb +9 -0
- data/spec/models/rspeed/redis/keys_spec.rb +29 -0
- data/spec/models/rspeed/redis/result_spec.rb +13 -0
- data/spec/models/rspeed/redis/set_spec.rb +9 -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 +47 -0
- data/spec/models/rspeed/splitter/actual_examples_spec.rb +26 -0
- data/spec/models/rspeed/splitter/append_question_spec.rb +37 -0
- data/spec/models/rspeed/splitter/append_spec.rb +6 -3
- data/spec/models/rspeed/splitter/diff_spec.rb +15 -14
- data/spec/models/rspeed/splitter/first_pipe_spec.rb +2 -4
- data/spec/models/rspeed/splitter/get_spec.rb +7 -9
- data/spec/models/rspeed/splitter/need_warm_question_spec.rb +37 -0
- data/spec/models/rspeed/splitter/pipe_files_spec.rb +26 -0
- data/spec/models/rspeed/splitter/rename_spec.rb +3 -5
- data/spec/models/rspeed/splitter/split_spec.rb +72 -36
- data/spec/models/rspeed/variable/append_name_spec.rb +19 -0
- data/spec/models/rspeed/variable/csv_spec.rb +5 -0
- data/spec/models/rspeed/variable/default_partner_spec.rb +5 -0
- data/spec/models/rspeed/variable/key_spec.rb +15 -0
- data/spec/models/rspeed/variable/pipe_name_spec.rb +15 -0
- data/spec/models/rspeed/variable/pipes_pattern_spec.rb +5 -0
- data/spec/models/rspeed/variable/result_spec.rb +19 -0
- data/spec/models/rspeed/variable/tmp_spec.rb +15 -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 +155 -20
- data/spec/models/rspeed/splitter/destroy_spec.rb +0 -33
- 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/result_spec.rb +0 -19
- data/spec/models/rspeed/splitter/save_spec.rb +0 -55
- data/spec/rails_helper.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de6e5d6c3ca630b15b835939ec2b01adbeec526480efde16052c294f297457af
|
4
|
+
data.tar.gz: 4c4d1efdf65c9f4c01106f1fe109d8ffb2160e40b6f90813b4bdc813061613dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ab45f421853bee217c88cfad0efd5d2bd16b9968b17b7676593b4ae0a2e708ac6b646f40845b8f186adfc000c505cef4e95f77c7c8273e6964203b0de22420a
|
7
|
+
data.tar.gz: 7e32c34c76fcdaff18e2aa2726c232d42c32fb4e3fc55b452f0d9b62f2dff0e5f458acd4c3dbacae75b5ca0c330e4b2792618179675c11adcf8aa566d13106c9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
## master
|
2
|
+
|
3
|
+
- None;
|
4
|
+
|
5
|
+
## v0.5.1
|
6
|
+
|
7
|
+
#### Fix
|
8
|
+
|
9
|
+
- Only pipe number 1 will warm up avoiding duplicated spec entries;
|
10
|
+
|
11
|
+
## v0.5.0
|
12
|
+
|
13
|
+
#### Fix
|
14
|
+
|
15
|
+
- Add env `RSPEED_NAME` to specify the application name and avoid result conflicts between multiple runs;
|
16
|
+
- No more depends on pipe sequence to generate ou aggregate the resul;
|
17
|
+
- rake `rspeed:install`;
|
18
|
+
|
19
|
+
#### Update
|
20
|
+
|
21
|
+
- The result of the pipes are no more saved on Redis. It's now calculated based on result key `rspeed`;
|
22
|
+
|
23
|
+
## v0.4.0
|
24
|
+
|
25
|
+
- Now we make diff to discover removed and added examples;
|
26
|
+
|
27
|
+
## v0.3.0
|
28
|
+
|
29
|
+
- Removed and added files now is considered on run;
|
30
|
+
|
31
|
+
## v0.2.0
|
32
|
+
|
33
|
+
- Splits specs by examples over files;
|
34
|
+
|
1
35
|
## v0.1.0
|
2
36
|
|
3
37
|
- First release;
|
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,22 @@ rake rspeed:install
|
|
25
26
|
|
26
27
|
## Usage
|
27
28
|
|
28
|
-
- `
|
29
|
-
- `RSPEED_PIPES`: Quantity of pipes
|
29
|
+
- `RSPEED_NAME`: You app name to avoid data override
|
30
30
|
- `RSPEED_PIPE`: Current pipe
|
31
|
+
- `RSPEED_PIPES`: Quantity of pipes
|
32
|
+
- `RSPEED_RESULT_KEY`: The key that keeps the final result of all pipes
|
33
|
+
- `RSPEED_TMP_KEY`: The temporary key that keeps the partial result of the pipes
|
34
|
+
- `RSPEED`: Enables RSpeed
|
31
35
|
|
32
36
|
```sh
|
33
|
-
RSPEED=true
|
37
|
+
RSPEED=true RSPEED_NAME=authorizy RSPEED_PIPE=1 RSPEED_PIPES=3 bundle exec rake rspeed:run
|
34
38
|
```
|
35
39
|
|
36
40
|
## How it Works
|
37
41
|
|
38
42
|
### First run
|
39
43
|
|
40
|
-
1. Since we
|
44
|
+
1. Since we have no statistics on the first time, we run all specs and collect it;
|
41
45
|
|
42
46
|
```json
|
43
47
|
{ "file": "./spec/models/1_spec.rb", "time": 0.01 }
|
data/lib/rspeed.rb
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
module RSpeed
|
4
4
|
require 'csv'
|
5
|
-
require 'redis'
|
6
|
-
end
|
7
5
|
|
8
|
-
require 'rspeed/
|
9
|
-
require 'rspeed/
|
10
|
-
require 'rspeed/
|
6
|
+
require 'rspeed/env'
|
7
|
+
require 'rspeed/extension'
|
8
|
+
require 'rspeed/logger'
|
9
|
+
require 'rspeed/observer'
|
10
|
+
require 'rspeed/redis'
|
11
|
+
require 'rspeed/runner'
|
12
|
+
require 'rspeed/splitter'
|
13
|
+
require 'rspeed/variable'
|
14
|
+
end
|
data/lib/rspeed/env.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpeed
|
4
|
+
module Env
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def db
|
8
|
+
ENV['RSPEED_DB']&.to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
def host
|
12
|
+
ENV['RSPEED_HOST']
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
ENV['RSPEED_NAME']
|
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 result_key
|
32
|
+
ENV.fetch('RESPEED_RESULT_KEY', RSpeed::Variable.result)
|
33
|
+
end
|
34
|
+
|
35
|
+
def rspeed
|
36
|
+
ENV['RSPEED'] == 'true'
|
37
|
+
end
|
38
|
+
|
39
|
+
def tmp_key
|
40
|
+
ENV.fetch('RESPEED_TMP_KEY', RSpeed::Variable.tmp)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/rspeed/extension.rb
CHANGED
@@ -1,43 +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
|
-
config.before
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
config.before do |example|
|
12
|
-
example.update_inherited_metadata start_at: example.clock.now
|
13
|
-
end
|
14
|
-
|
15
|
-
config.after do |example|
|
16
|
-
file_path = example.metadata[:file_path]
|
17
|
-
time_difference = example.clock.now - example.metadata[:start_at]
|
18
|
-
|
19
|
-
File.open('rspeed.csv', 'a') do |file|
|
20
|
-
file.write "#{time_difference},#{file_path}\n"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
config.after :suite do |_example|
|
25
|
-
result = {}
|
26
|
-
|
27
|
-
CSV.read('rspeed.csv').each do |line|
|
28
|
-
result[line[1]] ||= 0
|
29
|
-
result[line[1]] += line[0].to_d
|
30
|
-
end
|
31
|
-
|
32
|
-
result = result.sort_by { |line| line[1] }.reverse
|
33
|
-
|
34
|
-
File.open('rspeed.csv', 'w') { |file| file.truncate 0 }
|
35
|
-
|
36
|
-
File.open('rspeed.csv', 'a') do |file|
|
37
|
-
result.each do |file_spec, time|
|
38
|
-
file.write "#{time},#{file_spec}\n"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
7
|
+
config.before(:suite) { RSpeed::Observer.before_suite }
|
8
|
+
config.before { |example| RSpeed::Observer.before(example) }
|
9
|
+
config.after { |example| RSpeed::Observer.after(example) }
|
10
|
+
config.after(:suite) { RSpeed::Observer.after_suite }
|
42
11
|
end
|
43
12
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpeed
|
4
|
+
module Observer
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def after(example)
|
8
|
+
file_path = example.metadata[:file_path]
|
9
|
+
line_number = example.metadata[:line_number]
|
10
|
+
spent_time = example.clock.now - example.metadata[:start_at]
|
11
|
+
|
12
|
+
File.open(RSpeed::Variable::CSV, 'a') do |file|
|
13
|
+
file.write("#{spent_time},#{file_path}:#{line_number}\n")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_suite(splitter = ::RSpeed::Splitter.new)
|
18
|
+
RSpeed::Redis.set(RSpeed::Variable.pipe_name, true)
|
19
|
+
|
20
|
+
splitter.append if splitter.append?
|
21
|
+
|
22
|
+
return unless RSpeed::Redis.specs_finished?
|
23
|
+
|
24
|
+
splitter.rename
|
25
|
+
|
26
|
+
RSpeed::Redis.clean
|
27
|
+
end
|
28
|
+
|
29
|
+
def before(example)
|
30
|
+
example.update_inherited_metadata(start_at: example.clock.now)
|
31
|
+
end
|
32
|
+
|
33
|
+
def before_suite
|
34
|
+
truncate_csv_file
|
35
|
+
|
36
|
+
RSpeed::Redis.destroy(RSpeed::Variable.tmp) unless RSpeed::Redis.specs_initiated?
|
37
|
+
end
|
38
|
+
|
39
|
+
def truncate_csv_file
|
40
|
+
File.open(RSpeed::Variable::CSV, 'w') { |file| file.truncate(0) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/rspeed/redis.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpeed
|
4
|
+
module Redis
|
5
|
+
require 'redis'
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def clean
|
10
|
+
destroy(RSpeed::Variable::PIPES_PATTERN)
|
11
|
+
end
|
12
|
+
|
13
|
+
def client
|
14
|
+
@client ||= ::Redis.new(db: RSpeed::Env.db, host: RSpeed::Env.host, port: RSpeed::Env.port)
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy(pattern = RSpeed::Variable::DEFAULT_PATTERN)
|
18
|
+
keys(pattern).each { |key| client.del(key) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(key)
|
22
|
+
client.get(key)
|
23
|
+
end
|
24
|
+
|
25
|
+
def keys(pattern = RSpeed::Variable::DEFAULT_PATTERN)
|
26
|
+
cursor = 0
|
27
|
+
result = []
|
28
|
+
|
29
|
+
loop do
|
30
|
+
cursor, results = client.scan(cursor, match: pattern)
|
31
|
+
result += results
|
32
|
+
|
33
|
+
break if cursor.to_i.zero?
|
34
|
+
end
|
35
|
+
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
def result?
|
40
|
+
keys(RSpeed::Env.result_key).any?
|
41
|
+
end
|
42
|
+
|
43
|
+
def set(key, value)
|
44
|
+
client.set(key, value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def specs_finished?
|
48
|
+
RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).size == RSpeed::Env.pipes
|
49
|
+
end
|
50
|
+
|
51
|
+
def specs_initiated?
|
52
|
+
RSpeed::Redis.keys(RSpeed::Variable::PIPES_PATTERN).any?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/rspeed/runner.rb
CHANGED
@@ -4,25 +4,12 @@ module RSpeed
|
|
4
4
|
module Runner
|
5
5
|
module_function
|
6
6
|
|
7
|
-
def run(shell)
|
8
|
-
splitter
|
7
|
+
def run(shell, splitter: ::RSpeed::Splitter.new)
|
8
|
+
return shell.call(['bundle exec rspec', splitter.pipe_files].compact.join(' ')) if splitter.need_warm?
|
9
9
|
|
10
|
-
|
11
|
-
# splitter.destroy "rspeed_*"
|
12
|
-
splitter.destroy 'rspeed_tmp'
|
13
|
-
end
|
10
|
+
RSpeed::Logger.log("Pipe #{RSpeed::Env.pipe} skipped. Only Pipe 1 can warm.")
|
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
|
24
|
-
|
25
|
-
splitter.rename if splitter.last_pipe?
|
12
|
+
RSpeed::Observer.after_suite
|
26
13
|
end
|
27
14
|
end
|
28
15
|
end
|
data/lib/rspeed/splitter.rb
CHANGED
@@ -2,87 +2,87 @@
|
|
2
2
|
|
3
3
|
module RSpeed
|
4
4
|
class Splitter
|
5
|
-
|
5
|
+
require 'json'
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
redis.lpush 'rspeed_tmp', { file: file, time: time.to_f }.to_json
|
10
|
-
end
|
7
|
+
def initialize(specs_path: './spec/**/*_spec.rb')
|
8
|
+
@specs_path = specs_path
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
11
|
+
def actual_examples
|
12
|
+
@actual_examples ||= begin
|
13
|
+
[].tap do |examples|
|
14
|
+
Dir[@specs_path].sort.each do |file|
|
15
|
+
data = File.open(file).read
|
16
|
+
lines = data.split("\n")
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
lines&.each&.with_index do |item, index|
|
19
|
+
examples << "#{file}:#{index + 1}" if /^it/.match?(item.gsub(/\s+/, ''))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
stream(:actual_examples, examples)
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
23
|
-
def
|
24
|
-
|
28
|
+
def append?
|
29
|
+
RSpeed::Redis.result? || first_pipe?
|
25
30
|
end
|
26
31
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
keys(pattern).map { |key| JSON.parse redis.get(key) }
|
32
|
+
def append(files = CSV.read(RSpeed::Variable::CSV))
|
33
|
+
files.each do |time, file|
|
34
|
+
redis.lpush(RSpeed::Env.tmp_key, { file: file, time: time.to_f }.to_json)
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
+
def diff
|
39
|
+
actual_data = rspeed_data.select { |item| actual_examples.include?(item[:file]) }
|
40
|
+
added_data = added_examples.map { |item| { file: item, time: 0 } }
|
38
41
|
|
39
|
-
|
40
|
-
cursor, results = redis.scan(cursor, match: pattern)
|
41
|
-
result += results
|
42
|
+
removed_examples # called just for stream for now
|
42
43
|
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
result
|
44
|
+
actual_data + added_data
|
47
45
|
end
|
48
46
|
|
49
|
-
def
|
50
|
-
pipe ==
|
47
|
+
def first_pipe?
|
48
|
+
RSpeed::Env.pipe == 1
|
51
49
|
end
|
52
50
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
51
|
+
def get(pattern)
|
52
|
+
@get ||= begin
|
53
|
+
return redis.lrange(pattern, 0, -1) if [RSpeed::Variable.result, RSpeed::Variable.tmp].include?(pattern)
|
56
54
|
|
57
|
-
|
58
|
-
|
55
|
+
RSpeed::Redis.keys(pattern).map { |key| ::JSON.parse(redis.get(key)) }
|
56
|
+
end
|
59
57
|
end
|
60
58
|
|
61
|
-
def
|
62
|
-
|
59
|
+
def need_warm?
|
60
|
+
first_pipe? && !RSpeed::Redis.result?
|
63
61
|
end
|
64
62
|
|
65
|
-
def
|
66
|
-
|
63
|
+
def pipe_files
|
64
|
+
return unless RSpeed::Redis.result?
|
65
|
+
|
66
|
+
split[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].map { |item| item[:file] }.join(' ')
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
70
|
-
|
71
|
-
redis.set key, value.to_json
|
72
|
-
end
|
69
|
+
def rename
|
70
|
+
redis.rename(RSpeed::Env.tmp_key, RSpeed::Env.result_key)
|
73
71
|
end
|
74
72
|
|
75
|
-
def split(data)
|
73
|
+
def split(data = diff)
|
76
74
|
json = {}
|
77
75
|
|
78
|
-
pipes.times do |index|
|
79
|
-
json[
|
80
|
-
json[
|
76
|
+
RSpeed::Env.pipes.times do |index|
|
77
|
+
json[RSpeed::Variable.key(index + 1)] ||= []
|
78
|
+
json[RSpeed::Variable.key(index + 1)] = { total: 0, files: [], number: index + 1 }
|
81
79
|
end
|
82
80
|
|
83
|
-
data.
|
81
|
+
sorted_data = data.sort_by { |item| item[:time] }.reverse
|
82
|
+
|
83
|
+
sorted_data.each do |record|
|
84
84
|
selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
|
85
|
-
selected_pipe = json[
|
85
|
+
selected_pipe = json[RSpeed::Variable.key(selected_pipe_data[1][:number])]
|
86
86
|
time = record[:time].to_f
|
87
87
|
|
88
88
|
selected_pipe[:total] += time
|
@@ -94,44 +94,36 @@ module RSpeed
|
|
94
94
|
|
95
95
|
private
|
96
96
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def actual_specs
|
102
|
-
Dir['./spec/**/*_spec.rb']
|
103
|
-
end
|
104
|
-
|
105
|
-
def added_files
|
106
|
-
added_specs.map { |item| { file: item, time: 0 } }
|
107
|
-
end
|
108
|
-
|
109
|
-
def added_specs
|
110
|
-
actual_specs - saved_specs
|
111
|
-
end
|
112
|
-
|
113
|
-
def file_data
|
114
|
-
CSV.read('rspeed.csv')
|
97
|
+
def added_examples
|
98
|
+
@added_examples ||= begin
|
99
|
+
(actual_examples - rspeed_examples).tap { |examples| stream(:added_examples, examples) }
|
100
|
+
end
|
115
101
|
end
|
116
102
|
|
117
103
|
def redis
|
118
|
-
@redis ||= ::Redis.
|
104
|
+
@redis ||= ::RSpeed::Redis.client
|
119
105
|
end
|
120
106
|
|
121
|
-
def
|
122
|
-
|
107
|
+
def removed_examples
|
108
|
+
@removed_examples ||= begin
|
109
|
+
(rspeed_examples - actual_examples).tap { |examples| stream(:removed_examples, examples) }
|
110
|
+
end
|
123
111
|
end
|
124
112
|
|
125
113
|
def removed_time
|
126
|
-
|
114
|
+
removed_examples.sum { |item| item[0].to_f }
|
127
115
|
end
|
128
116
|
|
129
117
|
def rspeed_data
|
130
|
-
get(
|
118
|
+
@rspeed_data ||= get(RSpeed::Env.result_key).map { |item| JSON.parse(item, symbolize_names: true) }
|
131
119
|
end
|
132
120
|
|
133
|
-
def
|
121
|
+
def rspeed_examples
|
134
122
|
rspeed_data.map { |item| item[:file] }
|
135
123
|
end
|
124
|
+
|
125
|
+
def stream(type, data)
|
126
|
+
RSpeed::Logger.log("PIPE: #{RSpeed::Env.pipe} with #{type}: #{data}")
|
127
|
+
end
|
136
128
|
end
|
137
129
|
end
|