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

Cachalot breaks unit tests --parallel #117

Open
kunalgrover05 opened this issue Sep 15, 2018 · 2 comments
Open

Cachalot breaks unit tests --parallel #117

kunalgrover05 opened this issue Sep 15, 2018 · 2 comments
Labels

Comments

@kunalgrover05
Copy link

Running parallel unit tests in Django breaks when using Cachalot 2.1.0.

Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.6/unittest/case.py", line 601, in run
    self.setUp()
  File "/home/kunal/leanagri/protect/tests.py", line 26, in setUp
    nursery_area_factor=0.29)
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/query.py", line 394, in create
    obj.save(force_insert=True, using=self.db)
  File "/home/kunal/leanagri/core/models.py", line 111, in save
    self.full_clean()
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/base.py", line 1245, in full_clean
    self.validate_unique(exclude=exclude)
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/base.py", line 1034, in validate_unique
    errors = self._perform_unique_checks(unique_checks)
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/base.py", line 1131, in _perform_unique_checks
    if qs.exists():
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/query.py", line 670, in exists
    return self.query.has_results(using=self.db)
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/sql/query.py", line 517, in has_results
    return compiler.has_results()
  File "/home/kunal/env3/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 858, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/home/kunal/env3/lib/python3.6/site-packages/cachalot/monkey_patch.py", line 32, in inner
    return original(compiler, *args, **kwargs)
  File "/home/kunal/env3/lib/python3.6/site-packages/cachalot/monkey_patch.py", line 86, in inner
    cache_key, table_cache_keys)
  File "/home/kunal/env3/lib/python3.6/site-packages/cachalot/monkey_patch.py", line 40, in _get_result_or_execute_query
    data = cache.get_many(table_cache_keys + [cache_key])
  File "/home/kunal/env3/lib/python3.6/site-packages/cachalot/transaction.py", line 22, in get_many
    data.update(self.parent_cache.get_many(missing_keys))
  File "/home/kunal/env3/lib/python3.6/site-packages/cachalot/transaction.py", line 22, in get_many
    data.update(self.parent_cache.get_many(missing_keys))
  File "/home/kunal/env3/lib/python3.6/site-packages/django/core/cache/backends/memcached.py", line 96, in get_many
    ret = self._cache.get_multi(new_keys)
  File "/home/kunal/env3/lib/python3.6/site-packages/memcache.py", line 1216, in get_multi
    retvals[prefixed_to_orig_key[rkey]] = val
KeyError: b'TEST:1:cc5377d1567fb2cc4c59ba5a48b7354d7c987aca'
@Andrew-Chen-Wang
Copy link
Collaborator

I'd like to hear if anyone's still having issues with this with --parallel. Would be helpful to know exactly wtf is going on!

@dbartenstein
Copy link
Contributor

dbartenstein commented Aug 18, 2021

I'd like to hear if anyone's still having issues with this with --parallel. Would be helpful to know exactly wtf is going on!

Hi @Andrew-Chen-Wang: we are using cachalot and running our tests with --parallel and we’re not experiencing any issues. We are using Django 3.2 LTS and cachalot 2.4.2.

Edit:
We deactivate the caches when running unit tests. So this might be the reason why it works for us.

@override_settings(
    CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
        }
    }
)

With Django it’s possible to enforce that selected unit tests run in sequence: https://docs.djangoproject.com/en/3.2/topics/testing/advanced/#enforce-running-test-classes-sequentially

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants