Skip to content

Commit 5002cf8

Browse files
ZakuiZakoui
andauthored
Added support for async to timer panel (#2197)
* Added support for async to timer panel --------- Co-authored-by: Zakui <[email protected]>
1 parent d717797 commit 5002cf8

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ coverage.xml
1515
venv
1616
.direnv/
1717
.envrc
18-
venv
18+
.venv
1919
.vscode

debug_toolbar/panels/timer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class TimerPanel(Panel):
1717
Panel that displays the time a response took in milliseconds.
1818
"""
1919

20+
is_async = True
21+
2022
def nav_subtitle(self):
2123
stats = self.get_stats()
2224
if stats.get("utime"):

docs/architecture.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Problematic Parts
8181
the main benefit of the toolbar
8282
- Support for async and multi-threading: ``debug_toolbar.middleware.DebugToolbarMiddleware``
8383
is now async compatible and can process async requests. However certain
84-
panels such as ``TimerPanel``, ``RequestPanel`` and ``ProfilingPanel`` aren't
84+
panels such as ``RequestPanel`` and ``ProfilingPanel`` aren't
8585
fully compatible and currently being worked on. For now, these panels
8686
are disabled by default when running in async environment.
8787
follow the progress of this issue in `Async compatible toolbar project <https://github.com/orgs/jazzband/projects/9>`_.

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Change log
44
Pending
55
-------
66

7+
* Added support for async to timer panel.
78
* Added a note about the default password in ``make example``.
89
* Removed logging about the toolbar failing to serialize a value into JSON.
910
* Moved the the import statement of ``debug_toolbar.urls`` to within the if

tests/test_integration_async.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import unittest
23
from unittest.mock import patch
34

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

510+
async def test_server_timing_headers(self):
511+
response = await self.async_client.get("/execute_sql/")
512+
server_timing = response["Server-Timing"]
513+
expected_partials = [
514+
r'TimerPanel_utime;dur=(\d)*(\.(\d)*)?;desc="User CPU time", ',
515+
r'TimerPanel_stime;dur=(\d)*(\.(\d)*)?;desc="System CPU time", ',
516+
r'TimerPanel_total;dur=(\d)*(\.(\d)*)?;desc="Total CPU time", ',
517+
r'TimerPanel_total_time;dur=(\d)*(\.(\d)*)?;desc="Elapsed time", ',
518+
r'SQLPanel_sql_time;dur=(\d)*(\.(\d)*)?;desc="SQL 1 queries", ',
519+
r'CachePanel_total_time;dur=0;desc="Cache 0 Calls"',
520+
]
521+
for expected in expected_partials:
522+
self.assertTrue(re.compile(expected).search(server_timing))
523+
524+
@override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": True})
525+
async def test_timer_panel(self):
526+
response = await self.async_client.get("/regular/basic/")
527+
self.assertEqual(response.status_code, 200)
528+
self.assertContains(
529+
response,
530+
'<script type="module" src="/static/debug_toolbar/js/timer.js" async>',
531+
)
532+
509533
async def test_auth_login_view_without_redirect(self):
510534
response = await self.async_client.get("/login_without_redirect/")
511535
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)