DEV: Add rspec tests for `SignalTrapLogger` (#27302)

Follow-up to 23c38cbf11
This commit is contained in:
Alan Guo Xiang Tan 2024-06-03 13:40:21 +08:00 committed by GitHub
parent d68983e060
commit aec892339e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
RSpec.describe SignalTrapLogger do
describe "#log" do
it "should queue up messages to be logged which will then be logged by the logging thread" do
fake_logger = FakeLogger.new
SignalTrapLogger.instance.log(fake_logger, "message 1", level: :error)
# Ensures that thread doesn't die even if an error is encountered
SignalTrapLogger.instance.log(fake_logger, "error", level: :abcdes)
SignalTrapLogger.instance.log(fake_logger, "message 2", level: :info)
wait_for { fake_logger.errors.size == 1 && fake_logger.infos.size == 1 }
expect(fake_logger.errors).to eq(["message 1"])
expect(fake_logger.infos).to eq(["message 2"])
end
end
end