debian-mirror-gitlab/spec/lib/gitlab/checks/timed_logger_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Checks::TimedLogger do
2018-12-13 13:39:08 +05:30
let!(:timeout) { 50.seconds }
let!(:start) { Time.now }
let!(:ref) { "bar" }
let!(:logger) { described_class.new(start_time: start, timeout: timeout) }
let!(:log_messages) do
{
foo: "Foo message..."
}
end
before do
logger.append_message("Checking ref: #{ref}")
end
2023-03-04 22:38:38 +05:30
around do |example|
freeze_time do
example.run
end
end
2018-12-13 13:39:08 +05:30
describe '#log_timed' do
it 'logs message' do
2023-03-04 22:38:38 +05:30
travel_to(start + 30.seconds)
logger.log_timed(log_messages[:foo], start) { bar_check }
2018-12-13 13:39:08 +05:30
expect(logger.full_message).to eq("Checking ref: bar\nFoo message... (30000.0ms)")
end
context 'when time limit was reached' do
it 'cancels action' do
2023-03-04 22:38:38 +05:30
travel_to(start + 50.seconds)
expect do
logger.log_timed(log_messages[:foo], start) do
bar_check
end
end.to raise_error(described_class::TimeoutError)
2018-12-13 13:39:08 +05:30
expect(logger.full_message).to eq("Checking ref: bar\nFoo message... (cancelled)")
end
it 'cancels action with time elapsed if work was performed' do
2023-03-04 22:38:38 +05:30
travel_to(start + 30.seconds)
expect do
logger.log_timed(log_messages[:foo], start) do
grpc_check
end
end.to raise_error(described_class::TimeoutError)
expect(logger.full_message).to eq("Checking ref: bar\nFoo message... (cancelled after 30000.0ms)")
2018-12-13 13:39:08 +05:30
end
end
end
def bar_check
2 + 2
end
def grpc_check
raise GRPC::DeadlineExceeded
end
end