agent 0.10.0 → 0.11.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/Gemfile.lock +16 -11
- data/lib/agent/channel.rb +4 -2
- data/lib/agent/version.rb +1 -1
- data/spec/blocking_once_spec.rb +13 -13
- data/spec/channel_spec.rb +44 -44
- data/spec/error_spec.rb +2 -2
- data/spec/examples/channel_of_channels_spec.rb +2 -2
- data/spec/examples/producer_consumer_spec.rb +5 -5
- data/spec/examples/sieve_spec.rb +2 -2
- data/spec/go_spec.rb +3 -3
- data/spec/notifier_spec.rb +7 -7
- data/spec/once_spec.rb +13 -13
- data/spec/pop_spec.rb +29 -29
- data/spec/push_spec.rb +27 -27
- data/spec/queue_spec.rb +92 -92
- data/spec/queues_spec.rb +6 -6
- data/spec/selector_spec.rb +117 -58
- data/spec/spec_helper.rb +0 -1
- data/spec/uuid_spec.rb +2 -2
- data/spec/wait_group_spec.rb +5 -5
- metadata +3 -3
data/spec/queues_spec.rb
CHANGED
@@ -7,22 +7,22 @@ describe Agent::Queues do
|
|
7
7
|
|
8
8
|
it "should register queues" do
|
9
9
|
Agent::Queues.register("foo", String, 10)
|
10
|
-
Agent::Queues["foo"].
|
11
|
-
Agent::Queues["foo"].type.
|
12
|
-
Agent::Queues["foo"].max.
|
10
|
+
expect(Agent::Queues["foo"]).to be_a(Agent::Queue)
|
11
|
+
expect(Agent::Queues["foo"].type).to eq(String)
|
12
|
+
expect(Agent::Queues["foo"].max).to eq(10)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should delete queues" do
|
16
16
|
Agent::Queues.register("foo", String, 10)
|
17
17
|
Agent::Queues.delete("foo")
|
18
|
-
Agent::Queues["foo"].
|
18
|
+
expect(Agent::Queues["foo"]).to be_nil
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should remove all queues queues" do
|
22
22
|
Agent::Queues.register("foo", String, 10)
|
23
23
|
Agent::Queues.register("bar", String, 10)
|
24
24
|
Agent::Queues.clear
|
25
|
-
Agent::Queues["foo"].
|
26
|
-
Agent::Queues["bar"].
|
25
|
+
expect(Agent::Queues["foo"]).to be_nil
|
26
|
+
expect(Agent::Queues["bar"]).to be_nil
|
27
27
|
end
|
28
28
|
end
|
data/spec/selector_spec.rb
CHANGED
@@ -7,14 +7,14 @@ describe Agent::Selector do
|
|
7
7
|
# - http://golang.org/doc/go_spec.html#Select_statements
|
8
8
|
|
9
9
|
it "should yield Selector on select call" do
|
10
|
-
select! {|s| s.
|
10
|
+
select! {|s| expect(s).to be_kind_of Agent::Selector}
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should return immediately on empty select block" do
|
14
14
|
s = Time.now.to_f
|
15
15
|
select! {}
|
16
16
|
|
17
|
-
(Time.now.to_f - s).
|
17
|
+
expect(Time.now.to_f - s).to be_within(0.05).of(0)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should timeout select statement" do
|
@@ -23,25 +23,25 @@ describe Agent::Selector do
|
|
23
23
|
s.timeout(0.1) { r.push :timeout }
|
24
24
|
end
|
25
25
|
|
26
|
-
r.first.
|
27
|
-
(Time.now.to_f - now).
|
26
|
+
expect(r.first).to eq(:timeout)
|
27
|
+
expect(Time.now.to_f - now).to be_within(0.05).of(0.1)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not raise an error when a block is missing on default" do
|
31
|
-
|
31
|
+
expect {
|
32
32
|
select! do |s|
|
33
33
|
s.default
|
34
34
|
end
|
35
|
-
}.
|
35
|
+
}.not_to raise_error
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should not raise an error when a block is missing on timeout" do
|
39
|
-
|
39
|
+
expect {
|
40
40
|
select! do |s|
|
41
41
|
s.timeout(1)
|
42
42
|
s.default
|
43
43
|
end
|
44
|
-
}.
|
44
|
+
}.not_to raise_error
|
45
45
|
end
|
46
46
|
|
47
47
|
context "with unbuffered channels" do
|
@@ -58,26 +58,26 @@ describe Agent::Selector do
|
|
58
58
|
s.case(@c, :send, 1)
|
59
59
|
s.case(@c, :receive)
|
60
60
|
s.default
|
61
|
-
s.cases.size.
|
61
|
+
expect(s.cases.size).to eq(3)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should not raise an error when a block is missing on receive" do
|
66
|
-
|
66
|
+
expect {
|
67
67
|
select! do |s|
|
68
68
|
s.case(@c, :receive)
|
69
69
|
s.default
|
70
70
|
end
|
71
|
-
}.
|
71
|
+
}.not_to raise_error
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should not raise an error when a block is missing on send" do
|
75
|
-
|
75
|
+
expect {
|
76
76
|
select! do |s|
|
77
77
|
s.case(@c, :send, 1)
|
78
78
|
s.default
|
79
79
|
end
|
80
|
-
}.
|
80
|
+
}.not_to raise_error
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should scan all cases to identify available actions and execute first available one" do
|
@@ -92,8 +92,8 @@ describe Agent::Selector do
|
|
92
92
|
s.case(@c, :receive) { r.push 3 }
|
93
93
|
end
|
94
94
|
|
95
|
-
r.size.
|
96
|
-
r.first.
|
95
|
+
expect(r.size).to eq(1)
|
96
|
+
expect(r.first).to eq(2)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should evaluate default case immediately if no other cases match" do
|
@@ -104,28 +104,57 @@ describe Agent::Selector do
|
|
104
104
|
s.default { r.push :default }
|
105
105
|
end
|
106
106
|
|
107
|
-
r.size.
|
108
|
-
r.first.
|
107
|
+
expect(r.size).to eq(1)
|
108
|
+
expect(r.first).to eq(:default)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should evaluate a matching prior closed channel in preference to the default case" do
|
112
|
+
r = []
|
113
|
+
|
114
|
+
@c.close
|
115
|
+
select! do |s|
|
116
|
+
s.case(@c, :receive) { r.push :from_closed }
|
117
|
+
s.default { r.push :default }
|
118
|
+
end
|
119
|
+
|
120
|
+
expect(r.size).to eq(1)
|
121
|
+
expect(r.first).to eq(:from_closed)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should receive from channels that are closed while selecting on said channels" do
|
125
|
+
r = []
|
126
|
+
|
127
|
+
Thread.new do
|
128
|
+
sleep 0.2
|
129
|
+
@c.close
|
130
|
+
end
|
131
|
+
|
132
|
+
select! do |s|
|
133
|
+
s.case(@c, :receive) { r.push :from_closed }
|
134
|
+
end
|
135
|
+
|
136
|
+
expect(r.size).to eq(1)
|
137
|
+
expect(r.first).to eq(:from_closed)
|
109
138
|
end
|
110
139
|
|
111
140
|
it "should raise an error if the channel is closed out from under it and you are sending to it" do
|
112
141
|
go!{ sleep 0.25; @c.close }
|
113
142
|
|
114
|
-
|
143
|
+
expect {
|
115
144
|
select! do |s|
|
116
145
|
s.case(@c, :send, 1)
|
117
146
|
end
|
118
|
-
}.
|
147
|
+
}.to raise_error(Agent::Errors::ChannelClosed)
|
119
148
|
end
|
120
149
|
|
121
150
|
it "should not raise an error if the channel is closed out from under it and you are receiving from it" do
|
122
151
|
go!{ sleep 0.25; @c.close }
|
123
152
|
|
124
|
-
|
153
|
+
expect {
|
125
154
|
select! do |s|
|
126
155
|
s.case(@c, :receive){}
|
127
156
|
end
|
128
|
-
}.
|
157
|
+
}.not_to raise_error
|
129
158
|
end
|
130
159
|
|
131
160
|
context "select immediately available channel" do
|
@@ -142,8 +171,8 @@ describe Agent::Selector do
|
|
142
171
|
s.default { r.push :empty }
|
143
172
|
end
|
144
173
|
|
145
|
-
r.size.
|
146
|
-
r.first.
|
174
|
+
expect(r.size).to eq(1)
|
175
|
+
expect(r.first).to eq(:receive)
|
147
176
|
c.close
|
148
177
|
end
|
149
178
|
|
@@ -161,8 +190,8 @@ describe Agent::Selector do
|
|
161
190
|
s.default { r.push :empty }
|
162
191
|
end
|
163
192
|
|
164
|
-
r.size.
|
165
|
-
r.first.
|
193
|
+
expect(r.size).to eq(1)
|
194
|
+
expect(r.first).to eq(:send)
|
166
195
|
c.close
|
167
196
|
end
|
168
197
|
end
|
@@ -180,8 +209,8 @@ describe Agent::Selector do
|
|
180
209
|
s.case(c, :receive) {|value| r.push value }
|
181
210
|
end
|
182
211
|
|
183
|
-
r.size.
|
184
|
-
(Time.now.to_f - now).
|
212
|
+
expect(r.size).to eq(1)
|
213
|
+
expect(Time.now.to_f - now).to be_within(0.1).of(0.2)
|
185
214
|
c.close
|
186
215
|
end
|
187
216
|
|
@@ -190,13 +219,13 @@ describe Agent::Selector do
|
|
190
219
|
|
191
220
|
# brittle.. counting on select to execute within 0.5s
|
192
221
|
now = Time.now.to_f
|
193
|
-
go!{sleep(0.2); c.receive[0].
|
222
|
+
go!{sleep(0.2); expect(c.receive[0]).to eq(2 )}
|
194
223
|
|
195
224
|
select! do |s|
|
196
225
|
s.case(c, :send, 2)
|
197
226
|
end
|
198
227
|
|
199
|
-
(Time.now.to_f - now).
|
228
|
+
expect(Time.now.to_f - now).to be_within(0.1).of(0.2)
|
200
229
|
c.close
|
201
230
|
end
|
202
231
|
|
@@ -224,13 +253,13 @@ describe Agent::Selector do
|
|
224
253
|
|
225
254
|
ack.receive
|
226
255
|
|
227
|
-
res.size.
|
228
|
-
res.first.
|
256
|
+
expect(res.size).to eq(1)
|
257
|
+
expect(res.first).to eq(3)
|
229
258
|
|
230
259
|
# 0.3s goroutine should eventually fire
|
231
|
-
cr.receive[0].
|
260
|
+
expect(cr.receive[0]).to eq(2)
|
232
261
|
|
233
|
-
(Time.now.to_f - now).
|
262
|
+
expect(Time.now.to_f - now).to be_within(0.05).of(0.3)
|
234
263
|
cw.close
|
235
264
|
cr.close
|
236
265
|
end
|
@@ -250,26 +279,26 @@ describe Agent::Selector do
|
|
250
279
|
select! do |s|
|
251
280
|
s.case(@c, :send, 1)
|
252
281
|
s.case(@c, :receive)
|
253
|
-
s.cases.size.
|
282
|
+
expect(s.cases.size).to eq(2)
|
254
283
|
end
|
255
284
|
end
|
256
285
|
|
257
286
|
it "should not raise an error when a block is missing on receive" do
|
258
|
-
|
287
|
+
expect {
|
259
288
|
select! do |s|
|
260
289
|
s.case(@c, :receive)
|
261
290
|
s.default
|
262
291
|
end
|
263
|
-
}.
|
292
|
+
}.not_to raise_error
|
264
293
|
end
|
265
294
|
|
266
295
|
it "should not raise an error when a block is missing on send" do
|
267
|
-
|
296
|
+
expect {
|
268
297
|
select! do |s|
|
269
298
|
s.case(@c, :send, 1)
|
270
299
|
s.default
|
271
300
|
end
|
272
|
-
}.
|
301
|
+
}.not_to raise_error
|
273
302
|
end
|
274
303
|
|
275
304
|
it "should scan all cases to identify available actions and execute first available one" do
|
@@ -282,8 +311,8 @@ describe Agent::Selector do
|
|
282
311
|
s.case(@c, :receive) { r.push 3 }
|
283
312
|
end
|
284
313
|
|
285
|
-
r.size.
|
286
|
-
r.first.
|
314
|
+
expect(r.size).to eq(1)
|
315
|
+
expect(r.first).to eq(2)
|
287
316
|
end
|
288
317
|
|
289
318
|
it "should evaluate default case immediately if no other cases match" do
|
@@ -296,8 +325,38 @@ describe Agent::Selector do
|
|
296
325
|
s.default { r.push :default }
|
297
326
|
end
|
298
327
|
|
299
|
-
r.size.
|
300
|
-
r.first.
|
328
|
+
expect(r.size).to eq(1)
|
329
|
+
expect(r.first).to eq(:default)
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should evaluate a matching prior closed channel in preference to the default case" do
|
333
|
+
r = []
|
334
|
+
|
335
|
+
@c.close
|
336
|
+
|
337
|
+
select! do |s|
|
338
|
+
s.case(@c, :receive) { r.push :from_closed }
|
339
|
+
s.default { r.push :default }
|
340
|
+
end
|
341
|
+
|
342
|
+
expect(r.size).to eq(1)
|
343
|
+
expect(r.first).to eq(:from_closed)
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should receive from channels that are closed while selecting on said channels" do
|
347
|
+
r = []
|
348
|
+
|
349
|
+
Thread.new do
|
350
|
+
sleep 0.2
|
351
|
+
@c.close
|
352
|
+
end
|
353
|
+
|
354
|
+
select! do |s|
|
355
|
+
s.case(@c, :receive) { r.push :from_closed }
|
356
|
+
end
|
357
|
+
|
358
|
+
expect(r.size).to eq(1)
|
359
|
+
expect(r.first).to eq(:from_closed)
|
301
360
|
end
|
302
361
|
|
303
362
|
it "should raise an error if the channel is closed out from under it and you are sending to it" do
|
@@ -305,21 +364,21 @@ describe Agent::Selector do
|
|
305
364
|
|
306
365
|
go!{ sleep 0.25; @c.close }
|
307
366
|
|
308
|
-
|
367
|
+
expect {
|
309
368
|
select! do |s|
|
310
369
|
s.case(@c, :send, 1)
|
311
370
|
end
|
312
|
-
}.
|
371
|
+
}.to raise_error(Agent::Errors::ChannelClosed)
|
313
372
|
end
|
314
373
|
|
315
374
|
it "should not raise an error if the channel is closed out from under it and you are receiving from it" do
|
316
375
|
go!{ sleep 0.25; @c.close }
|
317
376
|
|
318
|
-
|
377
|
+
expect {
|
319
378
|
select! do |s|
|
320
379
|
s.case(@c, :receive){}
|
321
380
|
end
|
322
|
-
}.
|
381
|
+
}.not_to raise_error
|
323
382
|
end
|
324
383
|
|
325
384
|
context "select immediately available channel" do
|
@@ -334,8 +393,8 @@ describe Agent::Selector do
|
|
334
393
|
s.default { r.push :empty }
|
335
394
|
end
|
336
395
|
|
337
|
-
r.size.
|
338
|
-
r.first.
|
396
|
+
expect(r.size).to eq(1)
|
397
|
+
expect(r.first).to eq(:receive)
|
339
398
|
c.close
|
340
399
|
end
|
341
400
|
|
@@ -349,8 +408,8 @@ describe Agent::Selector do
|
|
349
408
|
s.default { r.push :empty }
|
350
409
|
end
|
351
410
|
|
352
|
-
r.size.
|
353
|
-
r.first.
|
411
|
+
expect(r.size).to eq(1)
|
412
|
+
expect(r.first).to eq(:send)
|
354
413
|
c.close
|
355
414
|
end
|
356
415
|
end
|
@@ -368,8 +427,8 @@ describe Agent::Selector do
|
|
368
427
|
s.case(c, :receive) {|value| r.push value }
|
369
428
|
end
|
370
429
|
|
371
|
-
r.size.
|
372
|
-
(Time.now.to_f - now).
|
430
|
+
expect(r.size).to eq(1)
|
431
|
+
expect(Time.now.to_f - now).to be_within(0.1).of(0.2)
|
373
432
|
c.close
|
374
433
|
end
|
375
434
|
|
@@ -385,8 +444,8 @@ describe Agent::Selector do
|
|
385
444
|
s.case(c, :send, 2)
|
386
445
|
end
|
387
446
|
|
388
|
-
c.receive[0].
|
389
|
-
(Time.now.to_f - now).
|
447
|
+
expect(c.receive[0]).to eq(2)
|
448
|
+
expect(Time.now.to_f - now).to be_within(0.1).of(0.2)
|
390
449
|
c.close
|
391
450
|
end
|
392
451
|
|
@@ -416,13 +475,13 @@ describe Agent::Selector do
|
|
416
475
|
ack.receive
|
417
476
|
|
418
477
|
# 0.8s goroutine should have consumed the message first
|
419
|
-
res.size.
|
420
|
-
res.first.
|
478
|
+
expect(res.size).to eq(1)
|
479
|
+
expect(res.first).to eq(1)
|
421
480
|
|
422
481
|
# send case should have fired, and we should have a message
|
423
|
-
cw.receive[0].
|
482
|
+
expect(cw.receive[0]).to eq(3)
|
424
483
|
|
425
|
-
(Time.now.to_f - now).
|
484
|
+
expect(Time.now.to_f - now).to be_within(0.1).of(0.2)
|
426
485
|
cw.close
|
427
486
|
cr.close
|
428
487
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/uuid_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Agent::UUID do
|
4
4
|
it "should generate a uuid" do
|
5
|
-
Agent::UUID.generate.
|
5
|
+
expect(Agent::UUID.generate).to match(/^[0-9a-f]{8}_[0-9a-f]{4}_[0-9a-f]{4}_[0-9a-f]{4}_[0-9a-f]{12}$/)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should generate unique IDs across the BLOCK_SIZE boundary" do
|
9
9
|
upper_bound = Agent::UUID::BLOCK_SIZE * 2 + 10
|
10
10
|
uuids = (1..upper_bound).map{ Agent::UUID.generate }
|
11
|
-
uuids.size.
|
11
|
+
expect(uuids.size).to eq(uuids.uniq.size)
|
12
12
|
end
|
13
13
|
end
|
data/spec/wait_group_spec.rb
CHANGED
@@ -17,17 +17,17 @@ describe Agent::WaitGroup do
|
|
17
17
|
|
18
18
|
it "should decrement the cound when WaitGroup#done is called" do
|
19
19
|
@wait_group.add(1)
|
20
|
-
@wait_group.count.
|
20
|
+
expect(@wait_group.count).to eq(1)
|
21
21
|
@wait_group.done
|
22
|
-
@wait_group.count.
|
22
|
+
expect(@wait_group.count).to eq(0)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should error when the count becomes negative via WaitGroup#add" do
|
26
|
-
|
26
|
+
expect{ @wait_group.add(-1) }.to raise_error(Agent::Errors::NegativeWaitGroupCount)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should error when the count becomes negative via WaitGroup#done" do
|
30
|
-
|
30
|
+
expect{ @wait_group.done }.to raise_error(Agent::Errors::NegativeWaitGroupCount)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should allow waiting on a wait_group and should signal when it is done" do
|
@@ -39,7 +39,7 @@ describe Agent::WaitGroup do
|
|
39
39
|
|
40
40
|
@wait_group.wait
|
41
41
|
|
42
|
-
(Time.now - t).
|
42
|
+
expect(Time.now - t).to be_within(0.01).of(0.2)
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|