Skip to content

Commit

Permalink
Fix StatsD server port for test server in spec (#1073)
Browse files Browse the repository at this point in the history
Set the port as an instance on the server instance, and not rely on the
env var to be read in the thread spawned during the test. It might not
be read properly.

[skip changeset]
  • Loading branch information
tombruijn committed Apr 29, 2024
1 parent ee08eed commit aea50d2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spec/lib/puma/appsignal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ def error(message)
# StatsD server used for these tests.
# Open a UDPSocket and listen for messages sent by the AppSignal Puma plugin.
class StatsdServer
def initialize(statsd_port)
@statsd_port = statsd_port
end

def start
stop
@socket = UDPSocket.new
@socket.bind("127.0.0.1", ENV.fetch("APPSIGNAL_STATSD_PORT"))
@socket.bind("127.0.0.1", @statsd_port)

loop do
# Listen for messages and track them on the messages Array.
Expand Down Expand Up @@ -116,7 +120,7 @@ def in_background(&block)
def run_plugin(stats_data, plugin, &block)
Puma._set_stats = stats_data
ENV["APPSIGNAL_STATSD_PORT"] = "8126"
@statsd = StatsdServer.new
@statsd = StatsdServer.new(ENV.fetch("APPSIGNAL_STATSD_PORT"))
@server_thread = Thread.new { @statsd.start }
@server_thread.abort_on_exception = true
@client_thread = Thread.new { start_plugin(plugin) }
Expand Down

0 comments on commit aea50d2

Please sign in to comment.