[#18] adding the Dashboard receiver

This commit is contained in:
Felipe Ripoll 2018-06-26 14:52:12 -06:00
parent eb799a4f5e
commit 4d1ae46ed4
8 changed files with 270 additions and 31 deletions

View File

@ -14,7 +14,12 @@ config :poa_backend,
config :poa_backend,
:receivers,
[
# {:dashboard_receiver, POABackend.Receivers.Dashboard, [args: "myargs"]}
{:dashboard_receiver, POABackend.Receivers.Dashboard, [
scheme: :http,
ws_url: "/ws",
port: 8181,
ws_secret: "mywssecret"
]}
]
# here we define the type of metrics we accept. We will create a GenStage Producer per each type
@ -29,5 +34,5 @@ config :poa_backend,
config :poa_backend,
:subscriptions,
[
# {:dashboard_receiver, [:ethereum_metrics]}
{:dashboard_receiver, [:ethereum_metrics]}
]

View File

@ -61,6 +61,7 @@ defmodule POABackend.Receiver do
- `init_receiver/1`: Called only once when the process starts
- `metrics_received/3`: This function is called eveytime the Producer (metric type) receives a message.
- `handle_message/1`: This is called when the Receiver process receives an Erlang message
- `terminate/1`: Called just before stopping the process
This is a simple example of custom Receiver Plugin
@ -102,6 +103,13 @@ defmodule POABackend.Receiver do
"""
@callback metrics_received(metrics :: [term()], from :: pid(), state :: any()) :: {:ok, state :: any()}
@doc """
In this callback is called when the Receiver process receives an erlang message.
It must return `{:ok, state}`.
"""
@callback handle_message(msg :: any(), state :: any()) :: {:ok, state :: any()}
@doc """
This callback is called just before the Process goes down. This is a good place for closing connections.
"""
@ -113,16 +121,19 @@ defmodule POABackend.Receiver do
@behaviour POABackend.Receiver
@doc false
def start_link(%{name: name} = state) do
GenStage.start_link(__MODULE__, state, name: name)
end
@doc false
def init(state) do
{:ok, internal_state} = init_receiver(state.args)
{:consumer, Map.put(state, :internal_state, internal_state), subscribe_to: state.subscribe_to}
end
@doc false
def handle_events(events, from, state) do
{:ok, internal_state} = metrics_received(events, from, state.internal_state)
@ -130,6 +141,13 @@ defmodule POABackend.Receiver do
{:noreply, [], %{state | internal_state: internal_state}}
end
@doc false
def handle_info(msg, state) do
{:ok, internal_state} = handle_message(msg, state.internal_state)
{:noreply, [], %{state | internal_state: internal_state}}
end
@doc false
def terminate(_reason, state) do
terminate(state)
end

View File

@ -0,0 +1,137 @@
defmodule POABackend.Receivers.Dashboard do
@moduledoc """
This is a Receiver Plugin which exposes a Websocket server and sends the metrics to the connected clients
This Receiver needs some data to be put in the config file (_receivers_ section), for example:
{:dashboard_receiver, POABackend.Receivers.Dashboard, [
scheme: :http,
ws_url: "/ws",
port: 8181,
ws_secret: "mywssecret"
]}
* scheme: the scheme type :http or :https
* ws_url: endpoint for starting websocket connection
* port: the TCP port where the websocket server will listen
* ws_secret: the secret string which the clients must put in the "wssecret" header in order to start the connection
__All fields are mandatory__
"""
use POABackend.Receiver
alias __MODULE__
defmodule SocketHandler do
@moduledoc false
alias POABackend.Protocol.Message
@behaviour :cowboy_websocket_handler
def init(_, _req, _opts) do
{:upgrade, :protocol, :cowboy_websocket}
end
def websocket_init(_type, req, %{receiver_id: receiver_id, ws_secret: ws_secret}) do
case :cowboy_req.parse_header("wssecret", req) do
{_, ^ws_secret, req} ->
send(receiver_id, {:add_client, self()})
{:ok, req, %{}}
{_, _, req} ->
{:shutdown, req}
end
end
def websocket_handle(_message, req, state) do
{:ok, req, state}
end
def websocket_info(%Message{} = message, req, state) do
{:reply, {:text, build_message(message)}, req, state}
end
def websocket_terminate(_reason, _req, _state) do
:ok
end
defp build_message(%Message{agent_id: agent_id, data: data}) do
{:ok, message} =
%{agent_id: agent_id, data: data}
|> Poison.encode
message
end
end
defmodule Router do
@moduledoc false
use Plug.Router
plug :match
plug :dispatch
match _ do
send_resp(conn, 404, "")
end
end
def init_receiver(opts) do
:ok = start_websockets_server(opts)
{:ok, %{clients: []}}
end
def metrics_received(metrics, _from, %{clients: clients} = state) do
:ok = dispatch_metric(metrics, clients)
{:ok, state}
end
def handle_message({:add_client, client}, %{clients: clients} = state) do
{:ok, %{state | clients: [client | clients]}}
end
def terminate(_) do
:ok
end
defp start_websockets_server(opts) do
{_, scheme} = List.keyfind(opts, :scheme, 0)
{_, ws_url} = List.keyfind(opts, :ws_url, 0)
{_, port} = List.keyfind(opts, :port, 0)
{_, ws_secret} = List.keyfind(opts, :ws_secret, 0)
%{start: {module, function, args}} = Plug.Adapters.Cowboy.child_spec(scheme: scheme, plug: Dashboard.Router, options: [port: port, dispatch: cowboy_dispatch(ws_url, ws_secret)])
apply(module, function, args)
:ok
end
defp cowboy_dispatch(url, secret) do
[
{:_, [
{url, Dashboard.SocketHandler, %{receiver_id: self(), ws_secret: secret}},
{:_, Plug.Adapters.Cowboy.Handler, {Dashboard.Router, []}}
]}
]
end
defp dispatch_metric(metrics, clients) do
for client <- clients do
for metric <- metrics do
send(client, metric)
end
end
:ok
end
end

View File

@ -78,6 +78,8 @@ defmodule POABackend.Receivers.DynamoDB do
{:ok, state}
end
def handle_message(_message, state), do: {:ok, state}
def terminate(_) do
:ok
end

View File

@ -41,6 +41,7 @@ defmodule POABackend.MixProject do
{:excoveralls, "~> 0.8", only: [:test, :dev], runtime: false},
{:httpoison, "~> 1.0", only: [:test], runtime: true},
{:mock, "~> 0.3", only: [:test], runtime: false},
{:websockex, "~> 0.4", only: [:test]},
# Docs
{:ex_doc, "~> 0.18", only: :dev, runtime: false}

View File

@ -1,31 +1,31 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [], [], "hexpm"},
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [], [{:cowlib, "~> 1.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [], [], "hexpm"},
"credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [], [], "hexpm"},
"ex_aws": {:hex, :ex_aws, "2.0.2", "8df2f96f58624a399abe5a0ce26db648ee848aca6393b9c65c939ece9ac07bfa", [], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
"ex_aws_dynamo": {:hex, :ex_aws_dynamo, "2.0.0", "07b1117bbd1b1d04e2598190834c69c271db1d357cc21b82240d1a0b17194165", [], [{:ex_aws, "~> 2.0.0", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.8.2", "b941a08a1842d7aa629e0bbc969186a4cefdd035bad9fe15d43aaaaaeb8fae36", [], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.14.0", "65ae78509f85b59d360690ce3378d5096c3130a0694bab95b0c4ae66f3008fad", [], [], "hexpm"},
"hackney": {:hex, :hackney, "1.12.1", "8bf2d0e11e722e533903fe126e14d6e7e94d9b7983ced595b75f532e04b7fdc7", [], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.1.1", "96ed7ab79f78a31081bb523eefec205fd2900a02cda6dbc2300e7a1226219566", [], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.1", "cbc3b2fa1645113267cc59c760bafa64b2ea0334635ef06dbac8801e42f7279c", [], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [], [], "hexpm"},
"meck": {:hex, :meck, "0.8.9", "64c5c0bd8bcca3a180b44196265c8ed7594e16bcc845d0698ec6b4e577f48188", [], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], [], "hexpm"},
"mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [], [], "hexpm"},
"plug": {:hex, :plug, "1.5.1", "1ff35bdecfb616f1a2b1c935ab5e4c47303f866cb929d2a76f0541e553a58165", [], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.3", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [], [], "hexpm"},
"ranch": {:hex, :ranch, "1.5.0", "f04166f456790fee2ac1aa05a02745cc75783c2bfb26d39faf6aefc9a3d3a58a", [], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [], [], "hexpm"},
"worker_pool": {:hex, :worker_pool, "3.1.0", "c908627e04057cf29940ad0e79b89ab161db520eebc76942efd08a187babf93a", [], [], "hexpm"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:make, :rebar], [{:cowlib, "~> 1.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
"credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"},
"ex_aws": {:hex, :ex_aws, "2.0.2", "8df2f96f58624a399abe5a0ce26db648ee848aca6393b9c65c939ece9ac07bfa", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm"},
"ex_aws_dynamo": {:hex, :ex_aws_dynamo, "2.0.0", "07b1117bbd1b1d04e2598190834c69c271db1d357cc21b82240d1a0b17194165", [:mix], [{:ex_aws, "~> 2.0.0", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.9.1", "14fd20fac51ab98d8e79615814cc9811888d2d7b28e85aa90ff2e30dcf3191d6", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.14.0", "65ae78509f85b59d360690ce3378d5096c3130a0694bab95b0c4ae66f3008fad", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.13.0", "24edc8cd2b28e1c652593833862435c80661834f6c9344e84b6a2255e7aeef03", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.2.0", "2702ed3da5fd7a8130fc34b11965c8cfa21ade2f232c00b42d96d4967c39a3a3", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.2", "e21cb58a09f0228a9e0b95eaa1217f1bcfc31a1aaa6e1fdf2f53a33f7dbd9494", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"meck": {:hex, :meck, "0.8.10", "455aaef8403be46752272206613e7a15467c014d40994b22fb54cde4d1ff7075", [:rebar3], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"},
"plug": {:hex, :plug, "1.6.0", "90d338a44c8cd762c32d3ea324f6728445c6145b51895403854b77f1536f1617", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"ranch": {:hex, :ranch, "1.5.0", "f04166f456790fee2ac1aa05a02745cc75783c2bfb26d39faf6aefc9a3d3a58a", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
"websockex": {:hex, :websockex, "0.4.1", "d7b7191ec3d5dd136683b60114405a5a130a175faade773a07cb52dbd98f9442", [:mix], [], "hexpm"},
"worker_pool": {:hex, :worker_pool, "3.1.0", "c908627e04057cf29940ad0e79b89ab161db520eebc76942efd08a187babf93a", [:rebar3], [], "hexpm"},
}

View File

@ -0,0 +1,68 @@
defmodule Receivers.DashboardTest do
use ExUnit.Case
alias POABackend.Protocol.Message
@base_url "http://localhost:8181"
defmodule Client do
use WebSockex
def send(client, message) do
WebSockex.send_frame(client, {:text, message})
end
def start_link(address, state, opts \\ []) do
WebSockex.start_link(address, __MODULE__, state, opts)
end
def handle_frame({_type, msg}, caller) do
Kernel.send(caller, msg)
{:ok, caller}
end
end
test "wrong wssecret" do
assert {:error, %WebSockex.RequestError{code: 400, message: "Bad Request"}} == Client.start_link("http://localhost:8181/ws", :state, [{:extra_headers, [{"wssecret", "wrongsecret"}]}])
assert {:error, %WebSockex.RequestError{code: 400, message: "Bad Request"}} == Client.start_link("http://localhost:8181/ws", :state)
end
test "connection success" do
{result, pid} = Client.start_link("http://localhost:8181/ws", :state, [{:extra_headers, [{"wssecret", "mywssecret"}]}])
assert :ok == result
assert is_pid(pid)
end
test "ws receive metric" do
Client.start_link("http://localhost:8181/ws", self(), [{:extra_headers, [{"wssecret", "mywssecret"}]}])
POABackend.Metric.add(:ethereum_metrics, [message()])
expected_message = expected_message()
assert_receive ^expected_message, 20_000
end
test "handle messages from the client to the server (test coverage)" do
{:ok, client} = Client.start_link("http://localhost:8181/ws", self(), [{:extra_headers, [{"wssecret", "mywssecret"}]}])
Client.send(client, "hello")
end
test "http call to the server (test coverage)" do
{:ok, response} = HTTPoison.post(@base_url <> "/someendpoint", "data", [])
assert 404 == response.status_code
end
defp expected_message do
"{\"data\":{\"c\":\"c\",\"b\":\"b\",\"a\":\"a\"},\"agent_id\":\"agentid1\"}"
end
defp message do
Message.new("agentid1", :ethereum_metric, :data, %{a: "a", b: "b", c: "c"})
end
end

View File

@ -13,6 +13,10 @@ defmodule Receivers.ReceiversTest do
{:ok, state}
end
def handle_message(_message, state) do
{:ok, state}
end
def terminate(_state) do
:ok
end
@ -39,6 +43,10 @@ defmodule Receivers.ReceiversTest do
{:ok, state}
end
def handle_message(_message, state) do
{:ok, state}
end
def terminate(_state) do
:ok
end