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

Keep random order stable for 24 hours in search API #13592

Merged
merged 2 commits into from
Feb 28, 2020

Conversation

diox
Copy link
Member

@diox diox commented Feb 27, 2020

@diox diox requested review from a team and bobsilverberg and removed request for a team February 27, 2020 13:56
Copy link
Contributor

@bobsilverberg bobsilverberg left a comment

Choose a reason for hiding this comment

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

This looks good, thanks for taking care of this @diox. I just had one suggestion about the tests.

r+wc

def test_sort_random_featured(self):
qs = self._filter(data={'featured': 'true', 'sort': 'random'})
# Note: this test does not call AddonFeaturedQueryParam so it won't
# apply the featured filtering. That's tested below in
# TestCombinedFilter.test_filter_featured_sort_random
assert qs['sort'] == ['_score']
assert qs['query']['function_score']['functions'] == [
{'random_score': {}}
{'random_score': {'seed': 737481}}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to leave room for human error. Would it be better to declare a const for the date, and then use that date both as input to @freeze_time(), and also do our own calculation of .toordinal() on the const? Then we're only specifying the value once, and not relying on a manual calculation in the test.

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 altered the value in one of the tests in e95d109 to test 2 different dates.

I kinda prefer hardcoding the value: that way we don't rely on a potentially unknown computation, we know exactly what we're going to send. With the second test having a different value I think it should be a little more reliable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd argue it's not unknown at all, as you know how it's being calculated in the code under test, but this is just a nit and I'm fine with it landing as it now stands.

@diox diox merged commit caa6adf into mozilla:master Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants