Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294185

Allow assertions on the number of database queries run during tests

$
0
0

Problem/Motivation

Once #3346765: Add PerformanceTestBase for allowing browser performance assertions within FunctionalJavaScriptTests lands it will be feasible to add database query logging to PerformanceTestTrait, this would allow us to count the number of database queries on certain pages (hot and cold caches too etc.), add assertions for them, then tighten the tests when the number of queries drops, or be warned if it's going to increase (which might be fine, or might be a regression).

Steps to reproduce

Proposed resolution

Add a performance_test module to core.

Enable this module in PerformanceTestBase.

Add a query logging implementation using the database API's new query events system.

In a post response task, designed to run last, write the logged query events to a key/value entry.

In PerformanceTestTrait, check the key value and add the query count to the PerformanceData value object.

Queries are collected incrementally until they're checked - this means that if a page causes asset, image style, or AJAX controllers to be requested too, the queries from those will be added to the log.

The number of queries is not 100% deterministic in the currrent test coverage, this might be interactions of things like cache collectors which could vary by the order in which http requests finish on the tested site. We can add greater than and less than assertions to start with and potentially address this later. But also asserting on a range will still lets us adjust that range if core goes lower or higher than it due to a change.

Remaining tasks

Already using this to verify #3395776: Make POST requests render cacheable and it found a missing change in that issue.

Additionally, via working on the two issues I think I've found a caching bug/shortcoming in Views #3400596: Views adds cache contexts inconsistently.

Once this is committed, we can build on it (probably without any significant changes, just additions) to add database queries to opentelemetry traces too #3377657: Add database query spans to otel traces. They'll then be browsable on http://grafana.tag1demo.tag1.io/d/teMVIdjVz/umami?orgId=1&refresh=30s&fr...

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 294185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>