BuildkiteTestCollector.Tracing (buildkite_test_collector v0.3.0)
Helpers for doing simple tracing in your tests.
Link to this section Summary
Functions
Measure the execution time of a function and add a trace to the test analytics.
Link to this section Types
Link to this type
section()
@type section() :: :http | :sql | :sleep | :annotation
Valid trace types.
See the documentation for more information.
Link to this type
tags()
ExUnit test tags (specifically the module and test tags).
These are used to uniquely identify the test being executed.
Link to this section Functions
Link to this function
measure(tags, section, detail \\ nil, callable)
Measure the execution time of a function and add a trace to the test analytics.
example
Example
alias BuildkiteTestCollector.Tracing
test "it can measure an HTTP request", tags do
assert {:ok, _} =
Tracing.measure(tags, :http, "The koan of Github", fn ->
Tesla.get("https://api.github.com/zen", headers: [{"user-agent", "Tesla"}])
end)
end
test "it can measure a SQL query", tags do
import Ecto.Query
query =
from(tt in "time_travellers",
where: tt.born >= 1968 and tt.born <= 1970,
select: tt.name,
order_by: tt.name
)
assert {:ok, ["Marty McFly", "Theodore Logan, III", "William Stanley Preston, Esq."]} =
Tracing.measure(tags, :sql, inspect(query), fn ->
MyApp.all(query)
end)
end