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

handle long or duplicated screenshot filenames #36000

Merged
merged 1 commit into from Apr 19, 2019
Merged

handle long or duplicated screenshot filenames #36000

merged 1 commit into from Apr 19, 2019

Conversation

JosieMcClellan
Copy link
Contributor

Fixes #32346

Long screenshot filenames in system tests had been throwing Errno::ENAMETOOLONG. This was mostly a problem with a Linux/RSpec combo because the EXT4 filesystem limits filenames to 255 characters, and RSpec Rails uses the full describe/context/it nesting in the filename. This commit rescues Errno::ENAMETOOLONG and truncates the name to its first 225 characters plus the seconds since epoch.

This commit also handles duplicate filenames, which become more common when truncating. E.g, a long describe/context nesting may have the same first 225 chars for many tests. It was already possible though, especially with multiple manual screenshots:

take_screenshot
click_on(something) # I'm trying to isolate this effect
take_screenshot

With this commit, duplicate filenames have a unique suffix appended instead of overwriting the existing file.

Other changes:

  • improve testing slightly
    • address some previously untested behavior
    • make a few tests more isolated
    • break down some lib methods to make them more testable
  • remove #absolute_image_path because #image_path had become absolute
  • tiny refactors

@rails-bot rails-bot bot added the actionpack label Apr 17, 2019

# Default to outputting a path to the screenshot
output_type ||= "simple"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this logic anymore, is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm new to open source, so I apologize if I overstepped what I should change. It seemed the "simple" value wasn't actually used for anything; only the special values "artifact" and "inline" were used. I'm happy to put "simple" back as the default.

Copy link
Member

Choose a reason for hiding this comment

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

That's ok @JosiMcClellan - the "simple" is used if the output type set in the above in the ENV is not set. So if RAILS_SYSTEM_TESTING_SCREENSHOT and CAPYBARA_INLINE_SCREENSHOT are not set it will default to simple.

However you're right - it looks like in the display_image case statement simple is not used. I think that might be a mistake and there should be an else (which would refer to simple).

@eileencodes eileencodes added this to the 6.0.0 milestone Apr 17, 2019
@eileencodes eileencodes self-assigned this Apr 17, 2019
Copy link
Member

@eileencodes eileencodes left a comment

Choose a reason for hiding this comment

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

Hey @JosiMcClellan thanks for opening your first PR to Rails. I know you're new so don't take this personally but I think the changes here are a lot broader than they need to be.

Do we know the max length that is allowed by the filename? I think in that case we should auto-truncate the name before we even get a ENAMETOOLONG error.


# Default to outputting a path to the screenshot
output_type ||= "simple"
Copy link
Member

Choose a reason for hiding this comment

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

That's ok @JosiMcClellan - the "simple" is used if the output type set in the above in the ENV is not set. So if RAILS_SYSTEM_TESTING_SCREENSHOT and CAPYBARA_INLINE_SCREENSHOT are not set it will default to simple.

However you're right - it looks like in the display_image case statement simple is not used. I think that might be a mistake and there should be an else (which would refer to simple).

@JosieMcClellan
Copy link
Contributor Author

Thank you for the review. I put back simple and started truncating immediately. Is there anything else covered by "broader than they needed to be" that I should undo? Or, I could go back and really just change the bare minimum to add truncation... which would just be adding [0...225] I think

@eileencodes
Copy link
Member

Sorry for being unclear - yea I meant to undo everything and just make the bare minimum changes to limit the filename length.

@JosieMcClellan
Copy link
Contributor Author

Okay, this one is the bare minimum. Thanks for taking the time to help me learn.

@eileencodes eileencodes merged commit 612af19 into rails:master Apr 19, 2019
@eileencodes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errno::ENAMETOOLONG on system test screenshot
3 participants