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.
20 lines
707 B
Ruby
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
|