Merge remote-tracking branch 'parent/main' into upstream-20230105
This commit is contained in:
commit
a0a3d1b101
65 changed files with 1008 additions and 453 deletions
|
@ -20,4 +20,157 @@ describe Mastodon::CLI::Main do
|
|||
.to output_results(Mastodon::Version.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#self_destruct' do
|
||||
let(:action) { :self_destruct }
|
||||
|
||||
context 'with self destruct mode enabled' do
|
||||
before do
|
||||
allow(SelfDestructHelper).to receive(:self_destruct?).and_return(true)
|
||||
end
|
||||
|
||||
context 'with pending accounts' do
|
||||
before { Fabricate(:account) }
|
||||
|
||||
it 'reports about pending accounts' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'already enabled',
|
||||
'still pending deletion'
|
||||
)
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with sidekiq notices being processed' do
|
||||
before do
|
||||
Account.delete_all
|
||||
stats_double = instance_double(Sidekiq::Stats, enqueued: 5)
|
||||
allow(Sidekiq::Stats).to receive(:new).and_return(stats_double)
|
||||
end
|
||||
|
||||
it 'reports about notices' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'already enabled',
|
||||
'notices are still being'
|
||||
)
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with sidekiq failed deliveries' do
|
||||
before do
|
||||
Account.delete_all
|
||||
stats_double = instance_double(Sidekiq::Stats, enqueued: 0, retry_size: 10)
|
||||
allow(Sidekiq::Stats).to receive(:new).and_return(stats_double)
|
||||
end
|
||||
|
||||
it 'reports about notices' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'already enabled',
|
||||
'some have failed and are scheduled'
|
||||
)
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with self descruct mode ready' do
|
||||
before do
|
||||
Account.delete_all
|
||||
stats_double = instance_double(Sidekiq::Stats, enqueued: 0, retry_size: 0)
|
||||
allow(Sidekiq::Stats).to receive(:new).and_return(stats_double)
|
||||
end
|
||||
|
||||
it 'reports about notices' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'already enabled',
|
||||
'can safely delete all data'
|
||||
)
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with self destruct mode disabled' do
|
||||
before do
|
||||
allow(SelfDestructHelper).to receive(:self_destruct?).and_return(false)
|
||||
end
|
||||
|
||||
context 'with an incorrect response to hostname' do
|
||||
before do
|
||||
answer_hostname_incorrectly
|
||||
end
|
||||
|
||||
it 'exits silently' do
|
||||
expect { subject }
|
||||
.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a correct response to hostname but no to proceed' do
|
||||
before do
|
||||
answer_hostname_correctly
|
||||
decline_proceed
|
||||
end
|
||||
|
||||
it 'passes first step but stops before instructions' do
|
||||
expect { subject }
|
||||
.to output_results('operation WILL NOT')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a correct response to hostname and yes to proceed' do
|
||||
before do
|
||||
answer_hostname_correctly
|
||||
accept_proceed
|
||||
end
|
||||
|
||||
it 'instructs to set the appropriate environment variable' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
'operation WILL NOT',
|
||||
'the following variable'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def answer_hostname_incorrectly
|
||||
allow(cli.shell)
|
||||
.to receive(:ask)
|
||||
.with('Type in the domain of the server to confirm:')
|
||||
.and_return('wrong.host')
|
||||
.once
|
||||
end
|
||||
|
||||
def answer_hostname_correctly
|
||||
allow(cli.shell)
|
||||
.to receive(:ask)
|
||||
.with('Type in the domain of the server to confirm:')
|
||||
.and_return(Rails.configuration.x.local_domain)
|
||||
.once
|
||||
end
|
||||
|
||||
def decline_proceed
|
||||
allow(cli.shell)
|
||||
.to receive(:no?)
|
||||
.with('Are you sure you want to proceed?')
|
||||
.and_return(true)
|
||||
.once
|
||||
end
|
||||
|
||||
def accept_proceed
|
||||
allow(cli.shell)
|
||||
.to receive(:no?)
|
||||
.with('Are you sure you want to proceed?')
|
||||
.and_return(false)
|
||||
.once
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -184,4 +184,58 @@ describe Mastodon::CLI::Media do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remove_orphans' do
|
||||
let(:action) { :remove_orphans }
|
||||
|
||||
before do
|
||||
FileUtils.mkdir_p Rails.public_path.join('system')
|
||||
end
|
||||
|
||||
context 'without any options' do
|
||||
it 'runs without error' do
|
||||
expect { subject }
|
||||
.to output_results('Removed', 'orphans (approx')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when in azure mode' do
|
||||
before do
|
||||
allow(Paperclip::Attachment).to receive(:default_options).and_return(storage: :azure)
|
||||
end
|
||||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('azure storage driver is not supported')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when in fog mode' do
|
||||
before do
|
||||
allow(Paperclip::Attachment).to receive(:default_options).and_return(storage: :fog)
|
||||
end
|
||||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('fog storage driver is not supported')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when in filesystem mode' do
|
||||
before do
|
||||
allow(File).to receive(:delete).and_return(true)
|
||||
media_attachment.delete
|
||||
end
|
||||
|
||||
let(:media_attachment) { Fabricate(:media_attachment) }
|
||||
|
||||
it 'removes the unlinked files' do
|
||||
expect { subject }
|
||||
.to output_results('Removed', 'orphans (approx')
|
||||
expect(File).to have_received(:delete).with(media_attachment.file.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,11 +33,13 @@ describe RequestPool do
|
|||
|
||||
subject
|
||||
|
||||
threads = Array.new(20) do |_i|
|
||||
threads = Array.new(3) do
|
||||
Thread.new do
|
||||
20.times do
|
||||
2.times do
|
||||
subject.with('http://example.com') do |http_client|
|
||||
http_client.get('/').flush
|
||||
# Nudge scheduler to yield and exercise the full pool
|
||||
sleep(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue