-
Notifications
You must be signed in to change notification settings - Fork 352
Fix: Make URL cache clearing thread-safe in _django_set_urlconf
#1233
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -107,3 +107,47 @@ def test_something_else(): | |||
|
|
||||
| result = django_pytester.runpytest_subprocess() | ||||
| assert result.ret == 0 | ||||
|
|
||||
|
|
||||
| @pytest.mark.django_project( | ||||
| extra_settings=""" | ||||
| ROOT_URLCONF = "empty" | ||||
| """ | ||||
| ) | ||||
| def test_urls_concurrent(django_pytester: DjangoPytester) -> None: | ||||
| "Test that the URL cache clearing is thread-safe with pytest-xdist." | ||||
| pytest.importorskip("xdist") | ||||
|
|
||||
| django_pytester.makepyfile( | ||||
| empty="urlpatterns = []", | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used
Suggested change
|
||||
| urls1=""" | ||||
| from django.urls import path | ||||
| urlpatterns = [path('url1/', lambda r: None, name='url1')] | ||||
| """, | ||||
| urls2=""" | ||||
| from django.urls import path | ||||
| urlpatterns = [path('url2/', lambda r: None, name='url2')] | ||||
| """, | ||||
| ) | ||||
|
|
||||
| django_pytester.create_test_module( | ||||
| """ | ||||
| import pytest | ||||
| from django.urls import reverse, NoReverseMatch | ||||
|
|
||||
| @pytest.mark.urls('urls1') | ||||
| def test_urls1(): | ||||
| reverse('url1') | ||||
| with pytest.raises(NoReverseMatch): | ||||
| reverse('url2') | ||||
|
|
||||
| @pytest.mark.urls('urls2') | ||||
| def test_urls2(): | ||||
| reverse('url2') | ||||
| with pytest.raises(NoReverseMatch): | ||||
| reverse('url1') | ||||
| """ | ||||
| ) | ||||
|
|
||||
| result = django_pytester.runpytest_subprocess("-n", "2") | ||||
| assert result.ret == 0 | ||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this test over to my
mainbranch, and ran this on py3.13it has not failed -- keeps going, after 100+ iterations (keep in mind, i only copied the test, not the "fix")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS. I also ran this with
pytest -n auto(same loop as above) -- no difference, i dont see the race condition