Skip to content
Snippets Groups Projects
Commit 00c78fb8 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent d2ffc30f
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -6,6 +6,7 @@ module Gitlab
 
def initialize(repository)
@repository = repository
@cache_store = {}
end
 
def for(submodule, sha)
Loading
Loading
@@ -18,8 +19,9 @@ module Gitlab
attr_reader :repository
 
def submodule_urls_for(sha)
strong_memoize(:"submodule_urls_for_#{sha}") do
repository.submodule_urls_for(sha)
@cache_store.fetch(sha) do
submodule_urls = repository.submodule_urls_for(sha)
@cache_store[sha] = submodule_urls
end
end
 
Loading
Loading
Loading
Loading
@@ -19619,6 +19619,9 @@ msgstr ""
msgid "failed"
msgstr ""
 
msgid "failed to dismiss associated finding(id=%{finding_id}): %{message}"
msgstr ""
msgid "for %{link_to_merge_request} with %{link_to_merge_request_source_branch}"
msgstr ""
 
Loading
Loading
Loading
Loading
@@ -16,19 +16,22 @@ FactoryBot.define do
after(:build) do |repository, evaluator|
next if evaluator.tags.to_a.none?
 
tags = evaluator.tags
# convert Array into Hash
tags = tags.product(['sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15']).to_h unless tags.is_a?(Hash)
allow(repository.client)
.to receive(:repository_tags)
.and_return({
'name' => repository.path,
'tags' => evaluator.tags
'tags' => tags.keys
})
 
evaluator.tags.each do |tag|
tags.each_pair do |tag, digest|
allow(repository.client)
.to receive(:repository_tag_digest)
.with(repository.path, tag)
.and_return('sha256:4c8e63ca4cb663ce6c688cb06f1c3' \
'72b088dac5b6d7ad7d49cd620d85cf72a15')
.and_return(digest)
end
end
end
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
# For easier debugging set `PUMA_DEBUG=1`
describe Gitlab::Cluster::Mixins::PumaCluster do
PUMA_STARTUP_TIMEOUT = 30
context 'when running Puma in Cluster-mode' do
%i[USR1 USR2 INT HUP].each do |signal|
it "for #{signal} does execute phased restart block" do
with_puma(workers: 1) do |pid|
Process.kill(signal, pid)
child_pid, child_status = Process.wait2(pid)
expect(child_pid).to eq(pid)
expect(child_status).to be_exited
expect(child_status.exitstatus).to eq(140)
end
end
end
end
private
def with_puma(workers:, timeout: PUMA_STARTUP_TIMEOUT)
with_puma_config(workers: workers) do |puma_rb|
cmdline = [
"bundle", "exec", "puma",
"-C", puma_rb,
"-I", Rails.root.to_s
]
IO.popen(cmdline) do |process|
# wait for process to start:
# [2123] * Listening on tcp://127.0.0.1:0
wait_for_output(process, /Listening on/, timeout: timeout)
consume_output(process)
yield(process.pid)
ensure
Process.kill(:KILL, process.pid) unless process.eof?
end
end
end
def with_puma_config(workers:)
Dir.mktmpdir do |dir|
File.write "#{dir}/puma.rb", <<-EOF
require './lib/gitlab/cluster/lifecycle_events'
require './lib/gitlab/cluster/mixins/puma_cluster'
workers #{workers}
bind "tcp://127.0.0.1:0"
preload_app!
app -> (env) { [404, {}, ['']] }
Puma::Cluster.prepend(#{described_class})
Gitlab::Cluster::LifecycleEvents.on_before_phased_restart do
exit(140)
end
# redirect stderr to stdout
$stderr.reopen($stdout)
EOF
yield("#{dir}/puma.rb")
end
end
def wait_for_output(process, output, timeout:)
Timeout.timeout(timeout) do
loop do
line = process.readline
puts "PUMA_DEBUG: #{line}" if ENV['PUMA_DEBUG']
break if line =~ output
end
end
end
def consume_output(process)
Thread.new do
loop do
line = process.readline
puts "PUMA_DEBUG: #{line}" if ENV['PUMA_DEBUG']
end
rescue
end
end
end
# frozen_string_literal: true
require 'spec_helper'
# For easier debugging set `UNICORN_DEBUG=1`
describe Gitlab::Cluster::Mixins::UnicornHttpServer do
UNICORN_STARTUP_TIMEOUT = 10
context 'when running Unicorn' do
%i[USR2].each do |signal|
it "for #{signal} does execute phased restart block" do
with_unicorn(workers: 1) do |pid|
Process.kill(signal, pid)
child_pid, child_status = Process.wait2(pid)
expect(child_pid).to eq(pid)
expect(child_status).to be_exited
expect(child_status.exitstatus).to eq(140)
end
end
end
%i[QUIT TERM INT].each do |signal|
it "for #{signal} does not execute phased restart block" do
with_unicorn(workers: 1) do |pid|
Process.kill(signal, pid)
child_pid, child_status = Process.wait2(pid)
expect(child_pid).to eq(pid)
expect(child_status).to be_exited
expect(child_status.exitstatus).to eq(0)
end
end
end
end
private
def with_unicorn(workers:, timeout: UNICORN_STARTUP_TIMEOUT)
with_unicorn_configs(workers: workers) do |unicorn_rb, config_ru|
cmdline = [
"bundle", "exec", "unicorn",
"-I", Rails.root.to_s,
"-c", unicorn_rb,
config_ru
]
IO.popen(cmdline) do |process|
# wait for process to start:
# I, [2019-10-15T13:21:27.565225 #3089] INFO -- : master process ready
wait_for_output(process, /master process ready/, timeout: timeout)
consume_output(process)
yield(process.pid)
ensure
Process.kill(:KILL, process.pid) unless process.eof?
end
end
end
def with_unicorn_configs(workers:)
Dir.mktmpdir do |dir|
File.write "#{dir}/unicorn.rb", <<-EOF
require './lib/gitlab/cluster/lifecycle_events'
require './lib/gitlab/cluster/mixins/unicorn_http_server'
worker_processes #{workers}
listen "127.0.0.1:0"
preload_app true
Unicorn::HttpServer.prepend(#{described_class})
Gitlab::Cluster::LifecycleEvents.on_before_phased_restart do
exit(140)
end
# redirect stderr to stdout
$stderr.reopen($stdout)
EOF
File.write "#{dir}/config.ru", <<-EOF
run -> (env) { [404, {}, ['']] }
EOF
yield("#{dir}/unicorn.rb", "#{dir}/config.ru")
end
end
def wait_for_output(process, output, timeout:)
Timeout.timeout(timeout) do
loop do
line = process.readline
puts "UNICORN_DEBUG: #{line}" if ENV['UNICORN_DEBUG']
break if line =~ output
end
end
end
def consume_output(process)
Thread.new do
loop do
line = process.readline
puts "UNICORN_DEBUG: #{line}" if ENV['UNICORN_DEBUG']
end
rescue
end
end
end
Loading
Loading
@@ -19,15 +19,11 @@ describe Gitlab::Metrics::Exporter::BaseExporter do
BindAddress: anything,
Logger: anything,
AccessLog: anything
).and_wrap_original do |m, *args|
m.call(DoNotListen: true, Logger: args.first[:Logger])
end
allow_any_instance_of(::WEBrick::HTTPServer).to receive(:start)
).and_call_original
 
allow(settings).to receive(:enabled).and_return(true)
allow(settings).to receive(:port).and_return(8082)
allow(settings).to receive(:address).and_return('localhost')
allow(settings).to receive(:port).and_return(0)
allow(settings).to receive(:address).and_return('127.0.0.1')
end
 
after do
Loading
Loading
@@ -61,6 +57,8 @@ describe Gitlab::Metrics::Exporter::BaseExporter do
m.call(DoNotListen: true, Logger: args.first[:Logger])
end
 
allow_any_instance_of(::WEBrick::HTTPServer).to receive(:start)
exporter.start.join
end
end
Loading
Loading
@@ -89,14 +87,14 @@ describe Gitlab::Metrics::Exporter::BaseExporter do
 
describe 'when exporter is running' do
before do
exporter.start.join
exporter.start
end
 
describe '#start' do
it "doesn't start running server" do
expect_any_instance_of(::WEBrick::HTTPServer).not_to receive(:start)
 
expect { exporter.start.join }.not_to change { exporter.thread? }
expect { exporter.start }.not_to change { exporter.thread? }
end
end
 
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Metrics::Exporter::WebExporter do
let(:exporter) { described_class.new }
context 'when blackout seconds is used' do
let(:blackout_seconds) { 0 }
let(:readiness_probe) { exporter.send(:readiness_probe).execute }
before do
stub_config(
monitoring: {
web_exporter: {
enabled: true,
port: 0,
address: '127.0.0.1',
blackout_seconds: blackout_seconds
}
}
)
exporter.start
end
after do
exporter.stop
end
context 'when running server' do
it 'readiness probe returns succesful status' do
expect(readiness_probe.http_status).to eq(200)
expect(readiness_probe.json).to include(status: 'ok')
expect(readiness_probe.json).to include('web_exporter' => [{ 'status': 'ok' }])
end
end
context 'when blackout seconds is 10s' do
let(:blackout_seconds) { 10 }
it 'readiness probe returns a failure status' do
# during sleep we check the status of readiness probe
expect(exporter).to receive(:sleep).with(10) do
expect(readiness_probe.http_status).to eq(503)
expect(readiness_probe.json).to include(status: 'failed')
expect(readiness_probe.json).to include('web_exporter' => [{ 'status': 'failed' }])
end
exporter.stop
end
end
context 'when blackout is disabled' do
let(:blackout_seconds) { 0 }
it 'readiness probe returns a failure status' do
expect(exporter).not_to receive(:sleep)
exporter.stop
end
end
end
end
Loading
Loading
@@ -8,7 +8,9 @@ describe Gitlab::SubmoduleLinks do
let(:links) { described_class.new(repo) }
 
describe '#for' do
subject { links.for(submodule_item, 'ref') }
let(:ref) { 'ref' }
subject { links.for(submodule_item, ref) }
 
context 'when there is no .gitmodules file' do
before do
Loading
Loading
@@ -35,8 +37,20 @@ describe Gitlab::SubmoduleLinks do
stub_urls({ 'gitlab-foss' => 'git@gitlab.com:gitlab-org/gitlab-foss.git' })
end
 
it 'returns links' do
it 'returns links and caches the by ref' do
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/tree/hash'])
cache_store = links.instance_variable_get("@cache_store")
expect(cache_store[ref]).to eq({ "gitlab-foss" => "git@gitlab.com:gitlab-org/gitlab-foss.git" })
end
context 'when ref name contains a dash' do
let(:ref) { 'signed-commits' }
it 'returns links' do
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/tree/hash'])
end
end
end
end
Loading
Loading
Loading
Loading
@@ -320,6 +320,22 @@ describe Blob do
expect(blob.rich_viewer).to be_a(BlobViewer::Markup)
end
end
context 'when the blob is video' do
it 'returns a video viewer' do
blob = fake_blob(path: 'file.mp4', binary: true)
expect(blob.rich_viewer).to be_a(BlobViewer::Video)
end
end
context 'when the blob is audio' do
it 'returns an audio viewer' do
blob = fake_blob(path: 'file.wav', binary: true)
expect(blob.rich_viewer).to be_a(BlobViewer::Audio)
end
end
end
 
describe '#auxiliary_viewer' do
Loading
Loading
Loading
Loading
@@ -78,7 +78,7 @@ describe ContainerRepository do
describe '#delete_tags!' do
let(:repository) do
create(:container_repository, name: 'my_image',
tags: %w[latest rc1],
tags: { latest: '123', rc1: '234' },
project: project)
end
 
Loading
Loading
@@ -86,6 +86,7 @@ describe ContainerRepository do
it 'returns status that indicates success' do
expect(repository.client)
.to receive(:delete_repository_tag)
.twice
.and_return(true)
 
expect(repository.delete_tags!).to be_truthy
Loading
Loading
@@ -96,6 +97,7 @@ describe ContainerRepository do
it 'returns status that indicates failure' do
expect(repository.client)
.to receive(:delete_repository_tag)
.twice
.and_return(false)
 
expect(repository.delete_tags!).to be_falsey
Loading
Loading
Loading
Loading
@@ -981,4 +981,55 @@ describe Note do
expect(note.parent).to be_nil
end
end
describe 'scopes' do
let_it_be(:note1) { create(:note, note: 'Test 345') }
let_it_be(:note2) { create(:note, note: 'Test 789') }
describe '#for_note_or_capitalized_note' do
it 'returns the expected matching note' do
notes = described_class.for_note_or_capitalized_note('Test 345')
expect(notes.count).to eq(1)
expect(notes.first.id).to eq(note1.id)
end
it 'returns the expected capitalized note' do
notes = described_class.for_note_or_capitalized_note('test 345')
expect(notes.count).to eq(1)
expect(notes.first.id).to eq(note1.id)
end
it 'does not support pattern matching' do
notes = described_class.for_note_or_capitalized_note('test%')
expect(notes.count).to eq(0)
end
end
describe '#like_note_or_capitalized_note' do
it 'returns the expected matching note' do
notes = described_class.like_note_or_capitalized_note('Test 345')
expect(notes.count).to eq(1)
expect(notes.first.id).to eq(note1.id)
end
it 'returns the expected capitalized note' do
notes = described_class.like_note_or_capitalized_note('test 345')
expect(notes.count).to eq(1)
expect(notes.first.id).to eq(note1.id)
end
it 'supports pattern matching' do
notes = described_class.like_note_or_capitalized_note('test%')
expect(notes.count).to eq(2)
expect(notes.first.id).to eq(note1.id)
expect(notes.second.id).to eq(note2.id)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment