Skip to content

Commit

Permalink
+tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Feb 9, 2024
1 parent fc577a7 commit 49270b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/lokalise_manager/task_definitions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ def project_id_with_branch
"#{config.project_id}:#{config.branch}"
end

EXCEPTIONS = [JSON::ParserError, RubyLokaliseApi::Error::TooManyRequests]

# In rare cases the server might return HTML instead of JSON.
# It happens when too many requests are being sent.
# Until this is fixed, we revert to this quick'n'dirty solution.
EXCEPTIONS = [JSON::ParserError, RubyLokaliseApi::Error::TooManyRequests].freeze

# Sends request with exponential backoff mechanism
def with_exp_backoff(max_retries)
return unless block_given?
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/lokalise_manager/task_definitions/exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@
expect(described_object).to have_received(:api_client).at_least(14).times
expect(fake_client).to have_received(:upload_file).exactly(14).times
end

it 'handles non-json responses but does not re-raise anything when raise_on_export_fail is false' do
allow(described_object.config).to receive_messages(max_retries_export: 1, raise_on_export_fail: false)

fake_client = instance_double(RubyLokaliseApi::Client)
allow(fake_client).to receive(:token).with(any_args).and_return('fake_token')
allow(fake_client).to receive(:upload_file).with(any_args).and_raise(JSON::ParserError)
allow(described_object).to receive_messages(sleep: 0, api_client: fake_client)
processes = []
expect { processes = described_object.export! }.not_to raise_error

expect(processes[0].success).to be false
expect(processes[1].error.class).to eq(JSON::ParserError)
expect(processes.count).to eq(7)

expect(described_object).to have_received(:sleep).exactly(7).times
expect(described_object).to have_received(:api_client).at_least(14).times
expect(fake_client).to have_received(:upload_file).exactly(14).times
end
end

context 'with errors' do
Expand Down

0 comments on commit 49270b2

Please sign in to comment.