ubicloud/spec/lib/thread_printer_spec.rb
Daniel Farina d61aa8a15c Move Thread dump code ThreadPrinter module
Printing thread stack traces is useful when diagnosing issues with
slow or non-termination, and we might have one of those issues on the
web site.  So, refactor the thread dumping code for reuse.
2023-09-04 13:01:21 -07:00

20 lines
707 B
Ruby

# frozen_string_literal: true
RSpec.describe ThreadPrinter do
describe "#print" do
it "can dump threads" do
expect(described_class).to receive(:puts).with(/Thread: #<Thread:.*>/)
expect(described_class).to receive(:puts).with(/backtrace/)
described_class.run
end
it "can handle threads with a nil backtrace" do
# The documentation calls out that the backtrace is an array or
# nil.
expect(described_class).to receive(:puts).with(/Thread: #<InstanceDouble.*>/)
expect(described_class).to receive(:puts).with(nil)
expect(Thread).to receive(:list).and_return([instance_double(Thread, backtrace: nil)])
described_class.run
end
end
end