lib/saucelabs_adapter/utilities.rb in saucelabs-adapter-0.8.4 vs lib/saucelabs_adapter/utilities.rb in saucelabs-adapter-0.8.5
- old
+ new
@@ -17,7 +17,22 @@
end
def raise_with_message(message)
raise "#{diagnostics_prefix} #{message}"
end
+
+ def find_unused_port(hostname, range = (3000..5000))
+ debug 'searching for unused port', 2
+ range.each do |port|
+ debug "trying #{hostname}:#{port}", 2
+ begin
+ socket = TCPSocket.new(hostname, port)
+ rescue Errno::ECONNREFUSED
+ debug "it's good, returning #{port}", 2
+ return port
+ ensure
+ socket.close if socket
+ end
+ end
+ end
end
end
\ No newline at end of file