depop-archive / archived-django-concurrent-test-helper

Helpers for executing Django app code concurrently within Django tests
Other
13 stars 3 forks source link

Support for Django 1.11 #5

Open msf opened 6 years ago

msf commented 6 years ago

Hi there, This project looks extremely useful. Attempting to reproduce a whole family of concurrency bugs that I've identified in some django apps I have led me here. Trying it on Django 1.11 fails with:

Exception in thread Thread-17:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/miguel/cm/GoTrips/env/lib/python2.7/site-packages/django_concurrent_tests/utils.py", line 45, in target
    env=os.environ.copy(),
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Exception in thread Thread-14:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/miguel/cm/GoTrips/env/lib/python2.7/site-packages/django_concurrent_tests/utils.py", line 45, in target
    env=os.environ.copy(),
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

trying to use this inside test code similar to:

from django.test import TransactionTestCase
from django_concurrent_tests.helpers import call_concurrently

from .mystuff import funcion_with_racy_access_to_database

class TestFoo(TransactionTestCase)
  def test_race(self):
        results = call_concurrently(
            2,
            function_with_racy_access_to_database,
            arg1='foo',
            arg2='bar',
        )
        expected = results[0]
        for e in results[1:]:
            self.assertEqual(expected, e)

where function_with_racy_access_to_database returns an int. contents of results is: [None, None]

anentropic commented 6 years ago

we have not tested on Django 1.11 yet

but this sounds like maybe you don't have:

INSTALLED_APPS = (
    # ...
    'django_concurrent_tests',
)

in your settings.py ?

That is needed so that our behind-the-scenes-magic manage.py command exists

anentropic commented 6 years ago

another thing you might need to customise in settings relates to this line of code:

getattr(settings, 'MANAGE_PY_PATH', 'manage.py')

I routinely make manage.py executable with a shebang, so I don't need to python manage.py

but you may need to set MANAGE_PY_PATH="python manage.py" or to a custom path for your project

(this is not mentioned in the README currently, but should be...)

anentropic commented 6 years ago

@msf did you solve your issue?

anentropic commented 6 years ago

I'm adding some tests for Django 1.10 and 1.11

current code is broken under 1.10+ ...they stopped using optparse in favour of argparse

but I think this is in addition to your problem with paths above

msf commented 6 years ago

Thanks, didn't test this again.

On Thu, Apr 5, 2018, 15:28 anentropic notifications@github.com wrote:

I'm adding some tests for Django 1.10 and 1.11

current code is broken under 1.10+ ...they stopped using optparse in favour of argparse

but I think this is in addition to your problem with paths above

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/depop/django-concurrent-test-helper/issues/5#issuecomment-378955776, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB9jK3jgOyuY26YMAcMrJ0LuLHzf6_Wks5tliomgaJpZM4S3e9e .

anentropic commented 6 years ago

I have released version 0.4.2 with Django 1.11 support