Skip to content

Commit

Permalink
Use different StatsD port during testing (#1070)
Browse files Browse the repository at this point in the history
Sometimes (especially on JRuby), the Puma plugin test fails. Use a
different port than the default, in the hopes it doesn't conflict with
the appsignal-agent process's StatsD server already using the port.

[skip changeset]
  • Loading branch information
tombruijn committed Apr 26, 2024
1 parent ccfa357 commit 9922140
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion spec/lib/puma/appsignal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class StatsdServer
def start
stop
@socket = UDPSocket.new
@socket.bind("127.0.0.1", 8125)
@socket.bind("127.0.0.1", ENV.fetch("APPSIGNAL_STATSD_PORT"))

loop do
# Listen for messages and track them on the messages Array.
Expand Down Expand Up @@ -115,13 +115,15 @@ def in_background(&block)

def run_plugin(stats_data, plugin, &block)
Puma._set_stats = stats_data
ENV["APPSIGNAL_STATSD_PORT"] = "8126"
@statsd = StatsdServer.new
@server_thread = Thread.new { @statsd.start }
@server_thread.abort_on_exception = true
@client_thread = Thread.new { start_plugin(plugin) }
@client_thread.abort_on_exception = true
wait_for(:puma_client_wait, &block)
ensure
ENV["APPSIGNAL_STATSD_PORT"] = nil
Puma._set_stats = nil
# Stop all threads in test and stop listening on the UDPSocket
@client_thread.kill if defined?(@client_thread) && @client_thread
Expand Down

0 comments on commit 9922140

Please sign in to comment.