Skip to content

Instantly share code, notes, and snippets.

@fxposter
Created December 7, 2012 08:51
Show Gist options
  • Save fxposter/4231894 to your computer and use it in GitHub Desktop.
Save fxposter/4231894 to your computer and use it in GitHub Desktop.
describe PortChecker do
around :each do |block|
EventMachine.run(&block)
end
it 'succeeds immediately if port is open' do
success = false
failure = false
EventMachine.start_server('localhost', 11111)
EventMachine.add_timer 0.05 do
success.should be_true
failure.should be_false
EventMachine.stop
end
PortChecker.new('localhost', 11111, 0.1, 1)
.callback {
success = true
}.errback {
failure = true
}
end
it 'waits until the port is open' do
success = false
failure = false
EventMachine.add_timer 0.05 do
success.should be_false
failure.should be_false
EventMachine.start_server('localhost', 11111)
end
EventMachine.add_timer 0.25 do
success.should be_true
failure.should be_false
EventMachine.stop
end
PortChecker.new('localhost', 11111, 0.1, 1)
.callback {
success = true
}.errback {
failure = true
}
end
it 'fails when the port is not open within specified timeout interval' do
success = false
failure = false
EventMachine.add_timer 0.25 do
success.should be_false
failure.should be_false
end
EventMachine.add_timer 0.6 do
success.should be_false
failure.should be_true
EventMachine.stop
end
PortChecker.new('localhost', 11111, 0.1, 0.5)
.callback {
success = true
}.errback {
failure = true
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment