aboutsummaryrefslogtreecommitdiff
path: root/test/ex_prometheus_io_test.exs
blob: c4ce57855d3e7889cc0311949e604d194dc918fa (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
defmodule ExPrometheusIoTest do
  use ExUnit.Case, async: true
  doctest ExPrometheusIo

  test "can query for up data" do
    {pid, ref} = ExPrometheusIo.query("up")
    assert_receive {:prometheus_results, ^ref, results}
    assert results["results"] != []
    assert results["resultType"] == "vector"
    refute Process.alive?(pid)
  end

  test "can query range for up data" do
    {pid, ref} = ExPrometheusIo.range("up", 1458855801, 1458855810, 1)
    assert_receive {:prometheus_results, ^ref, results}
    assert results["results"] != []
    assert results["resultType"] == "matrix"
    refute Process.alive?(pid)
  end

  test "can query up series data" do
    {pid, ref} = ExPrometheusIo.series(["up"])
    assert_receive {:prometheus_results, ^ref, results}
    refute Process.alive?(pid)
  end

  test "http query failure doesn't break the world" do
    {pid, ref} = ExPrometheusIo.query("kill")
    refute_receive {:prometheus_results, ^ref, _}
    refute Process.alive?(pid)
  end

  test "http range failure doesn't break the wolrd" do
    {pid, ref} = ExPrometheusIo.range("kill", 0, 1, 0.5)
    refute_receive {:prometheus_results, ^ref, _}
    refute Process.alive?(pid)
  end

  test "http series failure doesn't break the world" do
    {pid, ref} = ExPrometheusIo.series(["kill"])
    refute_receive {:prometheus_results, ^ref, _}
    refute Process.alive?(pid)
  end

  test "http query timeout doesn't stop the world" do
    {_, ref} = ExPrometheusIo.query("timeout")
    refute_receive {:prometheus_results, ^ref, _}, 10
  end

  test "http range timeout doesn't stop the world" do
    {_, ref} = ExPrometheusIo.range("timeout", 0, 1, 0.5)
    refute_receive {:prometheus_results, ^ref, _}, 10
  end

  test "http series timeout doesn't stop the world" do
    {_, ref} = ExPrometheusIo.series(["timeout"])
    refute_receive {:prometheus_results, ^ref, _}, 10
  end

end