Skip to content

Commit

Permalink
Attempt to remove flaky test for checking that tracer threads are cor…
Browse files Browse the repository at this point in the history
…rectly shutdown (#3228)

Attempt to fix flaky test for checking that tracer threads are
correctly shutdown by adding back call to 
Timeout.ensure_timeout_thread_created that was removed in #2991
  • Loading branch information
ekump authored Oct 30, 2023
1 parent b84ca45 commit 4d22403
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spec/datadog/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def inspect_threads(threads)

shutdown

expect(threads.size).to eq(original_threads.size),
"Expected #{original_threads.size} threads (#{original_threads_inspect}), "\
"got #{threads.size} threads (#{inspect_threads(threads)})"
post_shutdown_new_threads = Thread.list - original_threads

expect(post_shutdown_new_threads).to be_empty,
"Expected #{original_threads.size} threads but got #{threads.size} threads. "\
"extra_threads: (#{inspect_threads(post_shutdown_new_threads)})"
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,11 @@ def initialize(*args, &block)

# Helper matchers
RSpec::Matchers.define_negated_matcher :not_be, :be

# The Ruby Timeout class uses a long-lived class-level thread that is never terminated.
# Creating it early here ensures tests that tests that check for leaking threads are not
# triggered by the creation of this thread.
#
# This has to be one once for the lifetime of this process, and was introduced in Ruby 3.1.
# Before 3.1, a thread was created and destroyed on every Timeout#timeout call.
Timeout.ensure_timeout_thread_created if Timeout.respond_to?(:ensure_timeout_thread_created)

0 comments on commit 4d22403

Please sign in to comment.