Commit 5324791f authored by DJ Mountney's avatar DJ Mountney
Browse files

Merge branch 'rs-disable-progress-bar' into '7.0.10-stable'

Add configuration to globally disable fetcher progress bar

See merge request gitlab-org/omnibus!22
parents 1e8b748f 1c26e0e4
......@@ -617,6 +617,11 @@ module Omnibus
# @return [Integer]
default(:fetcher_retries, 5)
# Enable or disable the fetcher progress bar globally.
#
# @return [true, false]
default(:fetcher_progress_bar, true)
# --------------------------------------------------
# @!endgroup
#
......
......@@ -49,17 +49,20 @@ module Omnibus
def download_file!(from_url, to_path, download_options = {})
options = download_options.dup
# :enable_progress_bar is a special option we handle.
# by default we enable the progress bar.
enable_progress_bar = options.delete(:enable_progress_bar)
enable_progress_bar = true if enable_progress_bar.nil?
options.merge!(download_headers)
options[:read_timeout] = Omnibus::Config.fetcher_read_timeout
fetcher_retries ||= Omnibus::Config.fetcher_retries
reported_total = 0
# Allow disabling the progress bar at calltime, or globally via config
#
# Defaults to true in both cases and will only be disabled if either is
# explicitly false.
options[:enable_progress_bar] = true unless options.key?(:enable_progress_bar)
enable_progress_bar = options.delete(:enable_progress_bar) && Omnibus::Config.fetcher_progress_bar
if enable_progress_bar
progress_bar = ProgressBar.create(
output: $stdout,
......
......@@ -44,6 +44,7 @@ module Omnibus
include_examples "a configurable", :use_git_caching, true
include_examples "a configurable", :fetcher_read_timeout, 60
include_examples "a configurable", :fetcher_retries, 5
include_examples "a configurable", :fetcher_progress_bar, true
include_examples "a configurable", :fatal_licensing_warnings, false
include_examples "a configurable", :fips_mode, false
......
......@@ -258,17 +258,24 @@ module Omnibus
describe "downloading the file" do
let(:expected_open_opts) do
{
a_hash_including(
"Accept-Encoding" => "identity",
:read_timeout => 60,
:content_length_proc => an_instance_of(Proc),
:progress_proc => an_instance_of(Proc),
}
:read_timeout => 60
)
end
let(:tempfile_path) { "/tmp/intermediate_path/tempfile_path.random_garbage.tmp" }
let(:fetched_file) { instance_double("TempFile", path: tempfile_path) }
let(:fetched_file) do
instance_double(
"TempFile",
path: tempfile_path,
content_type: 'text/plain',
metas: nil,
status: 200,
base_uri: 'example.com'
)
end
let(:destination_path) { "/cache/file.tar.gz" }
......@@ -286,10 +293,7 @@ module Omnibus
end
before do
expect(subject).to receive(:open).with(source[:url], expected_open_opts) do |_url, open_uri_opts|
open_uri_opts[:content_length_proc].call(reported_content_length)
open_uri_opts[:progress_proc].call(cumulative_downloaded_length)
expect(subject).to receive(:open).with(source[:url], expected_open_opts) do |_url, _open_uri_opts|
fetched_file
end
expect(fetched_file).to receive(:close)
......@@ -303,6 +307,16 @@ module Omnibus
end
end
it "disables the progress bar globally" do
Config.fetcher_progress_bar(false)
expect(ProgressBar).not_to receive(:create)
capturing_stdout do
subject.send(:download)
end
end
# In Ci we somewhat frequently see:
# ProgressBar::InvalidProgressError: You can't set the item's current value to be greater than the total.
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment