context'when the class does not override lease_taken_log_level'do
it'does not call internal_method but logs error',:aggregate_failuresdo
expect(subject).not_toreceive(:internal_method)
expect(Gitlab::AppJsonLogger).toreceive(:error).with({message:"Cannot obtain an exclusive lease. There must be another instance already in execution.",lease_key:'exclusive_lease_guard_test_class',class_name:'ExclusiveLeaseGuardTestClass',lease_timeout:1.second})
context'when the class overrides lease_taken_log_level to return :info'do
subject:overwritten_subject_classdo
Class.new(subject_class)do
deflease_taken_log_level
:info
end
end
end
let(:subject){overwritten_subject_class.new}
it'logs info',:aggregate_failuresdo
expect(Gitlab::AppJsonLogger).toreceive(:info).with({message:"Cannot obtain an exclusive lease. There must be another instance already in execution.",lease_key:'exclusive_lease_guard_test_class',class_name:'ExclusiveLeaseGuardTestClass',lease_timeout:1.second})
subject.call
end
end
context'when the class overrides lease_taken_log_level to return :debug'do
subject:overwritten_subject_classdo
Class.new(subject_class)do
deflease_taken_log_level
:debug
end
end
end
let(:subject){overwritten_subject_class.new}
it'logs debug',:aggregate_failuresdo
expect(Gitlab::AppJsonLogger).toreceive(:debug).with({message:"Cannot obtain an exclusive lease. There must be another instance already in execution.",lease_key:'exclusive_lease_guard_test_class',class_name:'ExclusiveLeaseGuardTestClass',lease_timeout:1.second})