Skip to content

Commit

Permalink
fix server port loading order issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zvkemp committed May 5, 2023
1 parent 3b629e1 commit a83269c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions spec/support/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Server
class << self
attr_reader :port

def started?
!!@started
end

def start(opts)
if @started
if opts[:Port] && opts[:Port] != port
Expand All @@ -28,8 +32,9 @@ def start(opts)
return if @started
@started = true
@server = Puma::Server.new(self)
listener = @server.add_tcp_listener("127.0.0.1", opts.fetch(:Port))
listener = @server.add_tcp_listener("127.0.0.1", opts[:Port])
_, @port, = listener.addr

@server_thread = @server.run
end
end
Expand Down Expand Up @@ -219,17 +224,18 @@ def report_environment
end

def start_server(opts = {})
opts[:Port] ||= port
opts[:environment] ||= "test"
opts[:AccessLog] ||= []
opts[:debug] ||= ENV.fetch("DEBUG", nil)

server.start(opts)
Server.start(opts)

server.reset
Server.reset
end

def port
start_server unless Server.started?

Server.port
end

Expand Down

0 comments on commit a83269c

Please sign in to comment.