rspeed 0.5.0 → 0.5.1

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: c2d2d14366ee70f0cf449f6fbf6bc6c7cedd57edc8497b646721afa4b098720a
4
- data.tar.gz: 0ac5789e67ba474055620780a0311525bbe29c801b2c09344218888b33de55ac
3
+ metadata.gz: de6e5d6c3ca630b15b835939ec2b01adbeec526480efde16052c294f297457af
4
+ data.tar.gz: 4c4d1efdf65c9f4c01106f1fe109d8ffb2160e40b6f90813b4bdc813061613dc
5
5
  SHA512:
6
- metadata.gz: 00adb24277015b707cfbd1d5ea0f2cd9b220701344654a107471ab6683ea4876830a34cb34262a42b425078a5dab85efaee16cb2252da1027b807a3409eb22ac
7
- data.tar.gz: aa4932a206cd9a5ab93e4b4217099ebad1a110b8ee9d48c6c0dd9addaf9073d561249480cfe1f74137f484c27a649b05afc4720fde679abb825ef43ba59feb4a
6
+ metadata.gz: 5ab45f421853bee217c88cfad0efd5d2bd16b9968b17b7676593b4ae0a2e708ac6b646f40845b8f186adfc000c505cef4e95f77c7c8273e6964203b0de22420a
7
+ data.tar.gz: 7e32c34c76fcdaff18e2aa2726c232d42c32fb4e3fc55b452f0d9b62f2dff0e5f458acd4c3dbacae75b5ca0c330e4b2792618179675c11adcf8aa566d13106c9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  - None;
4
4
 
5
+ ## v0.5.1
6
+
7
+ #### Fix
8
+
9
+ - Only pipe number 1 will warm up avoiding duplicated spec entries;
10
+
5
11
  ## v0.5.0
6
12
 
7
13
  #### Fix
data/lib/rspeed.rb CHANGED
@@ -5,6 +5,7 @@ module RSpeed
5
5
 
6
6
  require 'rspeed/env'
7
7
  require 'rspeed/extension'
8
+ require 'rspeed/logger'
8
9
  require 'rspeed/observer'
9
10
  require 'rspeed/redis'
10
11
  require 'rspeed/runner'
data/lib/rspeed/env.rb CHANGED
@@ -21,7 +21,7 @@ module RSpeed
21
21
  end
22
22
 
23
23
  def pipes
24
- RSpeed::Redis.result? ? ENV.fetch('RSPEED_PIPES', 1).to_i : 1
24
+ ENV.fetch('RSPEED_PIPES', 1).to_i
25
25
  end
26
26
 
27
27
  def port
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpeed
4
+ module Logger
5
+ module_function
6
+
7
+ def log(message)
8
+ puts(message)
9
+ end
10
+ end
11
+ end
@@ -17,13 +17,13 @@ module RSpeed
17
17
  def after_suite(splitter = ::RSpeed::Splitter.new)
18
18
  RSpeed::Redis.set(RSpeed::Variable.pipe_name, true)
19
19
 
20
- splitter.append
20
+ splitter.append if splitter.append?
21
21
 
22
22
  return unless RSpeed::Redis.specs_finished?
23
23
 
24
24
  splitter.rename
25
25
 
26
- RSpeed::Redis.clean_pipes_flag
26
+ RSpeed::Redis.clean
27
27
  end
28
28
 
29
29
  def before(example)
data/lib/rspeed/redis.rb CHANGED
@@ -6,7 +6,7 @@ module RSpeed
6
6
 
7
7
  module_function
8
8
 
9
- def clean_pipes_flag
9
+ def clean
10
10
  destroy(RSpeed::Variable::PIPES_PATTERN)
11
11
  end
12
12
 
data/lib/rspeed/runner.rb CHANGED
@@ -5,9 +5,11 @@ module RSpeed
5
5
  module_function
6
6
 
7
7
  def run(shell, splitter: ::RSpeed::Splitter.new)
8
- return if splitter.redundant_run?
8
+ return shell.call(['bundle exec rspec', splitter.pipe_files].compact.join(' ')) if splitter.need_warm?
9
9
 
10
- shell.call(['bundle exec rspec', splitter.pipe_files].compact.join(' '))
10
+ RSpeed::Logger.log("Pipe #{RSpeed::Env.pipe} skipped. Only Pipe 1 can warm.")
11
+
12
+ RSpeed::Observer.after_suite
11
13
  end
12
14
  end
13
15
  end
@@ -25,6 +25,10 @@ module RSpeed
25
25
  end
26
26
  end
27
27
 
28
+ def append?
29
+ RSpeed::Redis.result? || first_pipe?
30
+ end
31
+
28
32
  def append(files = CSV.read(RSpeed::Variable::CSV))
29
33
  files.each do |time, file|
30
34
  redis.lpush(RSpeed::Env.tmp_key, { file: file, time: time.to_f }.to_json)
@@ -52,16 +56,16 @@ module RSpeed
52
56
  end
53
57
  end
54
58
 
59
+ def need_warm?
60
+ first_pipe? && !RSpeed::Redis.result?
61
+ end
62
+
55
63
  def pipe_files
56
64
  return unless RSpeed::Redis.result?
57
65
 
58
66
  split[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].map { |item| item[:file] }.join(' ')
59
67
  end
60
68
 
61
- def redundant_run?
62
- !first_pipe? && !exists?(RSpeed::Env.result_key)
63
- end
64
-
65
69
  def rename
66
70
  redis.rename(RSpeed::Env.tmp_key, RSpeed::Env.result_key)
67
71
  end
@@ -96,11 +100,6 @@ module RSpeed
96
100
  end
97
101
  end
98
102
 
99
- # TODO: exists? does not work: undefined method `>' for false:FalseClass
100
- def exists?(key)
101
- redis.keys.include?(key)
102
- end
103
-
104
103
  def redis
105
104
  @redis ||= ::RSpeed::Redis.client
106
105
  end
@@ -124,7 +123,7 @@ module RSpeed
124
123
  end
125
124
 
126
125
  def stream(type, data)
127
- puts "PIPE: #{RSpeed::Env.pipe} with #{type}: #{data}"
126
+ RSpeed::Logger.log("PIPE: #{RSpeed::Env.pipe} with #{type}: #{data}")
128
127
  end
129
128
  end
130
129
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpeed
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -3,39 +3,17 @@
3
3
  require 'support/env_mock'
4
4
 
5
5
  RSpec.describe RSpeed::Env, '.pipes' do
6
- context 'when result is false' do
7
- before { allow(RSpeed::Redis).to receive(:result?).and_return(false) }
8
-
9
- context 'when env is setted' do
10
- it 'returns number 1' do
11
- EnvMock.mock(rspeed_pipes: '2') do
12
- expect(described_class.pipes).to be(1)
13
- end
14
- end
15
- end
16
-
17
- context 'when env is not setted' do
18
- it 'returns number 1' do
19
- expect(described_class.pipes).to be(1)
6
+ context 'when env is setted' do
7
+ it 'returns the env value' do
8
+ EnvMock.mock(rspeed_pipes: '2') do
9
+ expect(described_class.pipes).to be(2)
20
10
  end
21
11
  end
22
12
  end
23
13
 
24
- context 'when result is true' do
25
- before { allow(RSpeed::Redis).to receive(:result?).and_return(true) }
26
-
27
- context 'when env is setted' do
28
- it 'returns the env value as integer' do
29
- EnvMock.mock(rspeed_pipes: '2') do
30
- expect(described_class.pipes).to be(2)
31
- end
32
- end
33
- end
34
-
35
- context 'when env is not setted' do
36
- it 'returns number 1' do
37
- expect(described_class.pipes).to be(1)
38
- end
14
+ context 'when env is not setted' do
15
+ it 'returns number 1' do
16
+ expect(described_class.pipes).to be(1)
39
17
  end
40
18
  end
41
19
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe RSpeed::Observer, '.after' do
3
+ RSpec.describe RSpeed::Observer, '.after_suite' do
4
4
  let!(:splitter) { instance_double('RSpeed::Splitter') }
5
5
 
6
6
  before do
@@ -8,27 +8,51 @@ RSpec.describe RSpeed::Observer, '.after' do
8
8
  allow(splitter).to receive(:append)
9
9
  end
10
10
 
11
- context 'when all specs is not finished' do
12
- before { allow(RSpeed::Redis).to receive(:specs_finished?).and_return(false) }
11
+ context 'when append? returns true' do
12
+ before do
13
+ allow(splitter).to receive(:append?).and_return(true)
14
+ allow(splitter).to receive(:rename)
15
+ end
13
16
 
14
- it 'sets true on pipe key to indicates that its finished' do
17
+ it 'appends the time result on tmp key' do
15
18
  described_class.after_suite
16
19
 
17
- expect(RSpeed::Redis.get('rspeed_pipe_1')).to eq('true')
20
+ expect(splitter).to have_received(:append)
21
+ end
22
+ end
23
+
24
+ context 'when append? returns false' do
25
+ before do
26
+ allow(splitter).to receive(:append?).and_return(false)
27
+ allow(splitter).to receive(:rename)
18
28
  end
19
29
 
20
- it 'appends the time result' do
30
+ it 'does not append the time result on tmp key' do
21
31
  described_class.after_suite
22
32
 
23
- expect(splitter).to have_received(:append)
33
+ expect(splitter).not_to have_received(:append)
34
+ end
35
+ end
36
+
37
+ context 'when all specs is not finished' do
38
+ before do
39
+ allow(splitter).to receive(:append?)
40
+ allow(RSpeed::Redis).to receive(:specs_finished?).and_return(false)
41
+ end
42
+
43
+ it 'sets true on pipe key to indicates that its finished' do
44
+ described_class.after_suite
45
+
46
+ expect(RSpeed::Redis.get('rspeed_pipe_1')).to eq('true')
24
47
  end
25
48
  end
26
49
 
27
50
  context 'when all specs finished' do
28
51
  before do
52
+ allow(splitter).to receive(:append?)
29
53
  allow(RSpeed::Redis).to receive(:specs_finished?).and_return(true)
30
54
  allow(splitter).to receive(:rename)
31
- allow(RSpeed::Redis).to receive(:clean_pipes_flag)
55
+ allow(RSpeed::Redis).to receive(:clean)
32
56
  end
33
57
 
34
58
  it 'renames the tmp data to the permanent key result' do
@@ -40,7 +64,7 @@ RSpec.describe RSpeed::Observer, '.after' do
40
64
  it 'destroyes pipe finished flag keys' do
41
65
  described_class.after_suite
42
66
 
43
- expect(RSpeed::Redis).to have_received(:clean_pipes_flag)
67
+ expect(RSpeed::Redis).to have_received(:clean)
44
68
  end
45
69
  end
46
70
  end
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe RSpeed::Redis, '.clean_pipes_flag' do
4
- before do
3
+ RSpec.describe RSpeed::Redis, '.clean' do
4
+ it 'destroys all keys that keeps the pipe finished info' do
5
5
  described_class.set('rspeed_pipe_1', true)
6
6
  described_class.set('rspeed_pipe_2', true)
7
- end
8
7
 
9
- it 'destroy all keys that keeps the pipe finished' do
10
- described_class.clean_pipes_flag
8
+ described_class.clean
11
9
 
12
10
  expect(described_class.keys('*')).to eq([])
13
11
  end
@@ -4,20 +4,31 @@ RSpec.describe RSpeed::Runner, '#run' do
4
4
  let!(:shell) { double('shell') }
5
5
  let!(:splitter) { instance_double('RSpeed::Splitter') }
6
6
 
7
- before { allow(RSpeed::Splitter).to receive(:new).and_return(splitter) }
7
+ before do
8
+ allow(shell).to receive(:call)
9
+ allow(RSpeed::Splitter).to receive(:new).and_return(splitter)
10
+ allow(RSpeed::Observer).to receive(:after_suite)
11
+ end
12
+
13
+ context 'when does not need warm' do
14
+ before { allow(splitter).to receive(:need_warm?).and_return(false) }
8
15
 
9
- context 'when is a redundant run' do
10
- before { allow(splitter).to receive(:redundant_run?).and_return(true) }
16
+ it 'does not run the specs' do
17
+ described_class.run(shell)
11
18
 
12
- it 'aborts the run' do
13
- expect(described_class.run(shell)).to be(nil)
19
+ expect(shell).not_to have_received(:call)
20
+ end
21
+
22
+ it 'executes the after suite to complete the current pipe' do
23
+ described_class.run(shell)
24
+
25
+ expect(RSpeed::Observer).to have_received(:after_suite)
14
26
  end
15
27
  end
16
28
 
17
- context 'when is not a redundant run' do
29
+ context 'when need warm' do
18
30
  before do
19
- allow(splitter).to receive(:redundant_run?).and_return(false)
20
- allow(shell).to receive(:call)
31
+ allow(splitter).to receive(:need_warm?).and_return(true)
21
32
  allow(splitter).to receive(:pipe_files).and_return('spec_1.rb spec_2.rb')
22
33
  end
23
34
 
@@ -26,5 +37,11 @@ RSpec.describe RSpeed::Runner, '#run' do
26
37
 
27
38
  expect(shell).to have_received(:call).with('bundle exec rspec spec_1.rb spec_2.rb')
28
39
  end
40
+
41
+ it 'does not execute the after suite to complete the current pipe' do
42
+ described_class.run(shell)
43
+
44
+ expect(RSpeed::Observer).not_to have_received(:after_suite)
45
+ end
29
46
  end
30
47
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Splitter, '#append?' do
4
+ subject(:splitter) { described_class.new }
5
+
6
+ context 'when has no result' do
7
+ before { allow(RSpeed::Redis).to receive(:result?).and_return(false) }
8
+
9
+ context 'when is not the first pipe' do
10
+ before { allow(splitter).to receive(:first_pipe?).and_return(false) }
11
+
12
+ it { expect(splitter.append?).to be(false) }
13
+ end
14
+
15
+ context 'when is the first pipe' do
16
+ before { allow(splitter).to receive(:first_pipe?).and_return(true) }
17
+
18
+ it { expect(splitter.append?).to be(true) }
19
+ end
20
+ end
21
+
22
+ context 'when has result' do
23
+ before { allow(RSpeed::Redis).to receive(:result?).and_return(true) }
24
+
25
+ context 'when is not the first pipe' do
26
+ before { allow(splitter).to receive(:first_pipe?).and_return(false) }
27
+
28
+ it { expect(splitter.append?).to be(true) }
29
+ end
30
+
31
+ context 'when is the first pipe' do
32
+ before { allow(splitter).to receive(:first_pipe?).and_return(true) }
33
+
34
+ it { expect(splitter.append?).to be(true) }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe RSpeed::Splitter, '#need_warm?' do
4
+ subject(:splitter) { described_class.new }
5
+
6
+ context 'when has no result' do
7
+ before { allow(RSpeed::Redis).to receive(:result?).and_return(false) }
8
+
9
+ context 'when is not the first pipe' do
10
+ before { allow(splitter).to receive(:first_pipe?).and_return(false) }
11
+
12
+ it { expect(splitter.need_warm?).to be(false) }
13
+ end
14
+
15
+ context 'when is the first pipe' do
16
+ before { allow(splitter).to receive(:first_pipe?).and_return(true) }
17
+
18
+ it { expect(splitter.need_warm?).to be(true) }
19
+ end
20
+ end
21
+
22
+ context 'when has result' do
23
+ before { allow(RSpeed::Redis).to receive(:result?).and_return(true) }
24
+
25
+ context 'when is not the first pipe' do
26
+ before { allow(splitter).to receive(:first_pipe?).and_return(false) }
27
+
28
+ it { expect(splitter.need_warm?).to be(false) }
29
+ end
30
+
31
+ context 'when is the first pipe' do
32
+ before { allow(splitter).to receive(:first_pipe?).and_return(true) }
33
+
34
+ it { expect(splitter.need_warm?).to be(false) }
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspeed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-06 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -167,6 +167,7 @@ files:
167
167
  - lib/rspeed.rb
168
168
  - lib/rspeed/env.rb
169
169
  - lib/rspeed/extension.rb
170
+ - lib/rspeed/logger.rb
170
171
  - lib/rspeed/observer.rb
171
172
  - lib/rspeed/redis.rb
172
173
  - lib/rspeed/runner.rb
@@ -191,7 +192,7 @@ files:
191
192
  - spec/models/rspeed/observer/after_suite_spec.rb
192
193
  - spec/models/rspeed/observer/before_spec.rb
193
194
  - spec/models/rspeed/observer/before_suite_spec.rb
194
- - spec/models/rspeed/redis/clean_pipes_flag_spec.rb
195
+ - spec/models/rspeed/redis/clean_spec.rb
195
196
  - spec/models/rspeed/redis/client_spec.rb
196
197
  - spec/models/rspeed/redis/destroy_spec.rb
197
198
  - spec/models/rspeed/redis/get_spec.rb
@@ -202,12 +203,13 @@ files:
202
203
  - spec/models/rspeed/redis/specs_initiated_spec.rb
203
204
  - spec/models/rspeed/runner/run_spec.rb
204
205
  - spec/models/rspeed/splitter/actual_examples_spec.rb
206
+ - spec/models/rspeed/splitter/append_question_spec.rb
205
207
  - spec/models/rspeed/splitter/append_spec.rb
206
208
  - spec/models/rspeed/splitter/diff_spec.rb
207
209
  - spec/models/rspeed/splitter/first_pipe_spec.rb
208
210
  - spec/models/rspeed/splitter/get_spec.rb
211
+ - spec/models/rspeed/splitter/need_warm_question_spec.rb
209
212
  - spec/models/rspeed/splitter/pipe_files_spec.rb
210
- - spec/models/rspeed/splitter/redundant_run_spec.rb
211
213
  - spec/models/rspeed/splitter/rename_spec.rb
212
214
  - spec/models/rspeed/splitter/split_spec.rb
213
215
  - spec/models/rspeed/variable/append_name_spec.rb
@@ -258,10 +260,10 @@ test_files:
258
260
  - spec/models/rspeed/variable/pipe_name_spec.rb
259
261
  - spec/models/rspeed/redis/destroy_spec.rb
260
262
  - spec/models/rspeed/redis/get_spec.rb
263
+ - spec/models/rspeed/redis/clean_spec.rb
261
264
  - spec/models/rspeed/redis/client_spec.rb
262
265
  - spec/models/rspeed/redis/specs_finished_spec.rb
263
266
  - spec/models/rspeed/redis/set_spec.rb
264
- - spec/models/rspeed/redis/clean_pipes_flag_spec.rb
265
267
  - spec/models/rspeed/redis/specs_initiated_spec.rb
266
268
  - spec/models/rspeed/redis/result_spec.rb
267
269
  - spec/models/rspeed/redis/keys_spec.rb
@@ -270,11 +272,12 @@ test_files:
270
272
  - spec/models/rspeed/splitter/actual_examples_spec.rb
271
273
  - spec/models/rspeed/splitter/get_spec.rb
272
274
  - spec/models/rspeed/splitter/rename_spec.rb
273
- - spec/models/rspeed/splitter/redundant_run_spec.rb
275
+ - spec/models/rspeed/splitter/need_warm_question_spec.rb
274
276
  - spec/models/rspeed/splitter/pipe_files_spec.rb
275
277
  - spec/models/rspeed/splitter/first_pipe_spec.rb
276
278
  - spec/models/rspeed/splitter/diff_spec.rb
277
279
  - spec/models/rspeed/splitter/split_spec.rb
280
+ - spec/models/rspeed/splitter/append_question_spec.rb
278
281
  - spec/models/rspeed/observer/before_suite_spec.rb
279
282
  - spec/models/rspeed/observer/before_spec.rb
280
283
  - spec/models/rspeed/observer/after_suite_spec.rb
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RSpeed::Splitter, '.redundant_run?' do
4
- subject(:splitter) { described_class.new }
5
-
6
- context 'when is not pipe 1' do
7
- before { allow(RSpeed::Env).to receive(:pipe).and_return(2) }
8
-
9
- context 'when result key exists' do
10
- let!(:redis) { redis_object }
11
-
12
- before do
13
- redis.set('rspeed', '{}')
14
-
15
- allow(RSpeed::Env).to receive(:pipe).and_return(2)
16
- end
17
-
18
- it { expect(splitter.redundant_run?).to be(false) }
19
- end
20
-
21
- context 'when result key does not exist' do
22
- it { expect(splitter.redundant_run?).to be(true) }
23
- end
24
- end
25
-
26
- context 'when is the first pipe' do
27
- before { allow(RSpeed::Env).to receive(:pipe).and_return(1) }
28
-
29
- context 'when result key exists' do
30
- let!(:redis) { redis_object }
31
-
32
- before do
33
- redis.set('rspeed', '{}')
34
-
35
- allow(RSpeed::Env).to receive(:pipe).and_return(2)
36
- end
37
-
38
- it { expect(splitter.redundant_run?).to be(false) }
39
- end
40
-
41
- context 'when result key does not exist' do
42
- it { expect(splitter.redundant_run?).to be(false) }
43
- end
44
- end
45
- end