uv-rays 0.0.1 → 0.2.0
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 +4 -4
- data/lib/uv-rays/abstract_tokenizer.rb +1 -1
- data/lib/uv-rays/buffered_tokenizer.rb +2 -2
- data/lib/uv-rays/connection.rb +23 -7
- data/lib/uv-rays/http/encoding.rb +1 -1
- data/lib/uv-rays/http/request.rb +2 -2
- data/lib/uv-rays/http/response.rb +2 -2
- data/lib/uv-rays/http_endpoint.rb +3 -3
- data/lib/uv-rays/scheduler/cron.rb +1 -1
- data/lib/uv-rays/scheduler/time.rb +2 -2
- data/lib/uv-rays/scheduler.rb +6 -6
- data/lib/uv-rays/tcp_server.rb +1 -1
- data/lib/uv-rays/version.rb +2 -2
- data/lib/uv-rays.rb +3 -6
- data/spec/abstract_tokenizer_spec.rb +17 -17
- data/spec/buffered_tokenizer_spec.rb +44 -44
- data/spec/connection_spec.rb +41 -15
- data/spec/http_endpoint_spec.rb +55 -55
- data/spec/scheduler_cron_spec.rb +93 -93
- data/spec/scheduler_spec.rb +11 -11
- data/spec/scheduler_time_spec.rb +63 -63
- data/uv-rays.gemspec +3 -3
- metadata +6 -6
data/spec/scheduler_cron_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'uv-rays'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe UV::Scheduler::CronLine do
|
4
4
|
|
5
5
|
def cl(cronline_string)
|
6
|
-
|
6
|
+
UV::Scheduler::CronLine.new(cronline_string)
|
7
7
|
end
|
8
8
|
|
9
9
|
def match(line, time)
|
10
|
-
cl(line).matches?(time).
|
10
|
+
expect(cl(line).matches?(time)).to eq(true)
|
11
11
|
end
|
12
12
|
def no_match(line, time)
|
13
|
-
cl(line).matches?(time).
|
13
|
+
expect(cl(line).matches?(time)).to eq(false)
|
14
14
|
end
|
15
15
|
def to_a(line, array)
|
16
|
-
cl(line).to_array.
|
16
|
+
expect(cl(line).to_array).to eq(array)
|
17
17
|
end
|
18
18
|
def local(*args)
|
19
19
|
Time.local(*args)
|
@@ -58,17 +58,17 @@ describe UvRays::Scheduler::CronLine do
|
|
58
58
|
|
59
59
|
it 'rejects invalid weekday expressions' do
|
60
60
|
|
61
|
-
|
61
|
+
expect { cl '0 17 * * MON_FRI' }.to raise_error
|
62
62
|
# underline instead of dash
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
expect { cl '* * * * 9' }.to raise_error
|
65
|
+
expect { cl '* * * * 0-12' }.to raise_error
|
66
|
+
expect { cl '* * * * BLABLA' }.to raise_error
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'rejects invalid cronlines' do
|
70
70
|
|
71
|
-
|
71
|
+
expect { cl '* nada * * 9' }.to raise_error(ArgumentError)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'interprets cron strings with TZ correctly' do
|
@@ -83,8 +83,8 @@ describe UvRays::Scheduler::CronLine do
|
|
83
83
|
'* * * * * * America/New_York',
|
84
84
|
[ nil, nil, nil, nil, nil, nil, nil, 'America/New_York' ])
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
expect { cl '* * * * * NotATimeZone' }.to raise_error
|
87
|
+
expect { cl '* * * * * * NotATimeZone' }.to raise_error
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'interprets cron strings with / (slashes) correctly' do
|
@@ -117,9 +117,9 @@ describe UvRays::Scheduler::CronLine do
|
|
117
117
|
|
118
118
|
it 'does not support ranges for monthdays (sun#1-sun#2)' do
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
}.
|
120
|
+
expect {
|
121
|
+
UV::Scheduler::CronLine.new('* * * * sun#1-sun#2')
|
122
|
+
}.to raise_error(ArgumentError)
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'accepts items with initial 0' do
|
@@ -142,27 +142,27 @@ describe UvRays::Scheduler::CronLine do
|
|
142
142
|
|
143
143
|
it 'does not support ranges for L' do
|
144
144
|
|
145
|
-
|
146
|
-
|
145
|
+
expect { cl '* * 15-L * *'}.to raise_error(ArgumentError)
|
146
|
+
expect { cl '* * L/4 * *'}.to raise_error(ArgumentError)
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'does not support multiple Ls' do
|
150
150
|
|
151
|
-
|
151
|
+
expect { cl '* * L,L * *'}.to raise_error(ArgumentError)
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'raises if L is used for something else than days' do
|
155
155
|
|
156
|
-
|
156
|
+
expect { cl '* L * * *'}.to raise_error(ArgumentError)
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'raises for out of range input' do
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
161
|
+
expect { cl '60-62 * * * *'}.to raise_error(ArgumentError)
|
162
|
+
expect { cl '62 * * * *'}.to raise_error(ArgumentError)
|
163
|
+
expect { cl '60 * * * *'}.to raise_error(ArgumentError)
|
164
|
+
expect { cl '* 25-26 * * *'}.to raise_error(ArgumentError)
|
165
|
+
expect { cl '* 25 * * *'}.to raise_error(ArgumentError)
|
166
166
|
#
|
167
167
|
# as reported by Aimee Rose in
|
168
168
|
# https://github.com/jmettraux/rufus-scheduler/pull/58
|
@@ -172,66 +172,66 @@ describe UvRays::Scheduler::CronLine do
|
|
172
172
|
describe '#next_time' do
|
173
173
|
|
174
174
|
def nt(cronline, now)
|
175
|
-
|
175
|
+
UV::Scheduler::CronLine.new(cronline).next_time(now)
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'computes the next occurence correctly' do
|
179
179
|
|
180
180
|
now = Time.at(0).getutc # Thu Jan 01 00:00:00 UTC 1970
|
181
181
|
|
182
|
-
nt('* * * * *', now).
|
183
|
-
nt('* * * * sun', now).
|
184
|
-
nt('* * * * * *', now).
|
185
|
-
nt('* * 13 * fri', now).
|
182
|
+
expect(nt('* * * * *', now)).to eq(now + 60)
|
183
|
+
expect(nt('* * * * sun', now)).to eq(now + 259200)
|
184
|
+
expect(nt('* * * * * *', now)).to eq(now + 1)
|
185
|
+
expect(nt('* * 13 * fri', now)).to eq(now + 3715200)
|
186
186
|
|
187
|
-
nt('10 12 13 12 *', now).
|
187
|
+
expect(nt('10 12 13 12 *', now)).to eq(now + 29938200)
|
188
188
|
# this one is slow (1 year == 3 seconds)
|
189
189
|
#
|
190
190
|
# historical note:
|
191
191
|
# (comment made in 2006 or 2007, the underlying libs got better and
|
192
192
|
# that slowness is gone)
|
193
193
|
|
194
|
-
nt('0 0 * * thu', now).
|
195
|
-
nt('00 0 * * thu', now).
|
194
|
+
expect(nt('0 0 * * thu', now)).to eq(now + 604800)
|
195
|
+
expect(nt('00 0 * * thu', now)).to eq(now + 604800)
|
196
196
|
|
197
|
-
nt('0 0 * * *', now).
|
198
|
-
nt('0 24 * * *', now).
|
197
|
+
expect(nt('0 0 * * *', now)).to eq(now + 24 * 3600)
|
198
|
+
expect(nt('0 24 * * *', now)).to eq(now + 24 * 3600)
|
199
199
|
|
200
200
|
now = local(2008, 12, 31, 23, 59, 59, 0)
|
201
201
|
|
202
|
-
nt('* * * * *', now).
|
202
|
+
expect(nt('* * * * *', now)).to eq(now + 1)
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'computes the next occurence correctly in UTC (TZ not specified)' do
|
206
206
|
|
207
207
|
now = utc(1970, 1, 1)
|
208
208
|
|
209
|
-
nt('* * * * *', now).
|
210
|
-
nt('* * * * sun', now).
|
211
|
-
nt('* * * * * *', now).
|
212
|
-
nt('* * 13 * fri', now).
|
209
|
+
expect(nt('* * * * *', now)).to eq(utc(1970, 1, 1, 0, 1))
|
210
|
+
expect(nt('* * * * sun', now)).to eq(utc(1970, 1, 4))
|
211
|
+
expect(nt('* * * * * *', now)).to eq(utc(1970, 1, 1, 0, 0, 1))
|
212
|
+
expect(nt('* * 13 * fri', now)).to eq(utc(1970, 2, 13))
|
213
213
|
|
214
|
-
nt('10 12 13 12 *', now).
|
214
|
+
expect(nt('10 12 13 12 *', now)).to eq(utc(1970, 12, 13, 12, 10))
|
215
215
|
# this one is slow (1 year == 3 seconds)
|
216
|
-
nt('* * 1 6 *', now).
|
216
|
+
expect(nt('* * 1 6 *', now)).to eq(utc(1970, 6, 1))
|
217
217
|
|
218
|
-
nt('0 0 * * thu', now).
|
218
|
+
expect(nt('0 0 * * thu', now)).to eq(utc(1970, 1, 8))
|
219
219
|
end
|
220
220
|
|
221
221
|
it 'computes the next occurence correctly in local TZ (TZ not specified)' do
|
222
222
|
|
223
223
|
now = local(1970, 1, 1)
|
224
224
|
|
225
|
-
nt('* * * * *', now).
|
226
|
-
nt('* * * * sun', now).
|
227
|
-
nt('* * * * * *', now).
|
228
|
-
nt('* * 13 * fri', now).
|
225
|
+
expect(nt('* * * * *', now)).to eq(local(1970, 1, 1, 0, 1))
|
226
|
+
expect(nt('* * * * sun', now)).to eq(local(1970, 1, 4))
|
227
|
+
expect(nt('* * * * * *', now)).to eq(local(1970, 1, 1, 0, 0, 1))
|
228
|
+
expect(nt('* * 13 * fri', now)).to eq(local(1970, 2, 13))
|
229
229
|
|
230
|
-
nt('10 12 13 12 *', now).
|
230
|
+
expect(nt('10 12 13 12 *', now)).to eq(local(1970, 12, 13, 12, 10))
|
231
231
|
# this one is slow (1 year == 3 seconds)
|
232
|
-
nt('* * 1 6 *', now).
|
232
|
+
expect(nt('* * 1 6 *', now)).to eq(local(1970, 6, 1))
|
233
233
|
|
234
|
-
nt('0 0 * * thu', now).
|
234
|
+
expect(nt('0 0 * * thu', now)).to eq(local(1970, 1, 8))
|
235
235
|
end
|
236
236
|
|
237
237
|
it 'computes the next occurence correctly in UTC (TZ specified)' do
|
@@ -241,15 +241,15 @@ describe UvRays::Scheduler::CronLine do
|
|
241
241
|
now = tz.local_to_utc(local(1970, 1, 1))
|
242
242
|
# Midnight in zone, UTC
|
243
243
|
|
244
|
-
nt("* * * * * #{zone}", now).
|
245
|
-
nt("* * * * sun #{zone}", now).
|
246
|
-
nt("* * * * * * #{zone}", now).
|
247
|
-
nt("* * 13 * fri #{zone}", now).
|
244
|
+
expect(nt("* * * * * #{zone}", now)).to eq(utc(1969, 12, 31, 23, 1))
|
245
|
+
expect(nt("* * * * sun #{zone}", now)).to eq(utc(1970, 1, 3, 23))
|
246
|
+
expect(nt("* * * * * * #{zone}", now)).to eq(utc(1969, 12, 31, 23, 0, 1))
|
247
|
+
expect(nt("* * 13 * fri #{zone}", now)).to eq(utc(1970, 2, 12, 23))
|
248
248
|
|
249
|
-
nt("10 12 13 12 * #{zone}", now).
|
250
|
-
nt("* * 1 6 * #{zone}", now).
|
249
|
+
expect(nt("10 12 13 12 * #{zone}", now)).to eq(utc(1970, 12, 13, 11, 10))
|
250
|
+
expect(nt("* * 1 6 * #{zone}", now)).to eq(utc(1970, 5, 31, 23))
|
251
251
|
|
252
|
-
nt("0 0 * * thu #{zone}", now).
|
252
|
+
expect(nt("0 0 * * thu #{zone}", now)).to eq(utc(1970, 1, 7, 23))
|
253
253
|
end
|
254
254
|
|
255
255
|
#it 'computes the next occurence correctly in local TZ (TZ specified)' do
|
@@ -257,72 +257,72 @@ describe UvRays::Scheduler::CronLine do
|
|
257
257
|
# tz = TZInfo::Timezone.get(zone)
|
258
258
|
# now = tz.local_to_utc(utc(1970, 1, 1)).localtime
|
259
259
|
# # Midnight in zone, local time
|
260
|
-
# nt("* * * * * #{zone}", now).
|
261
|
-
# nt("* * * * sun #{zone}", now).
|
262
|
-
# nt("* * * * * * #{zone}", now).
|
263
|
-
# nt("* * 13 * fri #{zone}", now).
|
264
|
-
# nt("10 12 13 12 * #{zone}", now).
|
265
|
-
# nt("* * 1 6 * #{zone}", now).
|
266
|
-
# nt("0 0 * * thu #{zone}", now).
|
260
|
+
# expect(nt("* * * * * #{zone}", now)).to eq(local(1969, 12, 31, 18, 1))
|
261
|
+
# expect(nt("* * * * sun #{zone}", now)).to eq(local(1970, 1, 3, 18))
|
262
|
+
# expect(nt("* * * * * * #{zone}", now)).to eq(local(1969, 12, 31, 18, 0, 1))
|
263
|
+
# expect(nt("* * 13 * fri #{zone}", now)).to eq(local(1970, 2, 12, 18))
|
264
|
+
# expect(nt("10 12 13 12 * #{zone}", now)).to eq(local(1970, 12, 13, 6, 10))
|
265
|
+
# expect(nt("* * 1 6 * #{zone}", now)).to eq(local(1970, 5, 31, 19))
|
266
|
+
# expect(nt("0 0 * * thu #{zone}", now)).to eq(local(1970, 1, 7, 18))
|
267
267
|
#end
|
268
268
|
|
269
269
|
it 'computes the next time correctly when there is a sun#2 involved' do
|
270
270
|
|
271
|
-
nt('* * * * sun#1', local(1970, 1, 1)).
|
272
|
-
nt('* * * * sun#2', local(1970, 1, 1)).
|
271
|
+
expect(nt('* * * * sun#1', local(1970, 1, 1))).to eq(local(1970, 1, 4))
|
272
|
+
expect(nt('* * * * sun#2', local(1970, 1, 1))).to eq(local(1970, 1, 11))
|
273
273
|
|
274
|
-
nt('* * * * sun#2', local(1970, 1, 12)).
|
274
|
+
expect(nt('* * * * sun#2', local(1970, 1, 12))).to eq(local(1970, 2, 8))
|
275
275
|
end
|
276
276
|
|
277
277
|
it 'computes the next time correctly when there is a sun#2,sun#3 involved' do
|
278
278
|
|
279
|
-
nt('* * * * sun#2,sun#3', local(1970, 1, 1)).
|
280
|
-
nt('* * * * sun#2,sun#3', local(1970, 1, 12)).
|
279
|
+
expect(nt('* * * * sun#2,sun#3', local(1970, 1, 1))).to eq(local(1970, 1, 11))
|
280
|
+
expect(nt('* * * * sun#2,sun#3', local(1970, 1, 12))).to eq(local(1970, 1, 18))
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'understands sun#L' do
|
284
284
|
|
285
|
-
nt('* * * * sun#L', local(1970, 1, 1)).
|
285
|
+
expect(nt('* * * * sun#L', local(1970, 1, 1))).to eq(local(1970, 1, 25))
|
286
286
|
end
|
287
287
|
|
288
288
|
it 'understands sun#-1' do
|
289
289
|
|
290
|
-
nt('* * * * sun#-1', local(1970, 1, 1)).
|
290
|
+
expect(nt('* * * * sun#-1', local(1970, 1, 1))).to eq(local(1970, 1, 25))
|
291
291
|
end
|
292
292
|
|
293
293
|
it 'understands sun#-2' do
|
294
294
|
|
295
|
-
nt('* * * * sun#-2', local(1970, 1, 1)).
|
295
|
+
expect(nt('* * * * sun#-2', local(1970, 1, 1))).to eq(local(1970, 1, 18))
|
296
296
|
end
|
297
297
|
|
298
298
|
it 'computes the next time correctly when "L" (last day of month)' do
|
299
299
|
|
300
|
-
nt('* * L * *', lo(1970, 1, 1)).
|
301
|
-
nt('* * L * *', lo(1970, 2, 1)).
|
302
|
-
nt('* * L * *', lo(1972, 2, 1)).
|
303
|
-
nt('* * L * *', lo(1970, 4, 1)).
|
300
|
+
expect(nt('* * L * *', lo(1970, 1, 1))).to eq(lo(1970, 1, 31))
|
301
|
+
expect(nt('* * L * *', lo(1970, 2, 1))).to eq(lo(1970, 2, 28))
|
302
|
+
expect(nt('* * L * *', lo(1972, 2, 1))).to eq(lo(1972, 2, 29))
|
303
|
+
expect(nt('* * L * *', lo(1970, 4, 1))).to eq(lo(1970, 4, 30))
|
304
304
|
end
|
305
305
|
|
306
306
|
it 'returns a time with subseconds chopped off' do
|
307
307
|
|
308
|
-
nt('* * * * *', Time.now).usec.
|
309
|
-
nt('* * * * *', Time.now).iso8601(10).match(/\.0+[^\d]/).
|
308
|
+
expect(nt('* * * * *', Time.now).usec).to eq(0)
|
309
|
+
expect(nt('* * * * *', Time.now).iso8601(10).match(/\.0+[^\d]/)).not_to eq(nil)
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
313
313
|
describe '#previous_time' do
|
314
314
|
|
315
315
|
def pt(cronline, now)
|
316
|
-
|
316
|
+
UV::Scheduler::CronLine.new(cronline).previous_time(now)
|
317
317
|
end
|
318
318
|
|
319
319
|
it 'returns the previous time the cron should have triggered' do
|
320
320
|
|
321
|
-
pt('* * * * sun', lo(1970, 1, 1)).
|
322
|
-
pt('* * 13 * *', lo(1970, 1, 1)).
|
323
|
-
pt('0 12 13 * *', lo(1970, 1, 1)).
|
321
|
+
expect(pt('* * * * sun', lo(1970, 1, 1))).to eq(lo(1969, 12, 28, 23, 59, 00))
|
322
|
+
expect(pt('* * 13 * *', lo(1970, 1, 1))).to eq(lo(1969, 12, 13, 23, 59, 00))
|
323
|
+
expect(pt('0 12 13 * *', lo(1970, 1, 1))).to eq(lo(1969, 12, 13, 12, 00))
|
324
324
|
|
325
|
-
pt('* * * * * sun', lo(1970, 1, 1)).
|
325
|
+
expect(pt('* * * * * sun', lo(1970, 1, 1))).to eq(lo(1969, 12, 28, 23, 59, 59))
|
326
326
|
end
|
327
327
|
end
|
328
328
|
|
@@ -400,17 +400,17 @@ describe UvRays::Scheduler::CronLine do
|
|
400
400
|
|
401
401
|
it 'returns the appropriate "sun#2"-like string' do
|
402
402
|
|
403
|
-
class
|
403
|
+
class UV::Scheduler::CronLine
|
404
404
|
public :monthdays
|
405
405
|
end
|
406
406
|
|
407
|
-
cl =
|
407
|
+
cl = UV::Scheduler::CronLine.new('* * * * *')
|
408
408
|
|
409
|
-
cl.monthdays(local(1970, 1, 1)).
|
410
|
-
cl.monthdays(local(1970, 1, 7)).
|
411
|
-
cl.monthdays(local(1970, 1, 14)).
|
409
|
+
expect(cl.monthdays(local(1970, 1, 1))).to eq(%w[ thu#1 thu#-5 ])
|
410
|
+
expect(cl.monthdays(local(1970, 1, 7))).to eq(%w[ wed#1 wed#-4 ])
|
411
|
+
expect(cl.monthdays(local(1970, 1, 14))).to eq(%w[ wed#2 wed#-3 ])
|
412
412
|
|
413
|
-
cl.monthdays(local(2011, 3, 11)).
|
413
|
+
expect(cl.monthdays(local(2011, 3, 11))).to eq(%w[ fri#2 fri#-3 ])
|
414
414
|
end
|
415
415
|
end
|
416
416
|
|
@@ -418,12 +418,12 @@ describe UvRays::Scheduler::CronLine do
|
|
418
418
|
|
419
419
|
it 'returns the shortest delta between two occurrences' do
|
420
420
|
|
421
|
-
|
422
|
-
|
421
|
+
expect(UV::Scheduler::CronLine.new('* * * * *').frequency).to eq(60)
|
422
|
+
expect(UV::Scheduler::CronLine.new('* * * * * *').frequency).to eq(1)
|
423
423
|
|
424
|
-
|
425
|
-
|
426
|
-
|
424
|
+
expect(UV::Scheduler::CronLine.new('5 23 * * *').frequency).to eq(24 * 3600)
|
425
|
+
expect(UV::Scheduler::CronLine.new('5 * * * *').frequency).to eq(3600)
|
426
|
+
expect(UV::Scheduler::CronLine.new('10,20,30 * * * *').frequency).to eq(600)
|
427
427
|
end
|
428
428
|
end
|
429
429
|
end
|
data/spec/scheduler_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'uv-rays'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe UV::Scheduler do
|
4
4
|
before :each do
|
5
5
|
@loop = Libuv::Loop.new
|
6
6
|
@general_failure = []
|
@@ -29,10 +29,10 @@ describe UvRays::Scheduler do
|
|
29
29
|
end
|
30
30
|
}
|
31
31
|
|
32
|
-
@general_failure.
|
33
|
-
@event.
|
32
|
+
expect(@general_failure).to eq([])
|
33
|
+
expect(@event).to eq(@result)
|
34
34
|
@diff = @triggered_at - @event.last_scheduled
|
35
|
-
(@diff >= 500 && @diff < 750).
|
35
|
+
expect((@diff >= 500 && @diff < 750)).to eq(true)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should be able to schedule a one shot event using 'at'" do
|
@@ -52,10 +52,10 @@ describe UvRays::Scheduler do
|
|
52
52
|
end
|
53
53
|
}
|
54
54
|
|
55
|
-
@general_failure.
|
56
|
-
@event.
|
55
|
+
expect(@general_failure).to eq([])
|
56
|
+
expect(@event).to eq(@result)
|
57
57
|
@diff = @triggered_at - @event.last_scheduled
|
58
|
-
(@diff >= 1000 && @diff < 1250).
|
58
|
+
expect((@diff >= 1000 && @diff < 1250)).to eq(true)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should be able to schedule a repeat event" do
|
@@ -81,10 +81,10 @@ describe UvRays::Scheduler do
|
|
81
81
|
end
|
82
82
|
}
|
83
83
|
|
84
|
-
@general_failure.
|
85
|
-
@run.
|
86
|
-
@event.
|
84
|
+
expect(@general_failure).to eq([])
|
85
|
+
expect(@run).to eq(2)
|
86
|
+
expect(@event).to eq(@result)
|
87
87
|
@diff = @triggered_at - @event.last_scheduled
|
88
|
-
(@diff >= 250 && @diff < 500).
|
88
|
+
expect((@diff >= 250 && @diff < 500)).to eq(true)
|
89
89
|
end
|
90
90
|
end
|
data/spec/scheduler_time_spec.rb
CHANGED
@@ -7,126 +7,126 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe UV::Scheduler do
|
11
11
|
|
12
12
|
describe '.parse_duration' do
|
13
13
|
|
14
14
|
def pd(s)
|
15
|
-
|
15
|
+
UV::Scheduler.parse_duration(s)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'parses duration strings' do
|
19
19
|
|
20
|
-
pd('-1.0d1.0w1.0d').
|
21
|
-
pd('-1d1w1d').
|
22
|
-
pd('-1w2d').
|
23
|
-
pd('-1h10s').
|
24
|
-
pd('-1h').
|
25
|
-
pd('-5.').
|
26
|
-
pd('-2.5s').
|
27
|
-
pd('-1s').
|
28
|
-
pd('-500').
|
29
|
-
pd('').
|
30
|
-
pd('5.0').
|
31
|
-
pd('0.5').
|
32
|
-
pd('.5').
|
33
|
-
pd('5.').
|
34
|
-
pd('500').
|
35
|
-
pd('1000').
|
36
|
-
pd('1').
|
37
|
-
pd('1s').
|
38
|
-
pd('2.5s').
|
39
|
-
pd('1h').
|
40
|
-
pd('1h10s').
|
41
|
-
pd('1w2d').
|
42
|
-
pd('1d1w1d').
|
43
|
-
pd('1.0d1.0w1.0d').
|
44
|
-
|
45
|
-
pd('.5m').
|
46
|
-
pd('5.m').
|
47
|
-
pd('1m.5s').
|
48
|
-
pd('-.5m').
|
49
|
-
|
50
|
-
pd('1').
|
51
|
-
pd('0.1').
|
52
|
-
pd('1s').
|
20
|
+
expect(pd('-1.0d1.0w1.0d')).to eq(-777600000)
|
21
|
+
expect(pd('-1d1w1d')).to eq(-777600000)
|
22
|
+
expect(pd('-1w2d')).to eq(-777600000)
|
23
|
+
expect(pd('-1h10s')).to eq(-3610000)
|
24
|
+
expect(pd('-1h')).to eq(-3600000)
|
25
|
+
expect(pd('-5.')).to eq(-5)
|
26
|
+
expect(pd('-2.5s')).to eq(-2500)
|
27
|
+
expect(pd('-1s')).to eq(-1000)
|
28
|
+
expect(pd('-500')).to eq(-500)
|
29
|
+
expect(pd('')).to eq(0)
|
30
|
+
expect(pd('5.0')).to eq(5)
|
31
|
+
expect(pd('0.5')).to eq(0)
|
32
|
+
expect(pd('.5')).to eq(0)
|
33
|
+
expect(pd('5.')).to eq(5)
|
34
|
+
expect(pd('500')).to eq(500)
|
35
|
+
expect(pd('1000')).to eq(1000)
|
36
|
+
expect(pd('1')).to eq(1)
|
37
|
+
expect(pd('1s')).to eq(1000)
|
38
|
+
expect(pd('2.5s')).to eq(2500)
|
39
|
+
expect(pd('1h')).to eq(3600000)
|
40
|
+
expect(pd('1h10s')).to eq(3610000)
|
41
|
+
expect(pd('1w2d')).to eq(777600000)
|
42
|
+
expect(pd('1d1w1d')).to eq(777600000)
|
43
|
+
expect(pd('1.0d1.0w1.0d')).to eq(777600000)
|
44
|
+
|
45
|
+
expect(pd('.5m')).to eq(30000)
|
46
|
+
expect(pd('5.m')).to eq(300000)
|
47
|
+
expect(pd('1m.5s')).to eq(60500)
|
48
|
+
expect(pd('-.5m')).to eq(-30000)
|
49
|
+
|
50
|
+
expect(pd('1')).to eq(1)
|
51
|
+
expect(pd('0.1')).to eq(0)
|
52
|
+
expect(pd('1s')).to eq(1000)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'calls #to_s on its input' do
|
56
56
|
|
57
|
-
pd(1).
|
57
|
+
expect(pd(1)).to eq(1)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'raises on wrong duration strings' do
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
expect { pd('-') }.to raise_error(ArgumentError)
|
63
|
+
expect { pd('h') }.to raise_error(ArgumentError)
|
64
|
+
expect { pd('whatever') }.to raise_error(ArgumentError)
|
65
|
+
expect { pd('hms') }.to raise_error(ArgumentError)
|
66
66
|
|
67
|
-
|
67
|
+
expect { pd(' 1h ') }.to raise_error(ArgumentError)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe '.to_duration' do
|
72
72
|
|
73
73
|
def td(o, opts={})
|
74
|
-
|
74
|
+
UV::Scheduler.to_duration(o, opts)
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'turns integers into duration strings' do
|
78
78
|
|
79
|
-
td(0).
|
80
|
-
td(60000).
|
81
|
-
td(61000).
|
82
|
-
td(3661000).
|
83
|
-
td(24 * 3600 * 1000).
|
84
|
-
td(7 * 24 * 3600 * 1000 + 1000).
|
85
|
-
td(30 * 24 * 3600 * 1000 + 1000).
|
79
|
+
expect(td(0)).to eq('0s')
|
80
|
+
expect(td(60000)).to eq('1m')
|
81
|
+
expect(td(61000)).to eq('1m1s')
|
82
|
+
expect(td(3661000)).to eq('1h1m1s')
|
83
|
+
expect(td(24 * 3600 * 1000)).to eq('1d')
|
84
|
+
expect(td(7 * 24 * 3600 * 1000 + 1000)).to eq('1w1s')
|
85
|
+
expect(td(30 * 24 * 3600 * 1000 + 1000)).to eq('4w2d1s')
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'ignores seconds and milliseconds if :drop_seconds => true' do
|
89
89
|
|
90
|
-
td(0, :drop_seconds => true).
|
91
|
-
td(5000, :drop_seconds => true).
|
92
|
-
td(61000, :drop_seconds => true).
|
90
|
+
expect(td(0, :drop_seconds => true)).to eq('0m')
|
91
|
+
expect(td(5000, :drop_seconds => true)).to eq('0m')
|
92
|
+
expect(td(61000, :drop_seconds => true)).to eq('1m')
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'displays months if :months => true' do
|
96
96
|
|
97
|
-
td(1000, :months => true).
|
98
|
-
td(30 * 24 * 3600 * 1000 + 1000, :months => true).
|
97
|
+
expect(td(1000, :months => true)).to eq('1s')
|
98
|
+
expect(td(30 * 24 * 3600 * 1000 + 1000, :months => true)).to eq('1M1s')
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'turns floats into duration strings' do
|
102
102
|
|
103
|
-
td(100).
|
104
|
-
td(1100).
|
103
|
+
expect(td(100)).to eq('100')
|
104
|
+
expect(td(1100)).to eq('1s100')
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
describe '.to_duration_hash' do
|
109
109
|
|
110
110
|
def tdh(o, opts={})
|
111
|
-
|
111
|
+
UV::Scheduler.to_duration_hash(o, opts)
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'turns integers duration hashes' do
|
115
115
|
|
116
|
-
tdh(0).
|
117
|
-
tdh(60000).
|
116
|
+
expect(tdh(0)).to eq({})
|
117
|
+
expect(tdh(60000)).to eq({ :m => 1 })
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'turns floats duration hashes' do
|
121
121
|
|
122
|
-
tdh(128).
|
123
|
-
tdh(60127).
|
122
|
+
expect(tdh(128)).to eq({ :ms => 128 })
|
123
|
+
expect(tdh(60127)).to eq({ :m => 1, :ms => 127 })
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'drops seconds and milliseconds if :drop_seconds => true' do
|
127
127
|
|
128
|
-
tdh(61127).
|
129
|
-
tdh(61127, :drop_seconds => true).
|
128
|
+
expect(tdh(61127)).to eq({ :m => 1, :s => 1, :ms => 127 })
|
129
|
+
expect(tdh(61127, :drop_seconds => true)).to eq({ :m => 1 })
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
data/uv-rays.gemspec
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path("../lib/uv-rays/version", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "uv-rays"
|
5
|
-
gem.version =
|
5
|
+
gem.version = UV::VERSION
|
6
6
|
gem.license = 'MIT'
|
7
7
|
gem.authors = ["Stephen von Takach"]
|
8
8
|
gem.email = ["steve@cotag.me"]
|
@@ -13,13 +13,13 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.required_ruby_version = '>= 1.9.2'
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
|
16
|
-
gem.add_runtime_dependency 'libuv'
|
16
|
+
gem.add_runtime_dependency 'libuv', '>= 0.11.19'
|
17
17
|
gem.add_runtime_dependency 'bisect'
|
18
18
|
gem.add_runtime_dependency 'tzinfo'
|
19
19
|
gem.add_runtime_dependency 'cookiejar'
|
20
20
|
gem.add_runtime_dependency 'ipaddress'
|
21
21
|
gem.add_runtime_dependency 'addressable'
|
22
|
-
gem.add_runtime_dependency 'http-parser'
|
22
|
+
gem.add_runtime_dependency 'http-parser', '>= 1.0.4'
|
23
23
|
|
24
24
|
gem.add_development_dependency 'rspec', '>= 2.14'
|
25
25
|
gem.add_development_dependency 'rake', '>= 10.1'
|