Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[register_device] fix regression that was causing a crash when creating a device that already exists #17799

Merged
merged 7 commits into from
Jan 20, 2021

Conversation

rogerluan
Copy link
Member

@rogerluan rogerluan commented Dec 14, 2020

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

This PR resolves a regression introduced in #17426
It resolves #17591 and also this user's issue #17429 (comment) (they're the same).

Description

The root cause of this issue is that since #17426 the new ConnectAPI's "create device" method doesn't check if there's an existing device for the given UDID like the Portal's one used to. This PR adds that verification, and adds tests around it.

I couldn't figure out how to create tests for the "create" method 🙇‍♂️🤔 so I wrote tests only for the new function I created.

Testing Steps

To test this branch, modify your Gemfile as:

gem "fastlane", :git => "https://github.com/fastlane/fastlane.git", :branch => "rogerluan-fix-register-device-existing-device"

Then run bundle exec fastlane run register_device passing a UDID that is already registered.

UI.verbose("UDID '#{udid}' already exists - Skipping its creation...")
return existing
end

resp = client.post_device(name: name, platform: platform, udid: udid)
Copy link

@crooke crooke Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't know a lot about fastlane's inner workings or best practices, but could another approach be to check/catch if this POST request returns a 409 Conflict and simply ignore it (well, maybe log a message that the device already exists like you're doing above), since it would mean the device already exists. Just thinking that might be a simpler solution and shave off some time from the register_device operation.

But like I said, I don't know a lot about fastlane development, so if what you have works, great!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the same approach used in the old (now deprecated) method that did the same thing using the iTunes undocumented APIs: instead of recovering from an error after sending the request, it fails the request early before sending it to the server. The server could still return a 409 if a) the local check fails or b) if the request is invalid for other reasons, but I think that's okay

@crooke
Copy link

crooke commented Jan 14, 2021

@rogerluan I tested this branch and it works. Thanks! Can this be merged now or is there anything I can do to help?

@rogerluan
Copy link
Member Author

Hey @crooke, thanks for testing this branch and confirming it works! The only thing left is a final ✅ from @joshdholtz 🙏 thanks for your understanding!

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought on the making the "find or create" more clear 😊

spaceship/lib/spaceship/connect_api/models/device.rb Outdated Show resolved Hide resolved
Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks for fixing this 😊

@joshdholtz joshdholtz merged commit b4034cf into master Jan 20, 2021
@joshdholtz joshdholtz deleted the rogerluan-fix-register-device-existing-device branch January 20, 2021 23:37
Copy link

@fastlane-bot fastlane-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations! 🎉 This was released as part of fastlane 2.172.0 🚀

@fastlane fastlane locked and limited conversation to collaborators Mar 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

register_device crashes when device already exists
4 participants