Skip to content

Trace function calls in concurrent Elixir processes.

License

Notifications You must be signed in to change notification settings

tagbase-io/tracee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tracee

Hex.pm CI Status

This Elixir library offers functionality to trace and assert expected function calls within concurrent Elixir processes.

This allows you to ensure that destructive and/or expensive functions are only called the expected number of times. For more information, see the Elixir forum post that motivated the development of this library.

Installation

Just add tracee to your list of dependencies in mix.exs:

def deps do
  [
    {:tracee, "~> 0.2.0", only: :test}
  ]
end

Usage

defmodule ModuleTest do
  use ExUnit.Case

  import Tracee

  setup :verify_on_exit!

  describe "fun/0" do
    test "calls expensive function only once" do
      expect(AnotherModule, :expensive_fun, 1)

      assert Module.fun()
    end

    test "calls expensive function only once from another process" do
      expect(AnotherModule, :expensive_fun, 1)

      assert fn -> Module.fun() end
             |> Task.async()
             |> Task.await()
    end

    test "never calls expensive function" do
      expect(AnotherModule, :expensive_fun, 1, 0)

      assert Module.fun()
    end
  end
end

License

MIT

About

Trace function calls in concurrent Elixir processes.

Topics

Resources

License

Stars

Watchers

Forks

Languages