Skip to content

Commit

Permalink
handle the case of missing thread
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Oct 28, 2024
1 parent b8ae0cd commit 6fdad9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/datadog/di/probe_notifier_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ def start
def stop(timeout = 1)
@stop_requested = true
wake.signal
unless thread&.join(timeout)
thread.kill
if thread
unless thread.join(timeout)
thread.kill
end
@thread = nil
end
@thread = nil
end

# Waits for background thread to send pending notifications.
Expand Down
24 changes: 19 additions & 5 deletions spec/datadog/di/probe_notifier_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,27 @@
end

describe '#stop' do
before do
worker.start
context 'worker is running' do
before do
worker.start
end

it 'stops the thread' do
worker.stop
expect(worker.send(:thread)).to be nil
end
end

it 'stops the thread' do
worker.stop
expect(worker.send(:thread)).to be nil
context 'worker is not running' do
before do
expect(worker.send(:thread)).to be nil
end

it 'does nothing and raises no exceptions' do
expect do
worker.stop
end.not_to raise_error
end
end
end

Expand Down

0 comments on commit 6fdad9c

Please sign in to comment.