fluffle 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/lib/fluffle/errors.rb +4 -0
- data/lib/fluffle/version.rb +1 -1
- data/spec/confirmer_spec.rb +74 -0
- data/spec/middleware_stack_spec.rb +40 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '038ddf285b4ce9d146162683b41abd91a89f9295'
|
4
|
+
data.tar.gz: cc7c21fe760f9f7337a3b05ecc41896964f9aa86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe9589b93d03cb89f2de6aa09577fafc954fadd305c7de68637493ae5d8191a2f021369a84a1ffed4bba6bcce4885e593f4b72f635e516bfd5c2d8fc3123f8a3
|
7
|
+
data.tar.gz: '01391ea97e789e91d373762f483d4c10592fdfab8da4aa51a46985b950db8c708bf5127f43abd6f1fc242bfb8a5e802fa1608d06871d95ddbb185f68b14489f4'
|
data/.travis.yml
CHANGED
data/lib/fluffle/errors.rb
CHANGED
@@ -17,6 +17,10 @@ module Fluffle
|
|
17
17
|
class ConfirmTimeoutError < TimeoutError
|
18
18
|
end
|
19
19
|
|
20
|
+
# Raised if it received a nack from the broker
|
21
|
+
class NackError < StandardError
|
22
|
+
end
|
23
|
+
|
20
24
|
# Raised if it received a return from the server
|
21
25
|
class ReturnError < StandardError
|
22
26
|
end
|
data/lib/fluffle/version.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fluffle::Confirmer do
|
4
|
+
class StubChannel
|
5
|
+
attr_accessor :confirm_handler, :tag
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@tag = 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def confirm_select(block = nil)
|
12
|
+
@confirm_handler = block
|
13
|
+
end
|
14
|
+
|
15
|
+
def next_publish_seq_no
|
16
|
+
@tag
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
@channel = StubChannel.new
|
22
|
+
@confirmer = Fluffle::Confirmer.new channel: @channel
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#with_confirmation' do
|
26
|
+
let(:default_timeout) { 5 }
|
27
|
+
|
28
|
+
before do
|
29
|
+
@confirmer.confirm_select
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'raises if it times out' do
|
33
|
+
expect {
|
34
|
+
@confirmer.with_confirmation(timeout: 0.001) { sleep 0.002 }
|
35
|
+
}.to raise_error(Fluffle::Errors::ConfirmTimeoutError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'raises if it receives a nack' do
|
39
|
+
send_nack = -> {
|
40
|
+
multiple = false
|
41
|
+
nack = true
|
42
|
+
@channel.confirm_handler.call @channel.tag, multiple, nack
|
43
|
+
}
|
44
|
+
|
45
|
+
expect {
|
46
|
+
@confirmer.with_confirmation(timeout: default_timeout) {
|
47
|
+
send_nack.call
|
48
|
+
}
|
49
|
+
}.to raise_error(Fluffle::Errors::NackError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns the result if it receives an ack' do
|
53
|
+
send_confirm = -> {
|
54
|
+
multiple = false
|
55
|
+
nack = false
|
56
|
+
@channel.confirm_handler.call @channel.tag, multiple, nack
|
57
|
+
}
|
58
|
+
|
59
|
+
result = double 'result'
|
60
|
+
|
61
|
+
expect(
|
62
|
+
@confirmer.with_confirmation(timeout: default_timeout) {
|
63
|
+
Thread.new {
|
64
|
+
sleep 0.1
|
65
|
+
send_confirm.call
|
66
|
+
}
|
67
|
+
|
68
|
+
sleep 0.2
|
69
|
+
result
|
70
|
+
}
|
71
|
+
).to eq result
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fluffle::MiddlewareStack do
|
4
|
+
describe '#call' do
|
5
|
+
it 'calls the middleware in the correct order' do
|
6
|
+
order = []
|
7
|
+
|
8
|
+
middleware1 = ->(parent) {
|
9
|
+
order.push :pre1
|
10
|
+
result = parent.call
|
11
|
+
order.push :post1
|
12
|
+
result
|
13
|
+
}
|
14
|
+
|
15
|
+
middleware2 = ->(parent) {
|
16
|
+
order.push :pre2
|
17
|
+
result = parent.call
|
18
|
+
order.push :post2
|
19
|
+
result
|
20
|
+
}
|
21
|
+
|
22
|
+
result = double 'result'
|
23
|
+
block = -> {
|
24
|
+
order.push :block
|
25
|
+
result
|
26
|
+
}
|
27
|
+
|
28
|
+
subject.push middleware1
|
29
|
+
subject.push middleware2
|
30
|
+
expect(subject.call(&block)).to eq result
|
31
|
+
expect(order).to eq [
|
32
|
+
:pre1,
|
33
|
+
:pre2,
|
34
|
+
:block,
|
35
|
+
:post2,
|
36
|
+
:post1,
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluffle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dirk Gadsden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -141,8 +141,10 @@ files:
|
|
141
141
|
- lib/fluffle/testing.rb
|
142
142
|
- lib/fluffle/version.rb
|
143
143
|
- spec/client_spec.rb
|
144
|
+
- spec/confirmer_spec.rb
|
144
145
|
- spec/handlers/delegator_spec.rb
|
145
146
|
- spec/handlers/dispatcher_spec.rb
|
147
|
+
- spec/middleware_stack_spec.rb
|
146
148
|
- spec/server_spec.rb
|
147
149
|
- spec/spec_helper.rb
|
148
150
|
homepage: https://github.com/Everlane/fluffle
|