Skip to content

[Bug]: QueryLog drops queries with zero elapsed time, query counters fail at random #26

Open

Description

@roxblnfk

Describe the bug

QueryLog::log() drops a query whose elapsed is 0.0. It skips entries with if (empty($context['elapsed'])) (src/Database/QueryLog.php:42), and empty(0.0) is true. A query that finishes faster than the clock's resolution is therefore not counted, so assertNumReads() / assertNumWrites() fail at random ("expected 1, got 0").

Is this a regression?

No.

To Reproduce

  1. A fast query on SQLite (in memory), on a runner with a coarse clock.
  2. captureReadQueries() around it, then assertNumReads(1).
  3. Sometimes fails with 0 reads. It failed the first CI run of test: raise line coverage #25 (PHP 8.2) and passed on rerun.

Deterministic: call $log->log('debug', 'SELECT 1', ['elapsed' => 0.0]) — the query is not recorded.

Expected behaviour

Every executed query is recorded: check isset($context['elapsed']) (or array_key_exists) instead of empty().

Media prove

Not applicable.

Database

All of them.

Your environment

cycle/testing 1.x, src/Database/QueryLog.php:42.

Additional context

Found while raising coverage in #25.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions