Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[synapse] fix bug in generate_backend_stanze #242

Merged
merged 1 commit into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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