Skip to content

Commit f3fa2f1

Browse files
authored
Crash with a useful error message when polling times out (#327)
1 parent b0fd460 commit f3fa2f1

File tree

2 files changed

+150
-119
lines changed

2 files changed

+150
-119
lines changed

lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_action.rb

+5
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ def self.poll_upload_release_operation(client, operation, binary_type)
232232
end
233233
end
234234
end
235+
236+
unless operation.done && operation.response && operation.response['release']
237+
UI.crash!("It took longer than expected to process your #{binary_type}, please try again.")
238+
end
239+
235240
extract_release(operation)
236241
end
237242

spec/firebase_app_distribution_action_spec.rb

+145-119
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
end
237237

238238
describe 'with android app' do
239-
describe 'when uploading an AAB' do
239+
describe 'with AAB' do
240240
let(:params) do
241241
{
242242
app: android_app_id,
@@ -304,158 +304,184 @@ def stub_get_aab_info(integration_state = 'INTEGRATED')
304304
end
305305
end
306306

307-
describe 'when successfully uploading' do
307+
describe 'with a successful upload' do
308308
let(:fake_binary_contents) { "Hello World" }
309309
let(:fake_binary) { double("Binary") }
310-
let(:release) { { name: "release-name", displayVersion: 'display-version' } }
311310

312311
before do
313312
allow(File).to receive(:exist?).and_return(true)
314313
allow(File).to receive(:open)
315314
.and_return(fake_binary)
316315
allow(fake_binary).to receive(:read)
317316
.and_return(fake_binary_contents)
317+
end
318+
319+
it 'crashes if it exceeds polling threshold' do
320+
stub_const('Fastlane::Actions::FirebaseAppDistributionAction::MAX_POLLING_RETRIES', 0)
318321
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
319322
.to receive(:http)
320-
.and_return({ name: 'operation-name', result: release }.to_json)
323+
.and_return({ name: 'operation-name' }.to_json)
321324
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
322325
.to receive(:get_project_app_release_operation)
326+
.with('operation-name')
323327
.and_return(Google::Apis::FirebaseappdistributionV1::GoogleLongrunningOperation.new(
324-
done: true,
325-
response: {
326-
'release' => release
327-
}
328+
done: false
328329
))
329-
end
330-
331-
it 'returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
332-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService).to_not(receive(:distribute_project_app_release))
333-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService).to_not(receive(:patch_project_app_release))
334330

335-
action.run({
336-
app: android_app_id,
337-
android_artifact_path: 'path/to.apk'
338-
})
339-
340-
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
331+
expect do
332+
action.run({
333+
app: android_app_id,
334+
android_artifact_path: 'path/to.apk'
335+
})
336+
end.to raise_error(FastlaneCore::Interface::FastlaneCrash)
341337
end
342338

343-
describe 'when distributing to testers' do
344-
it 'raises error if request returns a 400' do
345-
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
346-
.to receive(:distribute_project_app_release)
347-
.and_raise(Google::Apis::Error.new({}, status_code: '400'))
348-
349-
expect do
350-
action.run({
351-
app: android_app_id,
352-
android_artifact_path: 'path/to.apk',
353-
groups: "test-group-1, test-group-2",
354-
355-
})
356-
end.to raise_error("#{ErrorMessage::INVALID_TESTERS}\nEmails: [\"[email protected]\", \"[email protected]\"] \nGroup Aliases: [\"test-group-1\", \"test-group-2\"]")
357-
end
339+
describe 'when binary is processed' do
340+
let(:release) { { name: "release-name", displayVersion: 'display-version' } }
358341

359-
it 'distributes to testers, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
342+
before do
360343
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
361-
.to receive(:distribute_project_app_release)
362-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
363-
.to receive(:distribute_project_app_release) do |_, release_name, request|
364-
expect(request.tester_emails).to eq(%w[[email protected] [email protected]])
365-
# Response will fail if tester_emails or group_aliases field is nil
366-
# it sets absent values to empty arrays
367-
expect(request.group_aliases).to eq([])
368-
end
369-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
370-
.to_not(receive(:patch_project_app_release))
371-
372-
returned_release = action.run({
373-
app: android_app_id,
374-
android_artifact_path: 'path/to.apk',
375-
376-
})
377-
378-
expect(returned_release).to eq(release)
379-
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
344+
.to receive(:http)
345+
.and_return({ name: 'operation-name', result: release }.to_json)
346+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
347+
.to receive(:get_project_app_release_operation)
348+
.and_return(Google::Apis::FirebaseappdistributionV1::GoogleLongrunningOperation.new(
349+
done: true,
350+
response: {
351+
'release' => release
352+
}
353+
))
380354
end
381355

382-
it 'distributes to groups, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
383-
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
384-
.to receive(:distribute_project_app_release)
385-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
386-
.to receive(:distribute_project_app_release) do |_, release_name, request|
387-
expect(request.group_aliases).to eq(%w[test-group-1 test-group-2])
388-
# Response will fail if tester_emails or group_aliases field is nil
389-
# it sets absent values to empty arrays
390-
expect(request.tester_emails).to eq([])
391-
end
392-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
393-
.to_not(receive(:patch_project_app_release))
356+
it 'returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
357+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService).to_not(receive(:distribute_project_app_release))
358+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService).to_not(receive(:patch_project_app_release))
394359

395-
returned_release = action.run({
396-
app: android_app_id,
397-
android_artifact_path: 'path/to.apk',
398-
groups: "test-group-1, test-group-2"
399-
})
360+
action.run({
361+
app: android_app_id,
362+
android_artifact_path: 'path/to.apk'
363+
})
400364

401-
expect(returned_release).to eq(release)
402365
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
403366
end
404367

405-
it 'distributes to groups and testers, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
406-
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
407-
.to receive(:distribute_project_app_release)
408-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
409-
.to receive(:distribute_project_app_release) do |_, release_name, request|
410-
expect(request.group_aliases).to eq(%w[test-group-1 test-group-2])
411-
expect(request.tester_emails).to eq(%w[[email protected] [email protected]])
368+
describe 'when distributing to testers' do
369+
it 'raises error if request returns a 400' do
370+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
371+
.to receive(:distribute_project_app_release)
372+
.and_raise(Google::Apis::Error.new({}, status_code: '400'))
373+
374+
expect do
375+
action.run({
376+
app: android_app_id,
377+
android_artifact_path: 'path/to.apk',
378+
groups: "test-group-1, test-group-2",
379+
380+
})
381+
end.to raise_error("#{ErrorMessage::INVALID_TESTERS}\nEmails: [\"[email protected]\", \"[email protected]\"] \nGroup Aliases: [\"test-group-1\", \"test-group-2\"]")
412382
end
413-
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
414-
.to_not(receive(:patch_project_app_release))
415383

416-
returned_release = action.run({
417-
app: android_app_id,
418-
android_artifact_path: 'path/to.apk',
419-
groups: "test-group-1, test-group-2",
420-
421-
})
384+
it 'distributes to testers, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
385+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
386+
.to receive(:distribute_project_app_release)
387+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
388+
.to receive(:distribute_project_app_release) do |_, release_name, request|
389+
expect(request.tester_emails).to eq(%w[[email protected] [email protected]])
390+
# Response will fail if tester_emails or group_aliases field is nil
391+
# it sets absent values to empty arrays
392+
expect(request.group_aliases).to eq([])
393+
end
394+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
395+
.to_not(receive(:patch_project_app_release))
396+
397+
returned_release = action.run({
398+
app: android_app_id,
399+
android_artifact_path: 'path/to.apk',
400+
401+
})
402+
403+
expect(returned_release).to eq(release)
404+
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
405+
end
422406

423-
expect(returned_release).to eq(release)
424-
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
425-
end
426-
end
407+
it 'distributes to groups, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
408+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
409+
.to receive(:distribute_project_app_release)
410+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
411+
.to receive(:distribute_project_app_release) do |_, release_name, request|
412+
expect(request.group_aliases).to eq(%w[test-group-1 test-group-2])
413+
# Response will fail if tester_emails or group_aliases field is nil
414+
# it sets absent values to empty arrays
415+
expect(request.tester_emails).to eq([])
416+
end
417+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
418+
.to_not(receive(:patch_project_app_release))
419+
420+
returned_release = action.run({
421+
app: android_app_id,
422+
android_artifact_path: 'path/to.apk',
423+
groups: "test-group-1, test-group-2"
424+
})
425+
426+
expect(returned_release).to eq(release)
427+
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
428+
end
427429

428-
describe 'when updating release notes' do
429-
it 'raises error if request returns a 400' do
430-
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
431-
.to receive(:patch_project_app_release)
432-
.and_raise(Google::Apis::Error.new({}, status_code: '400', body: 'release notes too long'))
433-
434-
expect do
435-
action.run({
436-
app: android_app_id,
437-
android_artifact_path: 'path/to.apk',
438-
release_notes: 'updated'
439-
})
440-
end.to raise_error("#{ErrorMessage::INVALID_RELEASE_NOTES}: release notes too long")
430+
it 'distributes to groups and testers, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
431+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
432+
.to receive(:distribute_project_app_release)
433+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
434+
.to receive(:distribute_project_app_release) do |_, release_name, request|
435+
expect(request.group_aliases).to eq(%w[test-group-1 test-group-2])
436+
expect(request.tester_emails).to eq(%w[[email protected] [email protected]])
437+
end
438+
expect_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
439+
.to_not(receive(:patch_project_app_release))
440+
441+
returned_release = action.run({
442+
app: android_app_id,
443+
android_artifact_path: 'path/to.apk',
444+
groups: "test-group-1, test-group-2",
445+
446+
})
447+
448+
expect(returned_release).to eq(release)
449+
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(release)
450+
end
441451
end
442452

443-
it 'distributes to groups and testers, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
444-
updated_release = release.merge({ releaseNotes: { text: 'updated' } })
445-
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
446-
.to receive(:patch_project_app_release)
447-
.and_return(Google::Apis::FirebaseappdistributionV1::GoogleFirebaseAppdistroV1Release.from_json(updated_release.to_json))
448-
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
449-
.to receive(:distribute_project_app_release)
450-
451-
returned_release = action.run({
452-
app: android_app_id,
453-
android_artifact_path: 'path/to.apk',
454-
release_notes: 'updated'
455-
})
453+
describe 'when updating release notes' do
454+
it 'raises error if request returns a 400' do
455+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
456+
.to receive(:patch_project_app_release)
457+
.and_raise(Google::Apis::Error.new({}, status_code: '400', body: 'release notes too long'))
458+
459+
expect do
460+
action.run({
461+
app: android_app_id,
462+
android_artifact_path: 'path/to.apk',
463+
release_notes: 'updated'
464+
})
465+
end.to raise_error("#{ErrorMessage::INVALID_RELEASE_NOTES}: release notes too long")
466+
end
456467

457-
expect(returned_release).to eq(updated_release)
458-
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(updated_release)
468+
it 'distributes to groups and testers, returns release and updates FIREBASE_APP_DISTRO_RELEASE' do
469+
updated_release = release.merge({ releaseNotes: { text: 'updated' } })
470+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
471+
.to receive(:patch_project_app_release)
472+
.and_return(Google::Apis::FirebaseappdistributionV1::GoogleFirebaseAppdistroV1Release.from_json(updated_release.to_json))
473+
allow_any_instance_of(Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService)
474+
.to receive(:distribute_project_app_release)
475+
476+
returned_release = action.run({
477+
app: android_app_id,
478+
android_artifact_path: 'path/to.apk',
479+
release_notes: 'updated'
480+
})
481+
482+
expect(returned_release).to eq(updated_release)
483+
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE]).to eq(updated_release)
484+
end
459485
end
460486
end
461487
end

0 commit comments

Comments
 (0)