Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The tests fail randomly with the same error:
Link with label apple (2) found.
Fails:
https://www.drupal.org/pift-ci-job/545894
https://www.drupal.org/pift-ci-job/546665
https://www.drupal.org/pift-ci-job/545915
https://www.drupal.org/pift-ci-job/549727
https://www.drupal.org/pift-ci-job/550264
https://www.drupal.org/pift-ci-job/550273
The tests fail because duplicate results don't always get ordered in the same order.
Comment | File | Size | Author |
---|---|---|---|
#23 | interdiff-23.txt | 3.58 KB | dermario |
#23 | fix_random_test_fail-2834730-23.patch | 1.07 KB | dermario |
#18 | fix_random_test_fail-2834730-18.patch | 3.32 KB | dermario |
Comments
Comment #2
borisson_I ran the test locally with
--repeat 24 --class "Drupal\facets\Tests\IntegrationTest::testHardLimit"
and didn't get any red tests.Because that didn't cause any failures; I ran
php core/scripts/run-tests.sh --repeat 12 --concurrency 4 --class "Drupal\facets\Tests\IntegrationTest""
. That came back green as wellThis is with my local checkout of search_api, that does run on
HEAD
. Because it freaks me out that there's such a big difference, I went back and ran the first test again withbeta-3
that also ended up green.Comment #3
dermarioI get some fails on my vagrant box:
I try to find out more now.
Comment #4
dermarioMy assumption is that we get these fails by a kind of random sorted facets. As you can see in the screenshot, we have 3 facets but it's strawberry (2) and not apple (2).
Comment #5
borisson_This means that we can probably resolve this issue by adding alphabetical sorting as well as count sorting on the facet? That would make sense.
I'll give that a shot later.
Comment #6
dermarioYes, sorting excplitly is an option. A different approach could be to make sure that apple has a different amount of results in facets than strawberry. Currently they both have 2 results.
Comment #7
borisson_Comment #8
borisson_Committed #7, that should work in theory.
Comment #10
dermarioWith the patch applied i still get these random test fails on my local machine. 2 out of 8 tests are failing. It seems like my assumption regarding sort was not correct. I would like to debug that issue on my local machine to find the root cause. Should we reopen that issue?
Comment #11
borisson_Sure, reopening.
Comment #12
dermarioI just want to give an update and say that i am still working on it. One thing that is blocking me, is that i cannot enable hard limit due to this check:
Maybe i am doing it wrong but my facets source is
views_page:testindex__page_1
. Is my problem related to #2772745: Search API integration doesn't check/define feature support of backends ?What is weird is, that the sort order of facets is correct without the hard_limit:
And is incorrect with the hard limit set:
One assumption (no proof for it) might be, that the limiting is done before sorting? I would like to dive in deeper and debug the actual hard limit (and not the test). If i could solve the problem about (facet source id check) i could check that.
Comment #13
borisson_The check should've been fixed in #2835112: Incorrect search api check for hierarchy option.
Comment #14
dermarioComment #15
dermarioI could reproduce it, but i still do not know the root cause. :-)
I created the following facets scenario:
i disabled cache in
Drupal\views\ViewExecutable::execute
temorarly :After that i reloaded my search page several times and got this result:
https://www.drupal.org/files/issues/random-facets.mp4
For any reason
\Drupal\search_api_db\Plugin\search_api\backend\Database::getFacets()
returns these facets randomly with hard limit enabled on my machine.Comment #16
dermarioI could narrow it down to the sql query that generates the facets. In my case its this query, generated and called in
\Drupal\search_api_db\Plugin\search_api\backend\Database::getFacets
:This query gives me the facets with the same quantity in a random sort order:
To find a solution for that problem, we must decide how the hard limit should behave in such cases. If there is a hard limit of 3 but there are 4 facets with the same quantity of results, which one should be cut away? The sort options defined in the facets settings do not help here, as the processing (sorting) applies much later. E.g. we do not have the translated entities label here. I am not a facets pro but i see the following solutions for that problem:
ORDER BY num DESC, value ASC
. This would prevent randomness, but might be a non transparent to the user, as the selection bases on ids. But still better than random sort.I would try to go for option 1 + user info, but would be happy to get feedback on this.
Comment #17
borisson_Thanks for putting so much work into figuring this out @dermario, really awesome work!
I think we should go for .1 + a note in README.txt
Comment #18
dermarioThank you @borrison_ i really like to help here and try to finish things i started :) Thank you as well for always giving such a good and quick feedback.
I created #2836994: Fix random test fail in facets module in search_api with a patch to get 2nd sort dimension in. In the patch attached is a new method to assert a certain sort order of facets. That code helped me debugging this issue and could be useful for other tests. With the patch reported in #2836994: Fix random test fail in facets module i had 200 test-runs without a single fail.
There is also a text for the README.txt, which might be improved (as i am not a native speaker).
Comment #19
dermarioComment #20
borisson_The text here looks good, it clearly details the problem.
This passes 80 cols, and should be reformatted.
Comment #22
dermarioUps, seems like my new assertions are not working with the restructured test framework, so i reverted them again. I also corrected the line-length in README.txt
Comment #23
dermarioThis should be the right patch. Messed up my local repo a bit. Sorry for that :-)
Comment #25
borisson_Updated title to state more clearly what's actually going on + small update to IS.
Comment #26
dermario#2836994: Fix random test fail in facets module was committed yesterday. So we could add the description in #23.
Comment #27
borisson_@dermario: everything is currently waiting on reviews for #2772745: Search API integration doesn't check/define feature support of backends. The last time I had to reroll that issue it took me ~25 days to get everything back to green. Even though this is a very small change I'd prefer not to have to go trough rerolling that again. I'd love to get as much feedback as possible on that issue (does the upgrade path work, do the facet still work after that? Do the other changes make sense?)
Comment #28
borisson_Committed, thanks!