summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-10-25 10:36:40 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-10-25 10:52:03 +0100
commite0225aea1beb741601b888d4f505abd97f0f67a6 (patch)
tree818562012bb78cdbd73413b01558adef1bdfcc09 /spec/lib/gitlab
parentcb5f4d0cad520629aecaa838ddf1e84d7265ff49 (diff)
downloadgitlab-ce-e0225aea1beb741601b888d4f505abd97f0f67a6.tar.gz
Iterating through commit list times out
Validating each commit on ChangeAccess times out if it already took too long to complete. Improves the TimedLogger specs to not make use of a stubbed class anymore
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/checks/timed_logger_spec.rb58
1 files changed, 23 insertions, 35 deletions
diff --git a/spec/lib/gitlab/checks/timed_logger_spec.rb b/spec/lib/gitlab/checks/timed_logger_spec.rb
index 726f2bf2144..0ed3940c038 100644
--- a/spec/lib/gitlab/checks/timed_logger_spec.rb
+++ b/spec/lib/gitlab/checks/timed_logger_spec.rb
@@ -3,73 +3,61 @@
require 'spec_helper'
describe Gitlab::Checks::TimedLogger do
- let(:log_messages) do
+ 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
- class FooCheck
- attr_accessor :logger
-
- INTERNAL_TIMEOUT = 50.seconds.freeze
-
- def initialize(start_time, ref)
- @logger = Gitlab::Checks::TimedLogger.new(start_time: start_time, timeout: INTERNAL_TIMEOUT)
- @logger.log << "Checking ref: #{ref}"
- end
-
- def bar_check
- 2 + 2
- end
-
- def grpc_check
- raise GRPC::DeadlineExceeded
- end
+ before do
+ logger.append_message("Checking ref: #{ref}")
end
describe '#log_timed' do
it 'logs message' do
- start = Time.now
- check = FooCheck.new(start, "bar")
-
Timecop.freeze(start + 30.seconds) do
- check.logger.log_timed(log_messages[:foo], start) { check.bar_check }
+ logger.log_timed(log_messages[:foo], start) { bar_check }
end
- expect(check.logger.log).to eq(["Checking ref: bar", "Foo message... (30000.0ms)"])
+ 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
- start = Time.now
- check = FooCheck.new(start, "bar")
-
Timecop.freeze(start + 50.seconds) do
expect do
- check.logger.log_timed(log_messages[:foo], start) do
- check.bar_check
+ logger.log_timed(log_messages[:foo], start) do
+ bar_check
end
end.to raise_error(described_class::TimeoutError)
end
- expect(check.logger.log).to eq(["Checking ref: bar", "Foo message... (cancelled)"])
+ expect(logger.full_message).to eq("Checking ref: bar\nFoo message... (cancelled)")
end
it 'cancels action with time elapsed if work was performed' do
- start = Time.now
- check = FooCheck.new(start, "bar")
-
Timecop.freeze(start + 30.seconds) do
expect do
- check.logger.log_timed(log_messages[:foo], start) do
- check.grpc_check
+ logger.log_timed(log_messages[:foo], start) do
+ grpc_check
end
end.to raise_error(described_class::TimeoutError)
- expect(check.logger.log).to eq(["Checking ref: bar", "Foo message... (cancelled after 30000.0ms)"])
+ expect(logger.full_message).to eq("Checking ref: bar\nFoo message... (cancelled after 30000.0ms)")
end
end
end
end
+
+ def bar_check
+ 2 + 2
+ end
+
+ def grpc_check
+ raise GRPC::DeadlineExceeded
+ end
end