-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The test def test_no_cached_queryset(self): Is failing from time to time which is not handy as it makes the CI failing for unrelated reasons in PRs (e.g: #1766).
mongoengine/tests/queryset/queryset.py
Lines 4709 to 4719 in 42bbe63
| def test_no_cached_queryset(self): | |
| class Person(Document): | |
| name = StringField() | |
| Person.drop_collection() | |
| for i in range(100): | |
| Person(name="No: %s" % i).save() | |
| with query_counter() as q: | |
| self.assertEqual(q, 0) | |
| people = Person.objects.no_cache() |
The issue occurs because the query_counter() context was catching queries that aren't related to this particular test.
I managed to reproduce the issue after adding some debugging code and running travis in my fork (https://travis-ci.com/bagerard/mongoengine/jobs/143421029). The additional query being counted is actually a 'killcursors' query, probably being issued after the garbage collector closes another pymongo cursors.
The query_counter context manager is very handy for debugging but since it is not only counting the queries being issued within the context (other threads or processes can pollute it), it is not very robust.
I'll push a PR that makes the query_counter context ignoring 'killcursors' queries to fix this (and add a parameter ignore_query to the query_counter to let users customize the behavior if needed). Let me know if you have other ideas