mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
[1.10.x] Fixed #26888 -- Fixed concurrency issue in URL resolver.
Fixed a regression in625b8e9295: improper short-circuiting could lead to a KeyError when threads concurrently call RegexURLResolver._populate(). Backport of389a5318a0from master
This commit is contained in:
committed by
Tim Graham
parent
96a37a0266
commit
06323dafc7
@@ -5,6 +5,7 @@ Unit tests for reverse URL lookups.
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from admin_scripts.tests import AdminScriptTestCase
|
||||
|
||||
@@ -429,6 +430,18 @@ class ResolverTests(SimpleTestCase):
|
||||
self.assertTrue(resolver._is_callback('urlpatterns_reverse.nested_urls.View3'))
|
||||
self.assertFalse(resolver._is_callback('urlpatterns_reverse.nested_urls.blub'))
|
||||
|
||||
def test_populate_concurrency(self):
|
||||
"""
|
||||
RegexURLResolver._populate() can be called concurrently, but not more
|
||||
than once per thread (#26888).
|
||||
"""
|
||||
resolver = RegexURLResolver(r'^/', 'urlpatterns_reverse.urls')
|
||||
resolver._local.populating = True
|
||||
thread = threading.Thread(target=resolver._populate)
|
||||
thread.start()
|
||||
thread.join()
|
||||
self.assertNotEqual(resolver._reverse_dict, {})
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='urlpatterns_reverse.reverse_lazy_urls')
|
||||
class ReverseLazyTest(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user