knapsack 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/knapsack/tracker.rb +12 -2
- data/lib/knapsack/version.rb +1 -1
- data/spec/knapsack/tracker_spec.rb +50 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c687c34dd940bdf5c7594c114be9332548944ff
|
4
|
+
data.tar.gz: 38a10eaa09e1b6b87d4110a5c6173997f6dd73f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f4784ef9d81e7b1110269a1b280fdc7fd9b4ce8c16c08612c91a6524754d4e1c35a9fe88512b7d5512d03c26423bd70d2bea7eea15949b06d7eebb728800077
|
7
|
+
data.tar.gz: 6121b44a1c65b71d0a3c44478889cdfd80104448defcefe1b65f0a294b03fb38d6cfb4742e759bc4162ca71d8e54c25375fcb1578a224c87f527d05b7f831cb3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
* TODO
|
4
4
|
|
5
|
+
### 1.0.3
|
6
|
+
|
7
|
+
* Fix bug #11 - Track properly time when using Timecop gem in tests.
|
8
|
+
|
9
|
+
https://github.com/ArturT/knapsack/issues/11
|
10
|
+
|
11
|
+
https://github.com/ArturT/knapsack/issues/9
|
12
|
+
|
5
13
|
### 1.0.2
|
6
14
|
|
7
15
|
* Fix bug #8 - Sort all tests just in case to avoid wrong order of files when running tests on machines where `Dir.glob` has different implementation.
|
data/lib/knapsack/tracker.rb
CHANGED
@@ -19,11 +19,11 @@ module Knapsack
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def start_timer
|
22
|
-
@start_time =
|
22
|
+
@start_time = now_without_mock_time.to_f
|
23
23
|
end
|
24
24
|
|
25
25
|
def stop_timer
|
26
|
-
@execution_time =
|
26
|
+
@execution_time = now_without_mock_time.to_f - @start_time
|
27
27
|
update_global_time
|
28
28
|
update_test_file_time
|
29
29
|
@execution_time
|
@@ -79,5 +79,15 @@ module Knapsack
|
|
79
79
|
ci_node_index: Knapsack::Config::Env.ci_node_index
|
80
80
|
})
|
81
81
|
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def now_without_mock_time
|
86
|
+
if defined?(Timecop)
|
87
|
+
Time.now_without_mock_time
|
88
|
+
else
|
89
|
+
Time.now
|
90
|
+
end
|
91
|
+
end
|
82
92
|
end
|
83
93
|
end
|
data/lib/knapsack/version.rb
CHANGED
@@ -118,34 +118,67 @@ describe Knapsack::Tracker do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
describe 'track time execution' do
|
121
|
-
let(:now) { Time.now }
|
122
121
|
let(:test_paths) { ['a_spec.rb', 'b_spec.rb'] }
|
122
|
+
let(:delta) { 0.02 }
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
shared_examples 'test tracker' do
|
125
|
+
it { expect(tracker.global_time).to be_within(delta).of(0.3) }
|
126
|
+
it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
|
127
|
+
it { expect(tracker.test_files_with_time['a_spec.rb']).to be_within(delta).of(0.1) }
|
128
|
+
it { expect(tracker.test_files_with_time['b_spec.rb']).to be_within(delta).of(0.2) }
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'without Timecop' do
|
132
|
+
before do
|
133
|
+
test_paths.each_with_index do |test_path, index|
|
127
134
|
tracker.test_path = test_path
|
128
135
|
tracker.start_timer
|
129
|
-
|
130
|
-
|
131
|
-
seconds = index + 1
|
132
|
-
Timecop.freeze(now+seconds) do
|
136
|
+
sleep index.to_f / 10 + 0.1
|
133
137
|
tracker.stop_timer
|
134
138
|
end
|
135
139
|
end
|
140
|
+
|
141
|
+
it { expect(tracker.global_time).to be_within(delta).of(0.3) }
|
142
|
+
it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
|
143
|
+
it { expect(tracker.test_files_with_time['a_spec.rb']).to be_within(delta).of(0.1) }
|
144
|
+
it { expect(tracker.test_files_with_time['b_spec.rb']).to be_within(delta).of(0.2) }
|
136
145
|
end
|
137
146
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
147
|
+
context "with Timecop - Timecop shouldn't have impact on measured test time" do
|
148
|
+
let(:now) { Time.now }
|
149
|
+
|
150
|
+
before do
|
151
|
+
test_paths.each_with_index do |test_path, index|
|
152
|
+
Timecop.freeze(now) do
|
153
|
+
tracker.test_path = test_path
|
154
|
+
tracker.start_timer
|
155
|
+
end
|
156
|
+
|
157
|
+
delay = index + 1
|
158
|
+
Timecop.freeze(now+delay) do
|
159
|
+
tracker.stop_timer
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it { expect(tracker.global_time).to be >= 0 }
|
165
|
+
it { expect(tracker.global_time).to be_within(delta).of(0) }
|
166
|
+
it { expect(tracker.test_files_with_time.keys.size).to eql 2 }
|
167
|
+
it { expect(tracker.test_files_with_time['a_spec.rb']).to be_within(delta).of(0) }
|
168
|
+
it { expect(tracker.test_files_with_time['b_spec.rb']).to be_within(delta).of(0) }
|
144
169
|
end
|
170
|
+
end
|
145
171
|
|
146
|
-
|
147
|
-
|
148
|
-
|
172
|
+
describe '#reset!' do
|
173
|
+
before do
|
174
|
+
tracker.test_path = 'a_spec.rb'
|
175
|
+
tracker.start_timer
|
176
|
+
sleep 0.1
|
177
|
+
tracker.stop_timer
|
178
|
+
expect(tracker.global_time).not_to eql 0
|
179
|
+
tracker.reset!
|
149
180
|
end
|
181
|
+
|
182
|
+
it_behaves_like 'default trakcer attributes'
|
150
183
|
end
|
151
184
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knapsack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|