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

fix flaky user agent test #2530

Merged
merged 3 commits into from
Aug 10, 2022
Merged

Conversation

thdaraujo
Copy link
Contributor

Issue#

Fixes #2521

Description:

Fixes some flaky tests on test_faker_internet.rb related to bot_user_agent generation.

These previous test were matching against a fixed list of options for user agents and bot user agents.

The problem appeared when a new type of user agent was added to the locales. Because the generator randomly picks an user agent, the previous test would fail at random when the agent picked didn't match the regex.

But the generator should return a string even if the vendor is not available or the argument is invalid.

We can simply verify that the agent is present. Otherwise, we would have to keep the regex and these tests updated whenever a new user agent is added to the locale.

Verified

This commit was signed with the committer’s verified signature.
stevendpclark Steven Clark

Verified

This commit was signed with the committer’s verified signature.
stevendpclark Steven Clark
The previous test was matching against a fixed list of options.
The problem arised when a new type of user agent was
added to the locales. Because the generator randomly picks
an user agent, the previous test was very flaky.

The generator should return a string even if
the vendor is not available or the argument is invalid.

So we can simply verify that the agent is present.
There's no need to validate it against a regex,
because we would have to keep this regex updated
whenever a new user agent is added to the locale.
@thdaraujo thdaraujo self-assigned this Aug 9, 2022
Copy link
Contributor

@stefannibrasil stefannibrasil left a comment

Choose a reason for hiding this comment

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

Thanks! I agree that matching for strings here will always be prone to having those tests failing as it's easy to forget keeping them updated.

Have you considered adding the following scenario?

def test_bot_user_agent_with_no_argument
  assert @tester.bot_user_agent(vendor: nil)
end

Even though is not invalid, I feel like it's a good documentation to keep here.

@thdaraujo
Copy link
Contributor Author

Thanks! I agree that matching for strings here will always be prone to having those tests failing as it's easy to forget keeping them updated.

Have you considered adding the following scenario?

def test_bot_user_agent_with_no_argument
  assert @tester.bot_user_agent(vendor: nil)
end

Even though is not invalid, I feel like it's a good documentation to keep here.

good idea! Added your suggestion to the list of valid argument tests.

@thdaraujo thdaraujo force-pushed the ta/fix-flaky-user-agent-test branch from d771973 to e1c1dce Compare August 10, 2022 18:15

Verified

This commit was signed with the committer’s verified signature.
stevendpclark Steven Clark
@thdaraujo thdaraujo force-pushed the ta/fix-flaky-user-agent-test branch from e1c1dce to ec9136e Compare August 10, 2022 18:16
Copy link
Contributor

@stefannibrasil stefannibrasil left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@stefannibrasil stefannibrasil merged commit 0d689f2 into master Aug 10, 2022
@stefannibrasil stefannibrasil deleted the ta/fix-flaky-user-agent-test branch August 10, 2022 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix flaky test: bot_user_agent on test_faker_internet.rb
2 participants