Fixed #23682 -- Enhanced circular redirects detection in tests.

Please see [#23682](https://code.djangoproject.com/ticket/23682).
There's a merge conflict with master here. Do you want to update?