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 failing specs due to new wikipageviews API behavior when no data available #5513

Conversation

gabina
Copy link
Member

@gabina gabina commented Oct 18, 2023

What this PR does

The behavior of the wikipageviews API has changed when handling requests for which no data is available, causing some of our specs to fail. This PR starts managing this new behavior to fix our specs.
It basically adds a new no_data_available_response? method to identify these specific responses.
Read more details in the proper issue.

Closes #5508

Screenshots

Open questions and concerns

…e due to new wikipageviews api behavior. This change should fix failing wikipageviews specs.
@gabina
Copy link
Member Author

gabina commented Oct 19, 2023

CI failed, will check

1826 examples, 2 failures, 17 pending

Failed examples:

rspec ./spec/features/namespace_stats_spec.rb:27 # Namespace-specific stats generates and renders stats for Cookbook namespace on en.wikibooks.org
rspec ./spec/lib/importers/revision_score_importer_spec.rb:205 # RevisionScoreImporter.update_revision_scores_for_all_wikis imports data and calcuates an article completeness score for available wikis

Edit: the rerun has only one failure.
Failures:

  1) RevisionScoreImporter.update_revision_scores_for_all_wikis imports data and calcuates an article completeness score for available wikis
     Failure/Error: expect(wiki.revisions.first.wp10).to be_between(0, 100)
       expected nil to be between 0 and 100 (inclusive), but it does not respond to `<=` and `>=`
     # ./spec/lib/importers/revision_score_importer_spec.rb:213:in `block (5 levels) in <top (required)>'
     # ./spec/lib/importers/revision_score_importer_spec.rb:209:in `each'
     # ./spec/lib/importers/revision_score_importer_spec.rb:209:in `block (4 levels) in <top (required)>'
     # ./spec/lib/importers/revision_score_importer_spec.rb:206:in `block (3 levels) in <top (required)>'

Edit: it's passing now

…iven day. This is because otherwise the test gets broken if someone visits the article.
Comment on lines +164 to +165
before { travel_to Date.new(2023, 10, 18) }

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 had to add this because it looks like I visited the site yesterday so I broke the spec.
I noticed that because the build for PR #5498 failed with:

  3) WikiPageviews.average_views_for_article for an article that exist but has no view data returns 0
     Failure/Error: expect(subject).to eq(0)

       expected: 0
            got: 1.0

This way it should be more robust.

@gabina
Copy link
Member Author

gabina commented Oct 19, 2023

@ragesoss this PR is ready for review ( I don't think I can set you as reviewer)

Copy link
Member

@ragesoss ragesoss left a comment

Choose a reason for hiding this comment

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

Do you think the about:blank behavior for the type is a bug?

# As of October 2023, we started to see 404 not found responses with about:blank type
# and a specific detail when handling requests for which no data is available
def no_data_available_response?(response)
no_data_avialable_detail = 'The date(s) you used are valid, but we either do not have data '\
Copy link
Member

Choose a reason for hiding this comment

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

I think relying on the exact 'detail' message here is going to be too fragile. Is this always the message when type is about:blank? I think the type is less likely to change than the text of the 'detail' message, which could get updated wording at any point.

Copy link
Member Author

Choose a reason for hiding this comment

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

At first glance, I thought that about:blankas type was a kind of bug on the API side, as I didn't find any specific documentation for that and it wasn't pretty meaningful for me. That's why I decided to rely on the detail instead, I thought that maybe the type would change in the near future. However, I think we can rely on the status as you mentioned in your other comment.

@@ -101,13 +101,23 @@ def parse_results(response)
return data['items'] if data['items']
# As of October 2017, the data type is https://www.mediawiki.org/wiki/HyperSwitch/errors/not_found
return no_results if %r{errors/not_found}.match?(data['type'])
Copy link
Member

Choose a reason for hiding this comment

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

Are there still also requests that return this error type, or did all 404's become about:blank?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to just rely on the 404 status and ignore type altogether? I imagine that any case of a 404 should be treated the same way by the Dashboard, and it looks like that's the only error mode that we've ever handled anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm good point. I wasn't able to reproduce any request returning https://www.mediawiki.org/wiki/HyperSwitch/errors/not_found as type. If I understand correctly, this request should be one of those that returned that type. So I think that your point about only relying on the 404 status makes total sense. Done on 41a142f. Two specs are failing but I guess those are flaky tests?

Comment on lines +53 to +54
VCR.use_cassette 'wiki_pageviews/views_for_article' do
expect { subject }.not_to raise_error
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 don't think that stubbing the request makes sense now. Instead of that, I set start and end date out of the "allowed data range"

@gabina gabina requested a review from ragesoss October 20, 2023 19:30
@ragesoss ragesoss merged commit e57dd7d into WikiEducationFoundation:master Oct 20, 2023
1 check failed
@ragesoss
Copy link
Member

LGTM!

@gabina gabina deleted the update-wikipageviews-to-fix-specs-for-new-api-behavior branch November 3, 2023 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update WikiPageviews and spec for new API behavior
2 participants