• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

agentjido / jido / dbbb4f6e8540ac27914ef3adfb163d49c9ed7729

20 Feb 2025 12:44PM UTC coverage: 79.402% (-0.3%) from 79.729%
dbbb4f6e8540ac27914ef3adfb163d49c9ed7729

push

github

mikehostetler
Enhance test utilities with improved assertions and async testing support

- Add `assert_eventually/2` macro in new `JidoTest.Helpers.Assertions` module
- Refactor existing test cases to use new assertion helper
- Remove redundant `assert_eventually/3` implementation from `JidoTest.Case`
- Improve handling of async and timing-sensitive tests across multiple modules
- Remove `Jido.Memory.TestHelpers` module from test_helper.exs

8 of 18 new or added lines in 1 file covered. (44.44%)

1 existing line in 1 file now uncovered.

1939 of 2442 relevant lines covered (79.4%)

30779.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.44
/test/support/assertions.ex
1
defmodule JidoTest.Helpers.Assertions do
2
  @moduledoc false
3
  import ExUnit.Assertions
4

5
  @doc """
6
  Partially adapted from Thomas Millar's wait_for
7
  https://gist.github.com/thmsmlr/8b32cc702acb48f39e653afc0902374f
8

9
  This will assert continously for the :check_interval until the :timeout
10
  has been reached.
11

12
  NOTE: In general, it is preferable to wait for some signal like a telemetry
13
  event or message, but sometimes this is just easier.
14
  """
15
  defmacro assert_eventually(assertion, opts \\ []) do
16
    quote do
17
      JidoTest.Helpers.Assertions.wait_for(
18
        fn ->
19
          assert unquote(assertion)
20
        end,
21
        unquote(opts)
22
      )
23
    end
24
  end
25

26
  def wait_for(fun, opts \\ []) do
27
    timeout = Keyword.get(opts, :timeout, 100)
6✔
28
    check_interval = Keyword.get(opts, :check_interval, 10)
6✔
29

30
    start_time = System.monotonic_time(:millisecond)
6✔
31
    ref = make_ref()
6✔
32

33
    try do
6✔
34
      do_wait_for(fun, start_time, timeout, ref, check_interval)
6✔
35
    catch
36
      {:wait_for_timeout, ^ref, last_error} ->
NEW
37
        message = """
×
NEW
38
        Assertion did not succeed within #{timeout}ms.
×
39
        Last failure:
NEW
40
        #{Exception.format(:error, last_error, [])}
×
41
        """
42

NEW
43
        flunk(message)
×
44
    end
45
  end
46

47
  defp do_wait_for(fun, start_time, timeout, ref, check_interval) do
6✔
48
    fun.()
6✔
49
    :ok
50
  rescue
NEW
51
    error in [ExUnit.AssertionError] ->
×
NEW
52
      current_time = System.monotonic_time(:millisecond)
×
53

NEW
54
      if current_time - start_time < timeout do
×
NEW
55
        Process.sleep(check_interval)
×
NEW
56
        do_wait_for(fun, start_time, timeout, ref, check_interval)
×
57
      else
NEW
58
        throw({:wait_for_timeout, ref, error})
×
59
      end
60
  end
61
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc