Created
December 7, 2012 08:51
-
-
Save fxposter/4231894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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