summaryrefslogtreecommitdiff
path: root/test/soak.exs
blob: ab366f07bcfb2362bfb94080dd1052c04a3f6b0d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
defmodule Soak do
  @moduledoc """
  Run with a list of files to inspect:

      find /usr/share/ -name *png | xargs mix run test/soak.exs
  """

  def perform_infinite([]), do: false

  def perform_infinite(paths) do
    {:ok, pid} =
      GenMagic.ApprenticeServer.start_link(database_patterns: ["/usr/local/share/misc/*.mgc"])

    perform_infinite(paths, [], pid, 0)
  end

  defp perform_infinite([], done, pid, count) do
    perform_infinite(done, [], pid, count)
  end

  defp perform_infinite([path | paths], done, pid, count) do
    if rem(count, 1000) == 0, do: IO.puts(Integer.to_string(count))

    {:ok, [mime_type: _, encoding: _, content: _]} = GenServer.call(pid, {:file, path})
    perform_infinite(paths, [path | done], pid, count + 1)
  end
end

# Run with a list of files to inspect
#
#  find /usr/share/ -name *png | xargs mix run test/soak.exs

System.argv()
|> Enum.filter(&File.exists?/1)
|> Soak.perform_infinite()