Skip to content

Commit

Permalink
Add test for Puma::Server.current.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 12, 2024
1 parent 73b79ac commit 6e6e5b5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/test_puma_server_current.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.

require_relative "helper"

require "puma/server"

class PumaServerCurrentApplication
def call(env)
[200, {"Content-Type" => "text/plain"}, [Puma::Server.current.to_s]]
end
end

class PumaServerCurrentTest < Minitest::Test
parallelize_me!

def setup
@tester = PumaServerCurrentApplication.new
@server = Puma::Server.new @tester, nil, {log_writer: Puma::LogWriter.strings, clean_thread_locals: true}
@port = (@server.add_tcp_listener "127.0.0.1", 0).addr[1]
@tcp = "http://127.0.0.1:#{@port}"
@url = URI.parse(@tcp)
@server.run
end

def teardown
@server.stop(true)
end

def test_empty_locals
server_string = @server.to_s
responses = []

# This must be a persistent connection to hit the `clean_thread_locals` code path.
Net::HTTP.new(@url.host, @url.port).start do |connection|
3.times do
responses << connection.get("/").body
end
end

assert_equal [server_string]*3, responses
end
end

0 comments on commit 6e6e5b5

Please sign in to comment.