Skip to content

Commit

Permalink
Merge pull request #90 from bobtfish/fix_tcp_mode
Browse files Browse the repository at this point in the history
Fix to not include a cookie in TCP mode.
  • Loading branch information
igor47 committed Oct 17, 2014
2 parents a1cfd34 + 4f48b34 commit e012cd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/synapse/haproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,10 @@ def generate_backend_stanza(watcher, config)
config.map {|c| "\t#{c}"},
watcher.backends.shuffle.map {|backend|
backend_name = construct_name(backend)
"\tserver #{backend_name} #{backend['host']}:#{backend['port']} " \
"cookie #{backend_name} #{watcher.haproxy['server_options']}" }
b = "\tserver #{backend_name} #{backend['host']}:#{backend['port']}"
b = "#{b} cookie #{backend_name}" unless config.include?('mode tcp')
b = "#{b} #{watcher.haproxy['server_options']}"
b }
]
end

Expand Down
25 changes: 22 additions & 3 deletions spec/lib/synapse/haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@ class MockWatcher; end;
describe Synapse::Haproxy do
subject { Synapse::Haproxy.new(config['haproxy']) }

it 'updating the config' do
let(:mockwatcher) do
mockWatcher = double(Synapse::ServiceWatcher)
subject.should_receive(:generate_config)
subject.update_config([mockWatcher])
allow(mockWatcher).to receive(:name).and_return('example_service')
backends = [{ 'host' => 'somehost', 'port' => '5555'}]
allow(mockWatcher).to receive(:backends).and_return(backends)
allow(mockWatcher).to receive(:haproxy).and_return({'server_options' => "check inter 2000 rise 3 fall 2"})
mockWatcher
end

it 'updating the config' do
expect(subject).to receive(:generate_config)
subject.update_config([mockwatcher])
end

it 'generates backend stanza' do
mockConfig = []
expect(subject.generate_backend_stanza(mockwatcher, mockConfig)).to eql(["\nbackend example_service", [], ["\tserver somehost:5555 somehost:5555 cookie somehost:5555 check inter 2000 rise 3 fall 2"]])
end

it 'generates backend stanza without cookies for tcp mode' do
mockConfig = ['mode tcp']
expect(subject.generate_backend_stanza(mockwatcher, mockConfig)).to eql(["\nbackend example_service", ["\tmode tcp"], ["\tserver somehost:5555 somehost:5555 check inter 2000 rise 3 fall 2"]])
end

end

0 comments on commit e012cd3

Please sign in to comment.