Skip to content

Commit

Permalink
Stop minutely probes thread on Appsignal.stop
Browse files Browse the repository at this point in the history
Make sure the minutely probes thread is stopped when calling
`Appsignal.stop`. This makes sure nothing of the AppSignal gem is
running after you call stop.

This only affects apps that call stop manually (like in test suites),
because the thread is also stopped when the Ruby process stops.

Closes #815
  • Loading branch information
tombruijn committed Apr 26, 2024
1 parent 126132c commit 5f97aa2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changesets/stop-minutely-probes-on-appsignal-stop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "change"
---

Stop the minutely probes when `Appsignal.stop` is called. When `Appsignal.stop` is called, the probes thread will no longer continue running in the app process.
1 change: 1 addition & 0 deletions lib/appsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def stop(called_by = nil)
internal_logger.debug("Stopping appsignal")
end
Appsignal::Extension.stop
Appsignal::Probes.stop
end

def forked
Expand Down
3 changes: 2 additions & 1 deletion lib/appsignal/probes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def started?
@started
end

# @api private
# Stop the minutely probes mechanism. Stop the thread and clear all probe
# instances.
def stop
defined?(@thread) && @thread.kill
@started = false
Expand Down
9 changes: 8 additions & 1 deletion spec/lib/appsignal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,20 @@
end

describe ".stop" do
it "should call stop on the extension" do
it "calls stop on the extension" do
expect(Appsignal.internal_logger).to receive(:debug).with("Stopping appsignal")
expect(Appsignal::Extension).to receive(:stop)
Appsignal.stop
expect(Appsignal.active?).to be_falsy
end

it "stops the minutely probes" do
Appsignal::Probes.start
expect(Appsignal::Probes.started?).to be_truthy
Appsignal.stop
expect(Appsignal::Probes.started?).to be_falsy
end

context "with context specified" do
it "should log the context" do
expect(Appsignal.internal_logger).to receive(:debug).with("Stopping appsignal (something)")
Expand Down

0 comments on commit 5f97aa2

Please sign in to comment.