Skip to content

Commit

Permalink
Merge pull request #242 from lap1817/feng-pan-synapse
Browse files Browse the repository at this point in the history
[synapse] fix bug in generate_backend_stanze
  • Loading branch information
jolynch authored Sep 15, 2017
2 parents b1ef754 + 7f501c8 commit 26c5ab1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/synapse/config_generator/haproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ def generate_backend_stanza(watcher, config)

# The ordering here is important. First we add all the backends in the
# disabled state...
@state_cache.backends(watcher).each do |backend_name, backend|
@state_cache.backends(watcher.name).each do |backend_name, backend|
backends[backend_name] = backend.merge('enabled' => false)
# We remember the haproxy_server_id from a previous reload here.
# Note though that if live servers below define haproxy_server_id
Expand Down
42 changes: 42 additions & 0 deletions spec/lib/synapse/haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,48 @@ class MockWatcher; end;
expect(subject.generate_backend_stanza(mockwatcher, mockConfig)).to eql(["\nbackend example_service", [], ["\tserver somehost:5555 somehost:5555 id 1 cookie somehost:5555 check inter 2000 rise 3 fall 2"]])
end

describe 'when known backend gets offline' do
let(:mockStateCache) do
mockCache = double(Synapse::ConfigGenerator::Haproxy::HaproxyState)
allow(mockCache).to receive(:backends).with(mockwatcher.name).and_return(
{
"somehost2:5555" => {
"host" => "somehost2",
"port" => 5555,
'haproxy_server_id' => 10,
}
}
)
mockCache
end

before do
allow(mockwatcher).to receive(:config_for_generator).and_return(
{
'haproxy' => {
'server_options' => "check inter 2000 rise 3 fall 2",
'backend_order' => 'no_shuffle',
}
}
)
subject.instance_variable_set(:@state_cache, mockStateCache)
end

it 'generates backend stanza with the disabled stat' do
mockConfig = ['mode tcp']
expect(subject.generate_backend_stanza(mockwatcher, mockConfig)).to eql(
[
"\nbackend example_service",
["\tmode tcp"],
[
"\tserver somehost2:5555 somehost2:5555 id 10 check inter 2000 rise 3 fall 2 disabled",
"\tserver somehost:5555 somehost:5555 id 1 check inter 2000 rise 3 fall 2"
]
]
)
end
end

describe 'generate backend stanza in correct order' do
let(:multiple_backends_stanza_map) do
{
Expand Down

0 comments on commit 26c5ab1

Please sign in to comment.