Skip to content

Unit tests: assert on work done instead of elapsed time #13446

Closed

Description

@yuxi-liu-wired

5 unit-test assertions check elapsed time. They fail whenever the machine running the suite is busy, whether or not the code under test got slower:

  • frontend.worker.graph-view-test/tags-and-objects-graph-skips-large-unrelated-page-set-quickly: (< elapsed 1000), wall clock, best of 3.
  • frontend.worker.graph-view-test/tags-and-objects-graph-builds-large-tagged-set-quickly: (< elapsed 1000), wall clock, best of 3.
  • frontend.worker.search-test, the combine-results case: (< elapsed-ms 200), process CPU time.
  • frontend.worker.search-test/sync-search-indice-300-new-blocks-performance-when-semantic-search-enabled and ...-disabled: (< elapsed-ms 1000), process CPU time.

Two examples from running the suite on a laptop that was also in use: tags-and-objects-graph-builds-large-tagged-set-quickly measured 1509 ms; sync-search-indice-300-new-blocks-performance-when-semantic-search-enabled failed once and passed twice when run again alone, with no code change in between.

Proposal: keep each performance guarantee, but assert on work done instead of time, so the result does not depend on the machine.

  1. Count the work. For example, the "skips large unrelated page set" test builds the tags-and-objects graph over 12,000 unrelated pages. Instead of "under 1 second", count the entity lookups (d/entity) during build-graph and assert that the count does not depend on the 12,000 pages. This is the same idea as Django's assertNumQueries.
  2. Compare the work at 2 sizes. For a guarantee like "stays linear", count the work at n and at 4n items and assert it grew about 4 times, not 16. This catches the accidentally quadratic code these tests guard against, on any machine. The combine-results case already replaces d/entity and d/pull-many with stubs, so it can count their calls directly.

For the sync-search-indice pair, sync-search-indice-300-new-blocks-does-not-check-page-descendants already asserts the cause of the slowdown they guard without timing, so their time bound could go.

Timing itself would then belong in a separate benchmark run on a quiet machine that compares against earlier runs, rather than in the unit suite.

I can send a pull request that converts the 5 assertions this way, if that approach is acceptable.

Activity

  1. yuxi-liu-wired commented on Sep 30, 2026

    @yuxi-liu-wired
    ContributorAuthor

    Resolved by #13452: the 5 elapsed-time assertions listed here now bound the work done instead, and master has no elapsed-time assertion left in these tests.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions