timers 4.1.2 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -4
- data/.travis.yml +15 -17
- data/Gemfile +7 -11
- data/README.md +60 -24
- data/Rakefile +2 -6
- data/lib/timers.rb +5 -0
- data/lib/timers/events.rb +108 -106
- data/lib/timers/group.rb +124 -119
- data/lib/timers/interval.rb +43 -0
- data/lib/timers/timer.rb +121 -116
- data/lib/timers/version.rb +6 -1
- data/lib/timers/wait.rb +47 -42
- data/spec/spec_helper.rb +30 -13
- data/spec/timers/cancel_spec.rb +33 -28
- data/spec/timers/events_spec.rb +40 -35
- data/spec/timers/every_spec.rb +27 -22
- data/spec/timers/group_spec.rb +247 -242
- data/spec/timers/performance_spec.rb +83 -54
- data/spec/timers/strict_spec.rb +37 -32
- data/spec/timers/wait_spec.rb +22 -17
- data/timers.gemspec +27 -20
- metadata +29 -18
- data/.coveralls.yml +0 -1
- data/.rubocop.yml +0 -28
- data/.ruby-version +0 -1
- data/AUTHORS.md +0 -15
- data/CHANGES.md +0 -62
- data/LICENSE +0 -23
data/spec/timers/cancel_spec.rb
CHANGED
@@ -1,45 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# This file is part of the "timers" project and released under the MIT license.
|
4
|
+
#
|
5
|
+
# Copyright, 2018, by Samuel Williams. All rights reserved.
|
6
|
+
#
|
2
7
|
|
3
8
|
RSpec.describe Timers::Group do
|
4
|
-
|
5
|
-
|
9
|
+
it "should be able to cancel twice" do
|
10
|
+
fired = false
|
6
11
|
|
7
|
-
|
12
|
+
timer = subject.after(0.1) { fired = true }
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
2.times do
|
15
|
+
timer.cancel
|
16
|
+
subject.wait
|
17
|
+
end
|
13
18
|
|
14
|
-
|
15
|
-
|
19
|
+
expect(fired).to be false
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
it "should be possble to reset after cancel" do
|
23
|
+
fired = false
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
timer = subject.after(0.1) { fired = true }
|
26
|
+
timer.cancel
|
22
27
|
|
23
|
-
|
28
|
+
subject.wait
|
24
29
|
|
25
|
-
|
30
|
+
timer.reset
|
26
31
|
|
27
|
-
|
32
|
+
subject.wait
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
expect(fired).to be true
|
35
|
+
end
|
31
36
|
|
32
|
-
|
33
|
-
|
37
|
+
it "should cancel and remove one shot timers after they fire" do
|
38
|
+
x = 0
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
Timers::Wait.for(2) do |_remaining|
|
41
|
+
timer = subject.every(0.2) { x += 1 }
|
42
|
+
subject.after(0.1) { timer.cancel }
|
38
43
|
|
39
|
-
|
40
|
-
|
44
|
+
subject.wait
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
expect(subject.timers).to be_empty
|
48
|
+
expect(x).to be == 0
|
49
|
+
end
|
45
50
|
end
|
data/spec/timers/events_spec.rb
CHANGED
@@ -1,56 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# This file is part of the "timers" project and released under the MIT license.
|
4
|
+
#
|
5
|
+
# Copyright, 2018, by Samuel Williams. All rights reserved.
|
6
|
+
#
|
2
7
|
|
3
8
|
RSpec.describe Timers::Events do
|
4
|
-
|
5
|
-
|
9
|
+
it "should register an event" do
|
10
|
+
fired = false
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
callback = proc do |_time|
|
13
|
+
fired = true
|
14
|
+
end
|
10
15
|
|
11
|
-
|
16
|
+
subject.schedule(0.1, callback)
|
12
17
|
|
13
|
-
|
18
|
+
expect(subject.size).to be == 1
|
14
19
|
|
15
|
-
|
20
|
+
subject.fire(0.15)
|
16
21
|
|
17
|
-
|
22
|
+
expect(subject.size).to be == 0
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
expect(fired).to be true
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
it "should register events in order" do
|
28
|
+
fired = []
|
24
29
|
|
25
|
-
|
30
|
+
times = [0.95, 0.1, 0.3, 0.5, 0.4, 0.2, 0.01, 0.9]
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
times.each do |requested_time|
|
33
|
+
callback = proc do |_time|
|
34
|
+
fired << requested_time
|
35
|
+
end
|
31
36
|
|
32
|
-
|
33
|
-
|
37
|
+
subject.schedule(requested_time, callback)
|
38
|
+
end
|
34
39
|
|
35
|
-
|
36
|
-
|
40
|
+
subject.fire(0.5)
|
41
|
+
expect(fired).to be == times.sort.first(6)
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
subject.fire(1.0)
|
44
|
+
expect(fired).to be == times.sort
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
it "should fire events with the time they were fired at" do
|
48
|
+
fired_at = :not_fired
|
44
49
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
callback = proc do |time|
|
51
|
+
# The time we actually were fired at:
|
52
|
+
fired_at = time
|
53
|
+
end
|
49
54
|
|
50
|
-
|
55
|
+
subject.schedule(0.5, callback)
|
51
56
|
|
52
|
-
|
57
|
+
subject.fire(1.0)
|
53
58
|
|
54
|
-
|
55
|
-
|
59
|
+
expect(fired_at).to be == 1.0
|
60
|
+
end
|
56
61
|
end
|
data/spec/timers/every_spec.rb
CHANGED
@@ -1,33 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# This file is part of the "timers" project and released under the MIT license.
|
4
|
+
#
|
5
|
+
# Copyright, 2018, by Samuel Williams. All rights reserved.
|
6
|
+
#
|
2
7
|
|
3
8
|
RSpec.describe Timers::Group do
|
4
|
-
|
5
|
-
|
9
|
+
it "should fire several times" do
|
10
|
+
result = []
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
subject.every(0.7) { result << :a }
|
13
|
+
subject.every(2.3) { result << :b }
|
14
|
+
subject.every(1.3) { result << :c }
|
15
|
+
subject.every(2.4) { result << :d }
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
Timers::Wait.for(2.5) do |remaining|
|
18
|
+
subject.wait if subject.wait_interval < remaining
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
expect(result).to be == [:a, :c, :a, :a, :b, :d]
|
22
|
+
end
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
it "should fire immediately and then several times later" do
|
25
|
+
result = []
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
subject.every(0.7) { result << :a }
|
28
|
+
subject.every(2.3) { result << :b }
|
29
|
+
subject.now_and_every(1.3) { result << :c }
|
30
|
+
subject.now_and_every(2.4) { result << :d }
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
Timers::Wait.for(2.5) do |remaining|
|
33
|
+
subject.wait if subject.wait_interval < remaining
|
34
|
+
end
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
expect(result).to be == [:c, :d, :a, :c, :a, :a, :b, :d]
|
37
|
+
end
|
33
38
|
end
|
data/spec/timers/group_spec.rb
CHANGED
@@ -1,255 +1,260 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# This file is part of the "timers" project and released under the MIT license.
|
4
|
+
#
|
5
|
+
# Copyright, 2018, by Samuel Williams. All rights reserved.
|
6
|
+
#
|
2
7
|
|
3
8
|
RSpec.describe Timers::Group do
|
4
|
-
|
5
|
-
|
6
|
-
|
9
|
+
describe "#wait" do
|
10
|
+
it "calls the wait block with nil" do
|
11
|
+
called = false
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
13
|
+
subject.wait do |interval|
|
14
|
+
expect(interval).to be_nil
|
15
|
+
called = true
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
expect(called).to be true
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
it "calls the wait block with an interval" do
|
22
|
+
called = false
|
23
|
+
fired = false
|
19
24
|
|
20
|
-
|
25
|
+
subject.after(0.1) { fired = true }
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
subject.wait do |interval|
|
28
|
+
expect(interval).to be_within(TIMER_QUANTUM).of(0.1)
|
29
|
+
called = true
|
30
|
+
sleep 0.2
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
expect(called).to be true
|
34
|
+
expect(fired).to be true
|
35
|
+
end
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
38
|
+
it "sleeps until the next timer" do
|
39
|
+
interval = TIMER_QUANTUM * 2
|
40
|
+
started_at = Time.now
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
fired = false
|
43
|
+
subject.after(interval) { fired = true }
|
44
|
+
subject.wait
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
46
|
+
expect(fired).to be true
|
47
|
+
expect(Time.now - started_at).to be_within(TIMER_QUANTUM).of interval
|
48
|
+
end
|
49
|
+
|
50
|
+
it "fires instantly when next timer is in the past" do
|
51
|
+
fired = false
|
52
|
+
subject.after(TIMER_QUANTUM) { fired = true }
|
53
|
+
sleep(TIMER_QUANTUM * 2)
|
54
|
+
subject.wait
|
55
|
+
|
56
|
+
expect(fired).to be true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "calculates the interval until the next timer should fire" do
|
60
|
+
interval = 0.1
|
61
|
+
|
62
|
+
subject.after(interval)
|
63
|
+
expect(subject.wait_interval).to be_within(TIMER_QUANTUM).of interval
|
64
|
+
|
65
|
+
sleep(interval)
|
66
|
+
expect(subject.wait_interval).to be <= 0
|
67
|
+
end
|
68
|
+
|
69
|
+
it "fires timers in the correct order" do
|
70
|
+
result = []
|
71
|
+
|
72
|
+
subject.after(TIMER_QUANTUM * 2) { result << :two }
|
73
|
+
subject.after(TIMER_QUANTUM * 3) { result << :three }
|
74
|
+
subject.after(TIMER_QUANTUM * 1) { result << :one }
|
75
|
+
|
76
|
+
sleep TIMER_QUANTUM * 4
|
77
|
+
subject.fire
|
78
|
+
|
79
|
+
expect(result).to eq [:one, :two, :three]
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises TypeError if given an invalid time" do
|
83
|
+
expect do
|
84
|
+
subject.after(nil) { nil }
|
85
|
+
end.to raise_exception(TypeError)
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "recurring timers" do
|
89
|
+
it "continues to fire the timers at each interval" do
|
90
|
+
result = []
|
91
|
+
|
92
|
+
subject.every(TIMER_QUANTUM * 2) { result << :foo }
|
93
|
+
|
94
|
+
sleep TIMER_QUANTUM * 3
|
95
|
+
subject.fire
|
96
|
+
expect(result).to eq [:foo]
|
97
|
+
|
98
|
+
sleep TIMER_QUANTUM * 5
|
99
|
+
subject.fire
|
100
|
+
expect(result).to eq [:foo, :foo]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "calculates the proper interval to wait until firing" do
|
105
|
+
interval_ms = 25
|
106
|
+
|
107
|
+
subject.after(interval_ms / 1000.0)
|
108
|
+
|
109
|
+
expect(subject.wait_interval).to be_within(TIMER_QUANTUM).of(interval_ms / 1000.0)
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "pause and continue timers" do
|
113
|
+
before(:each) do
|
114
|
+
@interval = TIMER_QUANTUM * 2
|
115
|
+
|
116
|
+
@fired = false
|
117
|
+
@timer = subject.after(@interval) { @fired = true }
|
118
|
+
@fired2 = false
|
119
|
+
@timer2 = subject.after(@interval) { @fired2 = true }
|
120
|
+
end
|
121
|
+
|
122
|
+
it "does not fire when paused" do
|
123
|
+
@timer.pause
|
124
|
+
subject.wait
|
125
|
+
expect(@fired).to be false
|
126
|
+
end
|
127
|
+
|
128
|
+
it "fires when continued after pause" do
|
129
|
+
@timer.pause
|
130
|
+
subject.wait
|
131
|
+
@timer.resume
|
132
|
+
|
133
|
+
sleep @timer.interval
|
134
|
+
subject.wait
|
135
|
+
|
136
|
+
expect(@fired).to be true
|
137
|
+
end
|
138
|
+
|
139
|
+
it "can pause all timers at once" do
|
140
|
+
subject.pause
|
141
|
+
subject.wait
|
142
|
+
expect(@fired).to be false
|
143
|
+
expect(@fired2).to be false
|
144
|
+
end
|
145
|
+
|
146
|
+
it "can continue all timers at once" do
|
147
|
+
subject.pause
|
148
|
+
subject.wait
|
149
|
+
subject.resume
|
150
|
+
|
151
|
+
# We need to wait until we are sure both timers will fire, otherwise highly accurate clocks
|
152
|
+
# (e.g. JVM)may only fire the first timer, but not the second, because they are actually
|
153
|
+
# schedueled at different times.
|
154
|
+
sleep TIMER_QUANTUM * 2
|
155
|
+
subject.wait
|
156
|
+
|
157
|
+
expect(@fired).to be true
|
158
|
+
expect(@fired2).to be true
|
159
|
+
end
|
160
|
+
|
161
|
+
it "can fire the timer directly" do
|
162
|
+
fired = false
|
163
|
+
timer = subject.after(TIMER_QUANTUM * 1) { fired = true }
|
164
|
+
timer.pause
|
165
|
+
subject.wait
|
166
|
+
expect(fired).not_to be true
|
167
|
+
timer.resume
|
168
|
+
expect(fired).not_to be true
|
169
|
+
timer.fire
|
170
|
+
expect(fired).to be true
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "delay timer" do
|
175
|
+
it "adds appropriate amount of time to timer" do
|
176
|
+
timer = subject.after(10)
|
177
|
+
timer.delay(5)
|
178
|
+
expect(timer.offset - subject.current_offset).to be_within(TIMER_QUANTUM).of(15)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "delay timer collection" do
|
183
|
+
it "delay on set adds appropriate amount of time to all timers" do
|
184
|
+
timer = subject.after(10)
|
185
|
+
timer2 = subject.after(20)
|
186
|
+
subject.delay(5)
|
187
|
+
expect(timer.offset - subject.current_offset).to be_within(TIMER_QUANTUM).of(15)
|
188
|
+
expect(timer2.offset - subject.current_offset).to be_within(TIMER_QUANTUM).of(25)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "on delaying a timer" do
|
193
|
+
it "fires timers in the correct order" do
|
194
|
+
result = []
|
195
|
+
|
196
|
+
subject.after(TIMER_QUANTUM * 2) { result << :two }
|
197
|
+
subject.after(TIMER_QUANTUM * 3) { result << :three }
|
198
|
+
first = subject.after(TIMER_QUANTUM * 1) { result << :one }
|
199
|
+
first.delay(TIMER_QUANTUM * 3)
|
200
|
+
|
201
|
+
sleep TIMER_QUANTUM * 5
|
202
|
+
subject.fire
|
203
|
+
|
204
|
+
expect(result).to eq [:two, :three, :one]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "#inspect" do
|
209
|
+
it "before firing" do
|
210
|
+
fired = false
|
211
|
+
timer = subject.after(TIMER_QUANTUM * 5) { fired = true }
|
212
|
+
timer.pause
|
213
|
+
expect(fired).not_to be true
|
214
|
+
expect(timer.inspect).to match(/\A#<Timers::Timer:0x[\da-f]+ fires in [-\.\de]+ seconds>\Z/)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "after firing" do
|
218
|
+
fired = false
|
219
|
+
timer = subject.after(TIMER_QUANTUM) { fired = true }
|
220
|
+
|
221
|
+
subject.wait
|
222
|
+
|
223
|
+
expect(fired).to be true
|
224
|
+
expect(timer.inspect).to match(/\A#<Timers::Timer:0x[\da-f]+ fired [-\.\de]+ seconds ago>\Z/)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "recurring firing" do
|
228
|
+
result = []
|
229
|
+
timer = subject.every(TIMER_QUANTUM) { result << :foo }
|
230
|
+
|
231
|
+
subject.wait
|
232
|
+
expect(result).not_to be_empty
|
233
|
+
regex = /\A#<Timers::Timer:0x[\da-f]+ fires in [-\.\de]+ seconds, recurs every #{format("%0.2f", TIMER_QUANTUM)}>\Z/
|
234
|
+
expect(timer.inspect).to match(regex)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "#fires_in" do
|
239
|
+
let(:interval) { TIMER_QUANTUM * 2 }
|
240
|
+
|
241
|
+
it "calculates the interval until the next fire if it's recurring" do
|
242
|
+
timer = subject.every(interval) { true }
|
243
|
+
expect(timer.fires_in).to be_within(TIMER_QUANTUM).of(interval)
|
244
|
+
end
|
245
|
+
|
246
|
+
context "when timer is not recurring" do
|
247
|
+
let!(:timer) { subject.after(interval) { true } }
|
248
|
+
|
249
|
+
it "calculates the interval until the next fire if it hasn't already fired" do
|
250
|
+
expect(timer.fires_in).to be_within(TIMER_QUANTUM).of(interval)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "calculates the interval since last fire if already fired" do
|
254
|
+
subject.wait
|
255
|
+
sleep(interval)
|
256
|
+
expect(timer.fires_in).to be_within(TIMER_QUANTUM).of(0 - interval)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
255
260
|
end
|