Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ coverage.xml
venv
.direnv/
.envrc
venv
.venv
.vscode
2 changes: 2 additions & 0 deletions debug_toolbar/panels/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TimerPanel(Panel):
Panel that displays the time a response took in milliseconds.
"""

is_async = True

def nav_subtitle(self):
stats = self.get_stats()
if stats.get("utime"):
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Problematic Parts
the main benefit of the toolbar
- Support for async and multi-threading: ``debug_toolbar.middleware.DebugToolbarMiddleware``
is now async compatible and can process async requests. However certain
panels such as ``TimerPanel``, ``RequestPanel`` and ``ProfilingPanel`` aren't
panels such as ``RequestPanel`` and ``ProfilingPanel`` aren't
fully compatible and currently being worked on. For now, these panels
are disabled by default when running in async environment.
follow the progress of this issue in `Async compatible toolbar project <https://github.com/orgs/jazzband/projects/9>`_.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change log
Pending
-------

* Added support for async to timer panel.
* Added a note about the default password in ``make example``.
* Removed logging about the toolbar failing to serialize a value into JSON.
* Moved the the import statement of ``debug_toolbar.urls`` to within the if
Expand Down
24 changes: 24 additions & 0 deletions tests/test_integration_async.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import unittest
from unittest.mock import patch

Expand Down Expand Up @@ -506,6 +507,29 @@ async def test_intercept_redirects(self):
# Link to LOCATION header.
self.assertIn(b'href="/regular/redirect/"', response.content)

async def test_server_timing_headers(self):
response = await self.async_client.get("/execute_sql/")
server_timing = response["Server-Timing"]
expected_partials = [
r'TimerPanel_utime;dur=(\d)*(\.(\d)*)?;desc="User CPU time", ',
r'TimerPanel_stime;dur=(\d)*(\.(\d)*)?;desc="System CPU time", ',
r'TimerPanel_total;dur=(\d)*(\.(\d)*)?;desc="Total CPU time", ',
r'TimerPanel_total_time;dur=(\d)*(\.(\d)*)?;desc="Elapsed time", ',
r'SQLPanel_sql_time;dur=(\d)*(\.(\d)*)?;desc="SQL 1 queries", ',
r'CachePanel_total_time;dur=0;desc="Cache 0 Calls"',
]
for expected in expected_partials:
self.assertTrue(re.compile(expected).search(server_timing))

@override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": True})
async def test_timer_panel(self):
response = await self.async_client.get("/regular/basic/")
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
'<script type="module" src="/static/debug_toolbar/js/timer.js" async>',
)

async def test_auth_login_view_without_redirect(self):
response = await self.async_client.get("/login_without_redirect/")
self.assertEqual(response.status_code, 200)
Expand Down