EctoDoctor.RepeatedQueries.Assertions (Ecto Doctor v0.0.1)

Copy Markdown View Source

Checks one block of code for N+1 queries inside an ExUnit test.

import EctoDoctor.RepeatedQueries.Assertions

test "lists posts", %{conn: conn} do
  assert_no_repeated_queries(fn -> get(conn, ~p"/posts") end)
end

The block is scanned on its own so its queries don't count toward the test's own scan.

Summary

Functions

Fails the test when the function runs an N+1 query and shows where it came from.

Fails the test when the function runs no N+1 query, such as to prove the old code is still caught.

Functions

assert_no_repeated_queries(fun)

@spec assert_no_repeated_queries((-> term())) :: :ok

Fails the test when the function runs an N+1 query and shows where it came from.

assert_repeated_queries(fun)

@spec assert_repeated_queries((-> term())) :: :ok

Fails the test when the function runs no N+1 query, such as to prove the old code is still caught.