Lbspec
Lbspec is an RSpec plugin for easy Loadbalancer testing.
Installation
Add this line to your application's Gemfile:
gem 'lbspec'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lbspec
Functions
You can use lbspec to test load balancers.
#transfer
#transfer tests if a virtual host on a load balancer transfer requests to target nodes.
chains
You can use following chains with #transfer.
- port
- Tests if a virtual host transfers requests to specified port on target nodes.
- tcp
- Tests with tcp packets for the virtual host.
- udp
- Tests with udp packets for the virtual host.
- http
- Tests with an http request for the virtual host.
- https
- Tests with an https request for the virtual host.
- path
- Specifies a path for http or https requests.
- from
- Specifies which host sends to the virtual host.
- options
- Options which can be used in http or https request commands.
- You can use
optionsif you configure request commands or capture commands.
Requires
- Users need to be able to login with ssh to the target nodes.
- Users need to be able to
sudoon the target nodes. - netcat and ngrep are needed to be installed.
Limitations
- Lbspec uses only ssh configuration in ~/.ssh/config
Usage
Lbspec is best described by example. First, require lbspec in your spec_helper.rb:
# spec/spec_helper.rb
require 'rspec'
require 'lbspec'
Then, create a spec like this:
require_relative 'spec_helper'
describe 'vhost_a' do
it { should transfer('node_a') }
end
describe 'vhost_b' do
it { should transfer(['node_b','node_c']) }
end
describe 'vhost_c:80' do
it { should transfer(['node_b','node_c']).port(80) }
end
describe 'vhost_c:80' do
it { should transfer(['node_b','node_c']).port(53).udp }
end
describe 'vhost_c:80' do
it { should transfer('node_c').http.path('/test/') }
end
describe 'vhost_c:443' do
it { should transfer(['node_b','node_c']).port(80).https.path('/test/') }
end
describe 'vhost_c:443' do
it do
should transfer(['node_b','node_c']).port(80).https.path('/test/')
.(ignore_valid_ssl: true)
end
end
describe 'vhost_c:80' do
it { should transfer('node_c').http.path('/test/').from('node_a') }
end
How it works
#transfer
- ssh to nodes
- cupture probe
- access with probe
- judge

Configuration
#transfer
You can change how to capture probes and access to vhost with probes. You can replace default procedures to your procedures in spec_helpers or .spec files as follows. If you use Lbspec::Util.exec_command(), you can specify the node which generate request.
RSpec.configuration.lbspec_capture_command =
lambda do |port, prove|
port_str = port > 0 ? "port #{port}" : ''
"sudo ngrep #{prove} #{port_str} | grep -v \"match:\""
end
RSpec.configuration.lbspec_https_request_command =
lambda do |addr, port, path, prove|
uri = 'https://' + "#{addr}:#{port}#{path}?#{prove}"
Lbspec::Util.exec_command("curl -o /dev/null -sk #{uri}", @request_node)
end
You can also use the procedures with options with a chain options.
RSpec.configuration.lbspec_https_request_command =
lambda do |addr, port, path, prove|
opt = [:timeout] ? " -m #{@options[:timeout]}" : ''
opt << ([:ignore_valid_ssl] ? ' -k' : '')
Lbspec::Util.exec_command("curl -o /dev/null -s #{opt} #{uri}", @request_node)
end
You can replace following items.
lbspec_capture_commandwith|port, prove|lbspec_udp_request_commandwith|addr, port, prove|lbspec_tcp_request_commandwith|addr, port, prove|lbspec_http_request_commandwith|addr, port, path, prove|lbspec_https_request_commandwith|addr, port, path, prove|
Contributing
- Fork it ( http://github.com/otahi/lbspec/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request


