Fix port collision in tests
This commit is contained in:
parent
398017ba6e
commit
c1623ee740
|
@ -39,7 +39,10 @@ describe VagrantPlugins::FTPPush::FTPAdapter do
|
|||
include_context "unit"
|
||||
|
||||
before(:all) do
|
||||
@server = FakeFtp::Server.new(21212, 21213)
|
||||
@server = nil
|
||||
with_random_port do |port1, port2|
|
||||
@server = FakeFtp::Server.new(port1, port2)
|
||||
end
|
||||
@server.start
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ describe VagrantPlugins::FTPPush::Push do
|
|||
let(:env) { isolated_environment }
|
||||
let(:config) do
|
||||
double("config",
|
||||
host: "127.0.0.1:51234",
|
||||
host: "127.0.0.1:#{@port}",
|
||||
username: "sethvargo",
|
||||
password: "bacon",
|
||||
passive: false,
|
||||
|
@ -34,7 +34,11 @@ describe VagrantPlugins::FTPPush::Push do
|
|||
|
||||
describe "#push" do
|
||||
before(:all) do
|
||||
@server = FakeFtp::Server.new(51234, 21213)
|
||||
@server = nil
|
||||
with_random_port do |port1, port2|
|
||||
@port = port1
|
||||
@server = FakeFtp::Server.new(port1, port2)
|
||||
end
|
||||
@server.start
|
||||
|
||||
@dir = Dir.mktmpdir
|
||||
|
|
|
@ -116,4 +116,18 @@ shared_context "unit" do
|
|||
ENV[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
# This helper provides a randomly available port(s) for each argument to the
|
||||
# block.
|
||||
def with_random_port(&block)
|
||||
ports = []
|
||||
|
||||
block.arity.times do
|
||||
server = TCPServer.new('127.0.0.1', 0)
|
||||
ports << server.addr[1]
|
||||
server.close
|
||||
end
|
||||
|
||||
block.call(*ports)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,8 +42,12 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
|||
tf = Tempfile.new("vagrant")
|
||||
tf.close
|
||||
|
||||
port = 21212
|
||||
server = FakeFtp::Server.new(port, port+1)
|
||||
port = nil
|
||||
server = nil
|
||||
with_random_port do |port1, port2|
|
||||
port = port1
|
||||
server = FakeFtp::Server.new(port1, port2)
|
||||
end
|
||||
server.add_file(path.basename, path.read)
|
||||
server.start
|
||||
yield port
|
||||
|
|
Loading…
Reference in New Issue