From b1adfbf2258f0c6c973e6831cefc527fc52c09cd Mon Sep 17 00:00:00 2001 From: Eduardo Gurgel Date: Sun, 8 Oct 2017 19:39:57 +1300 Subject: [PATCH 1/3] Super ultra update to Elixir 1.5 --- .travis.yml | 6 +-- README.md | 2 +- lib/poxa.ex | 2 +- lib/poxa/adapter/gproc.ex | 8 ++-- lib/poxa/channels_handler.ex | 4 +- lib/poxa/console/console.ex | 4 +- lib/poxa/console/ws_handler.ex | 4 +- lib/poxa/event_handler.ex | 8 ++-- lib/poxa/presence_subscription.ex | 22 +++++----- lib/poxa/pusher_event.ex | 6 +-- lib/poxa/registry.ex | 2 +- lib/poxa/socket_id.ex | 2 +- lib/poxa/subscription.ex | 12 +++--- lib/poxa/users_handler.ex | 2 +- lib/poxa/web_hook/dispatcher.ex | 2 +- lib/poxa/web_hook/event_table.ex | 4 +- lib/poxa/websocket_handler.ex | 12 +++--- mix.exs | 22 +++++----- mix.lock | 40 +++++++----------- test/auth_signature_test.exs | 2 +- test/authentication_test.exs | 2 +- test/authorization_helper_test.exs | 2 +- test/channel_test.exs | 16 +++---- test/channels_handler_test.exs | 24 +++++------ test/console/console_test.exs | 26 ++++++------ test/console/console_ws_handler_test.exs | 4 +- test/event_handler_test.exs | 14 +++--- test/event_test.exs | 8 ++-- test/integration/connection_test.exs | 2 +- test/integration/public_channel_test.exs | 2 +- test/poxa/adapter/gproc_test.exs | 22 +++++----- test/presence_channel_test.exs | 2 +- test/presence_subscription_test.exs | 8 ++-- test/pusher_event_test.exs | 38 ++++++++--------- test/socket_id_test.exs | 2 +- test/subscription_handler_test.exs | 4 +- test/subscription_test.exs | 2 +- test/test_helper.exs | 2 +- test/users_handler_test.exs | 8 ++-- test/web_hook/dispatcher_test.exs | 6 +-- test/web_hook/event_table_test.exs | 20 ++++----- test/web_hook/handler_test.exs | 2 +- test/websocket_handler_test.exs | 54 ++++++++++++------------ 43 files changed, 212 insertions(+), 224 deletions(-) diff --git a/.travis.yml b/.travis.yml index dab4b71..ec6d697 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: elixir otp_release: - - 18.3 - - 19.0 + - 20.0 elixir: - - 1.2.6 - - 1.3.0 + - 1.5.1 sudo: false env: - MIX_ENV=test diff --git a/README.md b/README.md index 00dde7d..cf1f1f5 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ How do I speak 'poxa'? Poxa is a standalone elixir server implementation of the Pusher protocol. -You need [Elixir](http://elixir-lang.org) 1.2.6 at least and Erlang 18.0 +You need [Elixir](http://elixir-lang.org) 1.5 at least and Erlang 20.0 Clone this repository diff --git a/lib/poxa.ex b/lib/poxa.ex index b3644fc..c825429 100644 --- a/lib/poxa.ex +++ b/lib/poxa.ex @@ -21,7 +21,7 @@ defmodule Poxa do { '/apps/:app_id/channels/:channel_name/users', Poxa.UsersHandler, [] }, { '/app/:app_key', Poxa.WebsocketHandler, [] } ] } ]) - case load_config do + case load_config() do {:ok, config} -> Logger.info "Starting Poxa using app_key: #{config.app_key}, app_id: #{config.app_id}, app_secret: #{config.app_secret} on port #{config.port}" {:ok, _} = :cowboy.start_http(:poxa, 100, diff --git a/lib/poxa/adapter/gproc.ex b/lib/poxa/adapter/gproc.ex index ee657ab..0a76190 100644 --- a/lib/poxa/adapter/gproc.ex +++ b/lib/poxa/adapter/gproc.ex @@ -49,18 +49,18 @@ defmodule Poxa.Adapter.GProc do def channels(pid \\ :_) do Ex2ms.fun do {{:p, :l, {:pusher, channel}}, ^pid, _} -> channel - end |> select |> Enum.uniq + end |> select |> Enum.uniq_by(&(&1)) end def unique_subscriptions(channel) do - for {_pid, {user_id, user_info}} <- lookup_values({:p, :l, {:pusher, channel}}) do + for {_pid, {user_id, user_info}} <- lookup_values({:p, :l, {:pusher, channel}}), into: %{} do {user_id, user_info} - end |> Enum.uniq(fn {user_id, _} -> user_id end) + end end def fetch(key) do get_value({:p, :l, {:pusher, key}}) end - def clean_up, do: goodbye + def clean_up, do: goodbye() end diff --git a/lib/poxa/channels_handler.ex b/lib/poxa/channels_handler.ex index 2212a2d..45aba37 100644 --- a/lib/poxa/channels_handler.ex +++ b/lib/poxa/channels_handler.ex @@ -81,7 +81,7 @@ defmodule Poxa.ChannelsHandler do defp show(channel, attributes, req, state) do occupied = Channel.occupied?(channel) attribute_list = mount_attribute_list(attributes, channel) - {JSX.encode!([occupied: occupied] ++ attribute_list), req, state} + {Poison.encode!([occupied: occupied] ++ attribute_list), req, state} end defp mount_attribute_list(attributes, channel) do @@ -101,7 +101,7 @@ defmodule Poxa.ChannelsHandler do defp index(filter, attributes, req, state) do channels = channels(filter, attributes) - {JSX.encode!(channels: channels), req, state} + {Poison.encode!(channels: channels), req, state} end defp channels(filter, attributes) do diff --git a/lib/poxa/console/console.ex b/lib/poxa/console/console.ex index 179fe3b..6afd841 100644 --- a/lib/poxa/console/console.ex +++ b/lib/poxa/console/console.ex @@ -1,5 +1,5 @@ defmodule Poxa.Console do - import JSX, only: [encode!: 1] + import Poison, only: [encode!: 1] use GenEvent @doc false @@ -62,7 +62,7 @@ defmodule Poxa.Console do end defp message(type, socket_id, details) do - %{ type: type, socket: socket_id, details: details, time: time } + %{ type: type, socket: socket_id, details: details, time: time() } end defp time do diff --git a/lib/poxa/console/ws_handler.ex b/lib/poxa/console/ws_handler.ex index fbab025..f68db7a 100644 --- a/lib/poxa/console/ws_handler.ex +++ b/lib/poxa/console/ws_handler.ex @@ -13,7 +13,7 @@ defmodule Poxa.Console.WSHandler do {qs_vals, req} = :cowboy_req.qs_vals(req) if Authentication.check(method, path, "", qs_vals) do - :ok = Poxa.Event.add_handler({Poxa.Console, self}, self) + :ok = Poxa.Event.add_handler({Poxa.Console, self()}, self()) {:ok, req, nil} else Logger.error "Failed to authenticate on Console Websocket" @@ -31,7 +31,7 @@ defmodule Poxa.Console.WSHandler do @doc false def websocket_terminate(_reason, _req, _state) do - Poxa.Event.remove_handler({Poxa.Console, self}, self) + Poxa.Event.remove_handler({Poxa.Console, self()}, self()) :ok end end diff --git a/lib/poxa/event_handler.ex b/lib/poxa/event_handler.ex index c5b99a1..9ed943a 100644 --- a/lib/poxa/event_handler.ex +++ b/lib/poxa/event_handler.ex @@ -16,7 +16,7 @@ defmodule Poxa.EventHandler do def allowed_methods(req, state), do: {["POST"], req, state} - @invalid_event_json JSX.encode!(%{error: "Event must have channel(s), name, and data"}) + @invalid_event_json Poison.encode!(%{error: "Event must have channel(s), name, and data"}) @doc """ If the body is not JSON or not a valid PusherEvent this function will @@ -24,7 +24,7 @@ defmodule Poxa.EventHandler do """ def malformed_request(req, state) do {:ok, body, req} = :cowboy_req.body(req) - case JSX.decode(body) do + case Poison.decode(body) do {:ok, data} -> case PusherEvent.build(data) do {:ok, event} -> {false, req, %{body: body, event: event}} @@ -38,7 +38,7 @@ defmodule Poxa.EventHandler do end end - @authentication_error_json JSX.encode!(%{error: "Authentication error"}) + @authentication_error_json Poison.encode!(%{error: "Authentication error"}) @doc """ More info http://pusher.com/docs/rest_api#authentication @@ -56,7 +56,7 @@ defmodule Poxa.EventHandler do {authorized, req, state} end - @invalid_data_size_json JSX.encode!(%{error: "Data key must be smaller than 10KB"}) + @invalid_data_size_json Poison.encode!(%{error: "Data key must be smaller than 10KB"}) @doc """ The event data can't be greater than 10KB diff --git a/lib/poxa/presence_subscription.ex b/lib/poxa/presence_subscription.ex index e47b7cf..6a663fc 100644 --- a/lib/poxa/presence_subscription.ex +++ b/lib/poxa/presence_subscription.ex @@ -10,9 +10,9 @@ defmodule Poxa.PresenceSubscription do More info at: http://pusher.com/docs/client_api_guide/client_presence_channels """ @type user_id :: integer | binary - @type user_info :: :jsx.json_term + @type user_info :: term defstruct [:channel, :channel_data] - @type t :: %__MODULE__{channel: binary, channel_data: [{user_id, user_info}]} + @type t :: %__MODULE__{channel: binary, channel_data: %{user_id => user_info}} alias Poxa.PusherEvent alias Poxa.Event @@ -22,18 +22,18 @@ defmodule Poxa.PresenceSubscription do @doc """ Returns a PresenceSubscription struct """ - @spec subscribe!(binary, :jsx.json_term) :: __MODULE__.t + @spec subscribe!(binary, term) :: __MODULE__.t def subscribe!(channel, channel_data) do - decoded_channel_data = JSX.decode!(channel_data) - if member?(channel, self) do - Logger.info "Already subscribed #{inspect self} on channel #{channel}" + decoded_channel_data = Poison.decode!(channel_data) + if member?(channel, self()) do + Logger.info "Already subscribed #{inspect self()} on channel #{channel}" else - Logger.info "Registering #{inspect self} to channel #{channel}" + Logger.info "Registering #{inspect self()} to channel #{channel}" {user_id, user_info} = extract_userid_and_userinfo(decoded_channel_data) unless Poxa.Channel.member?(channel, user_id) do Event.notify(:member_added, %{channel: channel, user_id: user_id}) message = PusherEvent.presence_member_added(channel, user_id, user_info) - Poxa.registry.send!(message, channel, self) + Poxa.registry.send!(message, channel, self()) end Poxa.registry.register!(channel, {user_id, user_info}) end @@ -48,7 +48,7 @@ defmodule Poxa.PresenceSubscription do end defp sanitize_user_id(user_id) when is_binary(user_id), do: user_id - defp sanitize_user_id(user_id), do: JSX.encode!(user_id) + defp sanitize_user_id(user_id), do: Poison.encode!(user_id) @doc """ Unsubscribe from a presence channel, possibly triggering `presence_member_removed`. @@ -74,7 +74,7 @@ defmodule Poxa.PresenceSubscription do """ @spec check_and_remove :: non_neg_integer def check_and_remove do - for [channel, user_id] <- Poxa.registry.subscriptions(self), + for [channel, user_id] <- Poxa.registry.subscriptions(self()), presence?(channel), only_one_connection_on_user_id?(channel, user_id) do presence_member_removed(channel, user_id) end |> Enum.count @@ -83,7 +83,7 @@ defmodule Poxa.PresenceSubscription do defp presence_member_removed(channel, user_id) do Event.notify(:member_removed, %{channel: channel, user_id: user_id}) message = PusherEvent.presence_member_removed(channel, user_id) - Poxa.registry.send!(message, channel, self) + Poxa.registry.send!(message, channel, self()) end defp only_one_connection_on_user_id?(channel, user_id) do diff --git a/lib/poxa/pusher_event.ex b/lib/poxa/pusher_event.ex index 8368ae6..c51eb5c 100644 --- a/lib/poxa/pusher_event.ex +++ b/lib/poxa/pusher_event.ex @@ -6,7 +6,7 @@ defmodule Poxa.PusherEvent do """ alias Poxa.PresenceSubscription - import JSX, only: [encode!: 1] + import Poison, only: [encode!: 1] @doc """ Return a JSON for an established connection using the `socket_id` parameter to @@ -63,7 +63,7 @@ defmodule Poxa.PusherEvent do end def subscription_succeeded(%PresenceSubscription{channel: channel, channel_data: channel_data}) do - {ids, _Hash} = :lists.unzip(channel_data) + ids = Map.keys(channel_data) count = Enum.count(ids) data = %{presence: %{ids: ids, hash: channel_data, count: count}} |> encode! %{event: "pusher_internal:subscription_succeeded", @@ -192,7 +192,7 @@ defmodule Poxa.PusherEvent do defp publish_event_to_channel(event, channel) do message = build_message(event, channel) |> encode! - Poxa.registry.send!(message, channel, self, event.socket_id) + Poxa.registry.send!(message, channel, self(), event.socket_id) end defp build_message(event, channel) do diff --git a/lib/poxa/registry.ex b/lib/poxa/registry.ex index 7caf342..931d80a 100644 --- a/lib/poxa/registry.ex +++ b/lib/poxa/registry.ex @@ -46,7 +46,7 @@ defmodule Poxa.Registry do @doc """ Returns the unique subscriptions of the given channel. """ - @callback unique_subscriptions(binary) :: list(tuple()) + @callback unique_subscriptions(binary) :: Map.t @doc """ Returns the value assigned with the given property. diff --git a/lib/poxa/socket_id.ex b/lib/poxa/socket_id.ex index 9ff53f9..4ace4c1 100644 --- a/lib/poxa/socket_id.ex +++ b/lib/poxa/socket_id.ex @@ -4,7 +4,7 @@ defmodule Poxa.SocketId do """ @spec generate! :: binary def generate! do - <> = :crypto.rand_bytes(8) + <> = :crypto.strong_rand_bytes(8) "#{part1}.#{part2}" end diff --git a/lib/poxa/subscription.ex b/lib/poxa/subscription.ex index 4541652..e6d3cda 100644 --- a/lib/poxa/subscription.ex +++ b/lib/poxa/subscription.ex @@ -14,7 +14,7 @@ defmodule Poxa.Subscription do Returns {:ok, channel} to public and private channels and a PresenceSubscription to a presence channel """ - @spec subscribe!(:jsx.json_term, binary) :: {:ok, binary} + @spec subscribe!(term, binary) :: {:ok, binary} | PresenceSubscription.t | {:error, binary} def subscribe!(data, socket_id) do @@ -60,10 +60,10 @@ defmodule Poxa.Subscription do defp subscribe_channel(channel) do Logger.info "Subscribing to channel #{channel}" - if Channel.member?(channel, self) do - Logger.info "Already subscribed #{inspect self} on channel #{channel}" + if Channel.member?(channel, self()) do + Logger.info "Already subscribed #{inspect self()} on channel #{channel}" else - Logger.info "Registering #{inspect self} to channel #{channel}" + Logger.info "Registering #{inspect self()} to channel #{channel}" Poxa.registry.register!(channel) end {:ok, channel} @@ -72,10 +72,10 @@ defmodule Poxa.Subscription do @doc """ Unsubscribe from a channel always returning :ok """ - @spec unsubscribe!(:jsx.json_term) :: {:ok, binary} + @spec unsubscribe!(term) :: {:ok, binary} def unsubscribe!(data) do channel = data["channel"] - if Channel.member?(channel, self) do + if Channel.member?(channel, self()) do if Channel.presence?(channel) do PresenceSubscription.unsubscribe!(channel); end diff --git a/lib/poxa/users_handler.ex b/lib/poxa/users_handler.ex index 12d6cc0..274589e 100644 --- a/lib/poxa/users_handler.ex +++ b/lib/poxa/users_handler.ex @@ -50,7 +50,7 @@ defmodule Poxa.UsersHandler do """ def get_json(req, channel) do response = PresenceChannel.users(channel) |> Enum.map(fn(id) -> [id: id] end) - {JSX.encode!(users: response), req, nil} + {Poison.encode!(users: response), req, nil} end end diff --git a/lib/poxa/web_hook/dispatcher.ex b/lib/poxa/web_hook/dispatcher.ex index c20bdf5..c1b88ba 100644 --- a/lib/poxa/web_hook/dispatcher.ex +++ b/lib/poxa/web_hook/dispatcher.ex @@ -38,7 +38,7 @@ defmodule Poxa.WebHook.Dispatcher do defp send_web_hook!(events) do Logger.debug "Sending webhook request." - body = JSX.encode! %{time_ms: time_ms, events: events} + body = Poison.encode! %{time_ms: time_ms(), events: events} {:ok, url} = Application.fetch_env(:poxa, :web_hook) case HTTPoison.post(url, body, pusher_headers(body)) do {:ok, _} -> :ok diff --git a/lib/poxa/web_hook/event_table.ex b/lib/poxa/web_hook/event_table.ex index 008e9e8..89691b4 100644 --- a/lib/poxa/web_hook/event_table.ex +++ b/lib/poxa/web_hook/event_table.ex @@ -31,7 +31,7 @@ defmodule Poxa.WebHook.EventTable do def insert(events, delay) do Enum.filter events, fn(event) -> if delete_corresponding(event) == 0 do - :ets.insert(@table_name, {time_ms + delay, event}) + :ets.insert(@table_name, {time_ms() + delay, event}) end end end @@ -45,7 +45,7 @@ defmodule Poxa.WebHook.EventTable do This function returns all events in the ETS table that are ready to be sent for a given `timestamp`. """ - def ready(timestamp \\ time_ms + 1), do: {timestamp, filter_events [{:<, :"$1", timestamp}]} + def ready(timestamp \\ time_ms() + 1), do: {timestamp, filter_events [{:<, :"$1", timestamp}]} defp filter_events(filter) do select(@table_name, [{{:"$1", :"$2"}, filter, [:"$2"]}]) diff --git a/lib/poxa/websocket_handler.ex b/lib/poxa/websocket_handler.ex index 826724f..7cc434a 100644 --- a/lib/poxa/websocket_handler.ex +++ b/lib/poxa/websocket_handler.ex @@ -36,16 +36,16 @@ defmodule Poxa.WebsocketHandler do case :application.get_env(:poxa, :app_key) do {:ok, ^app_key} -> if supported_protocol?(protocol) do - send self, :start + send self(), :start {:ok, req, nil} else Logger.error "Protocol #{protocol} not supported" - send self, :start_error + send self(), :start_error {:ok, req, {4007, "Unsupported protocol version"}} end {:ok, expected_app_key} -> Logger.error "Invalid app_key, expected #{expected_app_key}, found #{app_key}" - send self, :start_error + send self(), :start_error {:ok, req, {4001, "Application does not exist"}} end end @@ -70,7 +70,7 @@ defmodule Poxa.WebsocketHandler do More info: http://pusher.com/docs/pusher_protocol """ def websocket_handle({:text, json}, req, state) do - JSX.decode!(json) |> handle_pusher_event(req, state) + Poison.decode!(json) |> handle_pusher_event(req, state) end def websocket_handle({:ping, _}, req, state), do: { :ok, req, state } @@ -104,7 +104,7 @@ defmodule Poxa.WebsocketHandler do defp handle_pusher_event("client-" <> _event_name, decoded_json, req, %State{socket_id: socket_id} = state) do {:ok, event} = PusherEvent.build_client_event(decoded_json, socket_id) channel = List.first(event.channels) - if Channel.private_or_presence?(channel) and Channel.member?(channel, self) do + if Channel.private_or_presence?(channel) and Channel.member?(channel, self()) do PusherEvent.publish(event) Event.notify(:client_event_message, %{socket_id: socket_id, channels: event.channels, name: event.name, data: event.data}) end @@ -160,7 +160,7 @@ defmodule Poxa.WebsocketHandler do def websocket_terminate(_reason, _req, nil), do: :ok def websocket_terminate(_reason, _req, %State{socket_id: socket_id, time: time}) do duration = Time.stamp - time - channels = Channel.all(self) + channels = Channel.all(self()) PresenceSubscription.check_and_remove Poxa.registry.clean_up Event.notify(:disconnected, %{socket_id: socket_id, channels: channels, duration: duration}) diff --git a/mix.exs b/mix.exs index a626205..0be88b8 100644 --- a/mix.exs +++ b/mix.exs @@ -3,12 +3,12 @@ defmodule Poxa.Mixfile do def project do [ app: :poxa, - version: "0.6.0", + version: "0.7.0", name: "Poxa", - elixir: "~> 1.2", - deps: deps, + elixir: "~> 1.5", + deps: deps(), dialyzer: [ - plt_add_apps: ~w(cowboy exjsx gproc httpoison signaturex), + plt_add_apps: ~w(cowboy poison gproc httpoison signaturex), plt_file: ".local.plt", flags: ~w(-Wunmatched_returns -Werror_handling -Wrace_conditions -Wno_opaque --fullpath --statistics) ] @@ -17,25 +17,23 @@ defmodule Poxa.Mixfile do def application do [ applications: [ :logger, :crypto, :gproc, :cowboy, :asn1, :public_key, - :ssl, :exjsx, :signaturex, :httpoison, :watcher, :ex2ms ], + :ssl, :poison, :signaturex, :httpoison, :watcher, :ex2ms ], mod: { Poxa, [] } ] end defp deps do [ {:cowboy, "~> 1.1.2" }, - {:exjsx, "~> 3.0"}, - {:signaturex, "~> 1.0"}, + {:poison, "~> 3.0"}, + {:signaturex, "~> 1.3"}, {:gproc, "~> 0.3.0"}, {:meck, "~> 0.8.2", only: :test}, {:pusher_client, github: "edgurgel/pusher_client", only: :test}, {:pusher, "~> 0.1", only: :test}, - {:exrm, "~> 1.0.0"}, - {:conform, "~> 2.0.0"}, - {:conform_exrm, "~> 1.0"}, - {:inch_ex, "~> 0.5.1", only: :docs}, + {:distillery, "~> 1.4", runtime: false}, + {:conform, "~> 2.0"}, {:httpoison, "~> 0.9"}, {:ex2ms, "~> 1.4.0"}, - {:watcher, "~> 1.0.0"}, + {:watcher, "~> 1.1.0"}, {:dialyxir, "~> 0.3", only: [:dev, :test]}] end end diff --git a/mix.lock b/mix.lock index 1326e6d..9345bee 100644 --- a/mix.lock +++ b/mix.lock @@ -1,34 +1,26 @@ -%{"bbmustache": {:hex, :bbmustache, "1.0.4", "7ba94f971c5afd7b6617918a4bb74705e36cab36eb84b19b6a1b7ee06427aa38", [:rebar], [], "hexpm"}, - "certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [], [], "hexpm"}, - "cf": {:hex, :cf, "0.2.1", "69d0b1349fd4d7d4dc55b7f407d29d7a840bf9a1ef5af529f1ebe0ce153fc2ab", [:rebar3], [], "hexpm"}, - "conform": {:hex, :conform, "2.0.0", "581ba82cc38a76104562b881dc76f92f4859ea13fa2028c3e6d10d6099b33fb7", [:mix], [{:neotoma, "~> 1.7.3", [hex: :neotoma, repo: "hexpm", optional: false]}], "hexpm"}, - "conform_exrm": {:hex, :conform_exrm, "1.0.0", "68d5923a74dad4169b51454d723d08ca1644b6a6deaf64eccd509fd084cd1343", [:mix], [{:conform, "> 0.0.0", [hex: :conform, repo: "hexpm", optional: false]}, {:exrm, "> 0.0.0", [hex: :exrm, repo: "hexpm", optional: false]}], "hexpm"}, +%{"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"}, + "conform": {:hex, :conform, "2.5.2", "7035787a9c09d28607745444e7a1700426dc47c452634a5694033fa2fbb3414c", [:mix], [{:neotoma, "~> 1.7.3", [hex: :neotoma, repo: "hexpm", optional: false]}], "hexpm"}, "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"}, "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"}, - "dialyxir": {:hex, :dialyxir, "0.3.3", "2f8bb8ab4e17acf4086cae847bd385c0f89296d3e3448dc304c26bfbe4b46cb4", [:mix], [], "hexpm"}, - "erlware_commons": {:hex, :erlware_commons, "0.21.0", "a04433071ad7d112edefc75ac77719dd3e6753e697ac09428fc83d7564b80b15", [], [{:cf, "0.2.1", [hex: :cf, repo: "hexpm", optional: false]}], "hexpm"}, + "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, + "distillery": {:hex, :distillery, "1.5.2", "eec18b2d37b55b0bcb670cf2bcf64228ed38ce8b046bb30a9b636a6f5a4c0080", [:mix], [], "hexpm"}, "ex2ms": {:hex, :ex2ms, "1.4.0", "e43b410888b45ba363ea6650db3736db3e455a0a412ec244ac633fede857bcb2", [:mix], [], "hexpm"}, - "exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, - "exrm": {:hex, :exrm, "1.0.6", "f708fc091dcacb93c1da58254a1ab34166d5ac3dca162877e878fe5d7a9e9dce", [], [{:relx, "~> 3.5", [hex: :relx, repo: "hexpm", optional: false]}], "hexpm"}, - "getopt": {:hex, :getopt, "0.8.2", "b17556db683000ba50370b16c0619df1337e7af7ecbf7d64fbf8d1d6bce3109b", [:rebar], [], "hexpm"}, + "exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, "gproc": {:hex, :gproc, "0.3.1", "ec14f40cb941bde3f940de59c11e59beb2977e90dbae72fab3ddf77743fd4ea9", [:rebar], [], "hexpm"}, - "hackney": {:hex, :hackney, "1.6.0", "8d1e9440c9edf23bf5e5e2fe0c71de03eb265103b72901337394c840eec679ac", [], [{:certifi, "0.4.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "1.2.0", [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.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "httpoison": {:hex, :httpoison, "0.9.0", "68187a2daddfabbe7ca8f7d75ef227f89f0e1507f7eecb67e4536b3c516faddb", [], [{:hackney, "~> 1.6.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, - "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [], [], "hexpm"}, - "inch_ex": {:hex, :inch_ex, "0.5.3", "39f11e96181ab7edc9c508a836b33b5d9a8ec0859f56886852db3d5708889ae7", [], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, - "jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], [], "hexpm"}, - "meck": {:hex, :meck, "0.8.4", "59ca1cd971372aa223138efcf9b29475bde299e1953046a0c727184790ab1520", [], [], "hexpm"}, + "hackney": {:hex, :hackney, "1.9.0", "51c506afc0a365868469dcfc79a9d0b94d896ec741cfd5bd338f49a5ec515bfe", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [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, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, + "idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, + "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], [], "hexpm"}, + "meck": {:hex, :meck, "0.8.8", "eeb3efe811d4346e1a7f65b2738abc2ad73cbe1a2c91b5dd909bac2ea0414fa6", [:rebar3], [], "hexpm"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, "neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], [], "hexpm"}, - "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [], [], "hexpm"}, - "providers": {:hex, :providers, "1.6.0", "db0e2f9043ae60c0155205fcd238d68516331d0e5146155e33d1e79dc452964a", [:rebar3], [{:getopt, "0.8.2", [hex: :getopt, repo: "hexpm", optional: false]}], "hexpm"}, + "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, "pusher": {:hex, :pusher, "0.1.3", "d3ed4c9c4f1dcb44791c24d5a964e41f9ae222fa9164a1d6fffdf62eb9685253", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:httpoison, "~> 0.8", [hex: :httpoison, repo: "hexpm", optional: false]}, {:signaturex, "~> 1.0", [hex: :signaturex, repo: "hexpm", optional: false]}], "hexpm"}, "pusher_client": {:git, "https://github.com/edgurgel/pusher_client.git", "2edb22a7b45b2fe962b12d6ee5460f7d722aadd7", []}, "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"}, - "relx": {:hex, :relx, "3.20.0", "b515b8317d25b3a1508699294c3d1fa6dc0527851dffc87446661bce21a36710", [], [{:bbmustache, "1.0.4", [hex: :bbmustache, repo: "hexpm", optional: false]}, {:cf, "0.2.1", [hex: :cf, repo: "hexpm", optional: false]}, {:erlware_commons, "0.21.0", [hex: :erlware_commons, repo: "hexpm", optional: false]}, {:getopt, "0.8.2", [hex: :getopt, repo: "hexpm", optional: false]}, {:providers, "1.6.0", [hex: :providers, repo: "hexpm", optional: false]}], "hexpm"}, - "signaturex": {:hex, :signaturex, "1.1.0", "ad274d5e6ec2670ff61a7b296c3b993550172777bc3c6076f3fb956da11ce32a", [], [], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [], [], "hexpm"}, - "ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5", "2e73e068cd6393526f9fa6d399353d7c9477d6886ba005f323b592d389fb47be", [:make], []}, - "watcher": {:hex, :watcher, "1.0.0", "0d9a43d0f1f3997b75775fc873dfb29437b8e3c5fb6bdcb8feaa5eedc7ee9cf6", [:mix], [], "hexpm"}, - "websocket_client": {:git, "https://github.com/jeremyong/websocket_client.git", "2b8d9805306d36f22330f432ae6472f1f2625c30", []}} + "signaturex": {:hex, :signaturex, "1.3.0", "47b7431990f3b38540803de013cc809e8dad248dade0aad01ef2c5661c02c7a3", [:mix], [], "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"}, + "watcher": {:hex, :watcher, "1.1.0", "69408dc4f45fc88268d4a3544691bcbc1c767bf84da83aeba69be020ea7d03f9", [:mix], [], "hexpm"}, + "websocket_client": {:git, "https://github.com/jeremyong/websocket_client.git", "9a6f65d05ebf2725d62fb19262b21f1805a59fbf", []}} diff --git a/test/auth_signature_test.exs b/test/auth_signature_test.exs index 507495d..a5a5869 100644 --- a/test/auth_signature_test.exs +++ b/test/auth_signature_test.exs @@ -6,7 +6,7 @@ defmodule Poxa.AuthSignatureTest do setup do new Authentication - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/authentication_test.exs b/test/authentication_test.exs index 93170fe..7b58bc5 100644 --- a/test/authentication_test.exs +++ b/test/authentication_test.exs @@ -6,7 +6,7 @@ defmodule Poxa.AuthenticationTest do setup do new Application new Signaturex - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/authorization_helper_test.exs b/test/authorization_helper_test.exs index ebff0ef..30b1f53 100644 --- a/test/authorization_helper_test.exs +++ b/test/authorization_helper_test.exs @@ -7,7 +7,7 @@ defmodule Poxa.AuthorizarionHelperTest do setup do new Authentication new :cowboy_req - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/channel_test.exs b/test/channel_test.exs index 4c2ef84..7eed2a5 100644 --- a/test/channel_test.exs +++ b/test/channel_test.exs @@ -6,7 +6,7 @@ defmodule Poxa.ChannelTest do setup do new Poxa.registry - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -30,32 +30,32 @@ defmodule Poxa.ChannelTest do channels = ~w(channel1 channel2 channel3) expect(Poxa.registry, :channels, [:_], ~w(channel1 channel2 channel3)) - assert all == channels + assert all() == channels assert validate Poxa.registry end test "list channels of a pid" do channels = ~w(channel1 channel2 channel3) - expect(Poxa.registry, :channels, [self], ~w(channel1 channel2 channel3)) + expect(Poxa.registry, :channels, [self()], ~w(channel1 channel2 channel3)) - assert all(self) == channels + assert all(self()) == channels assert validate Poxa.registry end test "channel is member? returning true" do - expect(Poxa.registry, :subscription_count, ["channel", self], 1) + expect(Poxa.registry, :subscription_count, ["channel", self()], 1) - assert member?("channel", self) + assert member?("channel", self()) assert validate Poxa.registry end test "channel is subscribed returning false" do - expect(Poxa.registry, :subscription_count, ["channel", self], 0) + expect(Poxa.registry, :subscription_count, ["channel", self()], 0) - refute member?("channel", self) + refute member?("channel", self()) assert validate Poxa.registry end diff --git a/test/channels_handler_test.exs b/test/channels_handler_test.exs index c3f0434..b7ea727 100644 --- a/test/channels_handler_test.exs +++ b/test/channels_handler_test.exs @@ -6,9 +6,9 @@ defmodule Poxa.ChannelsHandlerTest do import Poxa.ChannelsHandler setup do - new JSX + new Poison new :cowboy_req - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -106,11 +106,11 @@ defmodule Poxa.ChannelsHandlerTest do expect(Channel, :occupied?, 1, true) expect(Channel, :subscription_count, 1, 5) expected = [occupied: true, subscription_count: 5] - expect(JSX, :encode!, [{[expected], :encoded_json}]) + expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, {:one, :channel, ["subscription_count"]}) == {:encoded_json, :req, nil} - assert validate JSX + assert validate Poison assert validate Channel end @@ -118,11 +118,11 @@ defmodule Poxa.ChannelsHandlerTest do expect(Channel, :occupied?, 1, true) expect(PresenceChannel, :user_count, 1, 3) expected = [occupied: true, user_count: 3] - expect(JSX, :encode!, [{[expected], :encoded_json}]) + expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, {:one, :channel, ["user_count"]}) == {:encoded_json, :req, nil} - assert validate JSX + assert validate Poison assert validate Channel assert validate PresenceChannel end @@ -132,11 +132,11 @@ defmodule Poxa.ChannelsHandlerTest do expect(Channel, :subscription_count, 1, 5) expect(PresenceChannel, :user_count, 1, 3) expected = [occupied: true, subscription_count: 5, user_count: 3] - expect(JSX, :encode!, [{[expected], :encoded_json}]) + expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, {:one, :channel, ["subscription_count", "user_count"]}) == {:encoded_json, :req, nil} - assert validate JSX + assert validate Poison assert validate Channel assert validate PresenceChannel end @@ -147,11 +147,11 @@ defmodule Poxa.ChannelsHandlerTest do expect(Channel, :presence?, 1, true) expect(PresenceChannel, :user_count, 1, 3) expected = [channels: [{"presence-channel", user_count: 3}]] - expect(JSX, :encode!, [{[expected], :encoded_json}]) + expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, {:all, nil, ["user_count"]}) == {:encoded_json, :req, nil} - assert validate JSX + assert validate Poison assert validate Channel assert validate PresenceChannel end @@ -160,11 +160,11 @@ defmodule Poxa.ChannelsHandlerTest do expect(Channel, :all, 0, ["presence-channel", "poxa-channel"]) expect(Channel, :matches?, 2, seq([false, true])) expected = [channels: [{"poxa-channel", []}]] - expect(JSX, :encode!, [{[expected], :encoded_json}]) + expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, {:all, 'poxa-', []}) == {:encoded_json, :req, nil} - assert validate JSX + assert validate Poison assert validate Channel end end diff --git a/test/console/console_test.exs b/test/console/console_test.exs index 00ebffa..8a6b21a 100644 --- a/test/console/console_test.exs +++ b/test/console/console_test.exs @@ -4,69 +4,69 @@ defmodule Poxa.ConsoleTest do import Poxa.Console setup_all do - new JSX - expect(JSX, :encode!, &(&1)) - on_exit fn -> unload end + new Poison + expect(Poison, :encode!, &(&1)) + on_exit fn -> unload() end :ok end test "connected" do - handle_event(%{event: :connected, socket_id: "socket_id", origin: "origin"}, self) + handle_event(%{event: :connected, socket_id: "socket_id", origin: "origin"}, self()) assert_received %{details: "Origin: origin", socket: "socket_id", time: _, type: "Connection"} end test "disconnected" do - handle_event(%{event: :disconnected, socket_id: "socket_id", channels: ["channel1"], duration: 123}, self) + handle_event(%{event: :disconnected, socket_id: "socket_id", channels: ["channel1"], duration: 123}, self()) assert_received %{details: "Channels: [\"channel1\"], Lifetime: 123s", socket: "socket_id", time: _, type: "Disconnection"} end test "subscribed" do - handle_event(%{event: :subscribed, socket_id: "socket_id", channel: "channel"}, self) + handle_event(%{event: :subscribed, socket_id: "socket_id", channel: "channel"}, self()) assert_received %{details: "Channel: channel", socket: "socket_id", time: _, type: "Subscribed"} end test "unsubscribed" do - handle_event(%{event: :unsubscribed, socket_id: "socket_id", channel: "channel"}, self) + handle_event(%{event: :unsubscribed, socket_id: "socket_id", channel: "channel"}, self()) assert_received %{details: "Channel: channel", socket: "socket_id", time: _, type: "Unsubscribed"} end test "api_message" do - handle_event(%{event: :api_message, channels: ["channel"], name: "event_message"}, self) + handle_event(%{event: :api_message, channels: ["channel"], name: "event_message"}, self()) assert_received %{details: "Channels: [\"channel\"], Event: event_message", socket: "", time: _, type: "API Message"} end test "client_event_message" do - handle_event(%{event: :client_event_message, socket_id: "socket_id", channels: ["channel"], name: "event_message"}, self) + handle_event(%{event: :client_event_message, socket_id: "socket_id", channels: ["channel"], name: "event_message"}, self()) assert_received %{details: "Channels: [\"channel\"], Event: event_message", socket: "socket_id", time: _, type: "Client Event Message"} end test "member_added" do - handle_event(%{event: :member_added, socket_id: "socket_id", channel: "presence-channel", user_id: "user_id"}, self) + handle_event(%{event: :member_added, socket_id: "socket_id", channel: "presence-channel", user_id: "user_id"}, self()) assert_received %{details: "Channel: \"presence-channel\", UserId: \"user_id\"", socket: "socket_id", time: _, type: "Member added"} end test "member_removed" do - handle_event(%{event: :member_removed, socket_id: "socket_id", channel: "presence-channel", user_id: "user_id"}, self) + handle_event(%{event: :member_removed, socket_id: "socket_id", channel: "presence-channel", user_id: "user_id"}, self()) assert_received %{details: "Channel: \"presence-channel\", UserId: \"user_id\"", socket: "socket_id", time: _, type: "Member removed"} end test "channel_occupied" do - handle_event(%{event: :channel_occupied, channel: "channel", socket_id: "socket_id"}, self) + handle_event(%{event: :channel_occupied, channel: "channel", socket_id: "socket_id"}, self()) assert_received %{details: "Channel: \"channel\"", socket: "socket_id", time: _, type: "Channel occupied"} end test "channel_vacated" do - handle_event(%{event: :channel_vacated, channel: "channel", socket_id: "socket_id"}, self) + handle_event(%{event: :channel_vacated, channel: "channel", socket_id: "socket_id"}, self()) assert_received %{details: "Channel: \"channel\"", socket: "socket_id", time: _, type: "Channel vacated"} end diff --git a/test/console/console_ws_handler_test.exs b/test/console/console_ws_handler_test.exs index 0cd8909..9c23258 100644 --- a/test/console/console_ws_handler_test.exs +++ b/test/console/console_ws_handler_test.exs @@ -9,7 +9,7 @@ defmodule Poxa.Console.WSHandlerTest do new Authentication new :cowboy_req new Event - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -18,7 +18,7 @@ defmodule Poxa.Console.WSHandlerTest do expect(:cowboy_req, :path, 1, {:path, :req3}) expect(:cowboy_req, :qs_vals, 1, {:qs_vals, :req4}) expect(Authentication, :check, [{[:method, :path, "", :qs_vals], true}]) - expect(Event, :add_handler, [{[{Poxa.Console, self}, self], :ok}]) + expect(Event, :add_handler, [{[{Poxa.Console, self()}, self()], :ok}]) assert websocket_init(:tranport, :req, []) == {:ok, :req4, nil} diff --git a/test/event_handler_test.exs b/test/event_handler_test.exs index 68717e5..e37c905 100644 --- a/test/event_handler_test.exs +++ b/test/event_handler_test.exs @@ -7,43 +7,43 @@ defmodule Poxa.EventHandlerTest do import Poxa.EventHandler setup do - on_exit fn -> unload end + on_exit fn -> unload() end :ok end test "malformed_request with valid data" do event = %PusherEvent{} expect(:cowboy_req, :body, 1, {:ok, :body, :req1}) - expect(JSX, :decode, 1, {:ok, :data}) + expect(Poison, :decode, 1, {:ok, :data}) expect(PusherEvent, :build, [{[:data], {:ok, event}}]) assert malformed_request(:req, :state) == {false, :req1, %{body: :body, event: event}} assert validate :cowboy_req - assert validate JSX + assert validate Poison end test "malformed_request with invalid JSON" do expect(:cowboy_req, :body, 1, {:ok, :body, :req1}) expect(:cowboy_req, :set_resp_body, 2, :req2) - expect(JSX, :decode, 1, :error) + expect(Poison, :decode, 1, :error) assert malformed_request(:req, :state) == {true, :req2, :state} assert validate :cowboy_req - assert validate JSX + assert validate Poison end test "malformed_request with invalid data" do expect(:cowboy_req, :body, 1, {:ok, :body, :req1}) expect(:cowboy_req, :set_resp_body, 2, :req2) - expect(JSX, :decode, 1, {:ok, :data}) + expect(Poison, :decode, 1, {:ok, :data}) expect(PusherEvent, :build, [{[:data], {:error, :reason}}]) assert malformed_request(:req, :state) == {true, :req2, :state} assert validate :cowboy_req - assert validate JSX + assert validate Poison end test "is_authorized with failing authentication" do diff --git a/test/event_test.exs b/test/event_test.exs index ba1acfc..1ec993c 100644 --- a/test/event_test.exs +++ b/test/event_test.exs @@ -7,7 +7,7 @@ defmodule Poxa.EventTest do setup do new SocketId { :ok, _ } = GenEvent.start_link(name: Poxa.Event) - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -25,7 +25,7 @@ defmodule Poxa.EventTest do end test "notifies handler with a socket_id" do - :ok = Event.add_handler({TestHandler, self}, self) + :ok = Event.add_handler({TestHandler, self()}, self()) :ok = Event.notify(:successful_handling, %{socket_id: :socket_id, data: :map}) assert_receive %{event: :successful_handling, data: :map, @@ -33,7 +33,7 @@ defmodule Poxa.EventTest do end test "notifies handler without a socket_id" do - :ok = Event.add_handler({TestHandler, self}, self) + :ok = Event.add_handler({TestHandler, self()}, self()) expect(SocketId, :mine, 0, :socket_id) @@ -43,7 +43,7 @@ defmodule Poxa.EventTest do end test "handler failures are notified" do - :ok = Event.add_handler({TestHandler, self}, self) + :ok = Event.add_handler({TestHandler, self()}, self()) :ok = Event.notify(:failed_handling, %{socket_id: :socket_id}) assert_receive {:gen_event_EXIT, _, _} end diff --git a/test/integration/connection_test.exs b/test/integration/connection_test.exs index d15c4e6..c672133 100644 --- a/test/integration/connection_test.exs +++ b/test/integration/connection_test.exs @@ -10,7 +10,7 @@ defmodule Poxa.Integration.ConnectionTest do end test "connects and receive socket_id" do - {:ok, _pid} = PusherClient.start_link("ws://localhost:8080", "app_key", "secret", stream_to: self) + {:ok, _pid} = PusherClient.start_link("ws://localhost:8080", "app_key", "secret", stream_to: self()) assert_receive %{channel: nil, event: "pusher:connection_established", data: %{"socket_id" => socket_id, diff --git a/test/integration/public_channel_test.exs b/test/integration/public_channel_test.exs index c27dbc0..733eb62 100644 --- a/test/integration/public_channel_test.exs +++ b/test/integration/public_channel_test.exs @@ -45,7 +45,7 @@ defmodule Poxa.Integration.PublicChannelTest do data: %{"data" => 42}}, 1_000 end - test "subscribe to a public channel and trigger event excluding itself", context do + test "subscribe to a public channel and trigger event excluding itself()", context do pid = context[:pid] channel = "channel" diff --git a/test/poxa/adapter/gproc_test.exs b/test/poxa/adapter/gproc_test.exs index 5b6f6c1..8ece09a 100644 --- a/test/poxa/adapter/gproc_test.exs +++ b/test/poxa/adapter/gproc_test.exs @@ -10,14 +10,14 @@ defmodule Poxa.Adapter.GProcTest do end def spawn_registered(channel, execution, value \\ nil) do - parent = self + parent = self() child = spawn_link fn -> if value do register!(channel, value) else register!(channel) end - send parent, {self, :registered} + send parent, {self(), :registered} execution.() end assert_receive {^child, :registered} @@ -43,28 +43,28 @@ defmodule Poxa.Adapter.GProcTest do end test "send message to registered processes" do - parent = self + parent = self() child = spawn_registered("channel", fn -> receive do {^parent, msg} -> - send parent, {self, msg} + send parent, {self(), msg} end end) - send!(:msg, "channel", self) + send!(:msg, "channel", self()) assert_receive {^child, :msg} end test "send message to registered processes with socket_id" do - parent = self + parent = self() child = spawn_registered("channel", fn -> receive do {^parent, msg, socket_id} -> - send parent, {self, msg, socket_id} + send parent, {self(), msg, socket_id} end end) - send!(:msg, "channel", self, :socket_id) + send!(:msg, "channel", self(), :socket_id) assert_receive {^child, :msg, :socket_id} end @@ -85,7 +85,7 @@ defmodule Poxa.Adapter.GProcTest do test "subscriptions" do register!("presence-channel1", {"user123", "userinfo"}) register!("presence-channel2", {"user234", "userinfo"}) - assert subscriptions(self) == [ + assert subscriptions(self()) == [ ["presence-channel1", "user123"], ["presence-channel2", "user234"] ] @@ -100,7 +100,7 @@ defmodule Poxa.Adapter.GProcTest do child_channel1 = spawn_registered("channel1", execution) child_channel2 = spawn_registered("channel2", execution) - assert channels == ["channel1", "channel2"] + assert channels() == ["channel1", "channel2"] assert channels(child_channel1) == ["channel1"] assert channels(child_channel2) == ["channel2"] end @@ -115,7 +115,7 @@ defmodule Poxa.Adapter.GProcTest do spawn_registered("channel", execution, {"user1", "different user1 info"}) spawn_registered("channel", execution, {"user2", "user2 info"}) - [{"user1", _}, {"user2", "user2 info"}] = unique_subscriptions("channel") + %{ "user1" => "different user1 info", "user2" => "user2 info" } = unique_subscriptions("channel") end test "subscription_count" do diff --git a/test/presence_channel_test.exs b/test/presence_channel_test.exs index 7adcd1f..ffce674 100644 --- a/test/presence_channel_test.exs +++ b/test/presence_channel_test.exs @@ -5,7 +5,7 @@ defmodule Poxa.PresenceChannelTest do setup do new Poxa.registry - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/presence_subscription_test.exs b/test/presence_subscription_test.exs index 876b5ba..8ce7b00 100644 --- a/test/presence_subscription_test.exs +++ b/test/presence_subscription_test.exs @@ -8,7 +8,7 @@ defmodule Poxa.PresenceSubscriptionTest do setup do new [PusherEvent, Poxa.registry, Poxa.Event] - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -92,7 +92,7 @@ defmodule Poxa.PresenceSubscriptionTest do expect(Poxa.registry, :send!, 3, :ok) expect(Poxa.Event, :notify, [:member_removed, %{channel: "presence-channel", user_id: :userid}], :ok) - assert check_and_remove == 1 + assert check_and_remove() == 1 assert validate [PusherEvent, Poxa.registry, Poxa.Event] end @@ -100,13 +100,13 @@ defmodule Poxa.PresenceSubscriptionTest do test "check subscribed presence channels and remove having more than one connection on userid" do expect(Poxa.registry, :subscriptions, 1, [["presence-channel", :userid]]) expect(Poxa.registry, :subscription_count, 2, 5) - assert check_and_remove == 0 + assert check_and_remove() == 0 assert validate [PusherEvent, Poxa.registry] end test "check subscribed presence channels and find nothing to unsubscribe" do expect(Poxa.registry, :subscriptions, 1, []) - assert check_and_remove == 0 + assert check_and_remove() == 0 assert validate Poxa.registry end end diff --git a/test/pusher_event_test.exs b/test/pusher_event_test.exs index 3798c79..860bfcb 100644 --- a/test/pusher_event_test.exs +++ b/test/pusher_event_test.exs @@ -6,56 +6,56 @@ defmodule Poxa.PusherEventTest do setup do new Poxa.registry - on_exit fn -> unload end + on_exit fn -> unload() end :ok end doctest Poxa.PusherEvent test "connection established output" do - json ="{\"data\":\"{\\\"activity_timeout\\\":120,\\\"socket_id\\\":\\\"SocketId\\\"}\",\"event\":\"pusher:connection_established\"}" + json = "{\"event\":\"pusher:connection_established\",\"data\":\"{\\\"socket_id\\\":\\\"SocketId\\\",\\\"activity_timeout\\\":120}\"}" assert connection_established("SocketId") == json end test "subscription established output" do - json = "{\"channel\":\"channel\",\"data\":{},\"event\":\"pusher_internal:subscription_succeeded\"}" + json = "{\"event\":\"pusher_internal:subscription_succeeded\",\"data\":{},\"channel\":\"channel\"}" assert subscription_succeeded("channel") == json end test "subscription error output" do - json = "{\"data\":{},\"event\":\"pusher:subscription_error\"}" - assert subscription_error == json + json = "{\"event\":\"pusher:subscription_error\",\"data\":{}}" + assert subscription_error() == json end test "pusher error output" do - json = "{\"data\":{\"code\":null,\"message\":\"An error\"},\"event\":\"pusher:error\"}" + json = "{\"event\":\"pusher:error\",\"data\":{\"message\":\"An error\",\"code\":null}}" assert pusher_error("An error") == json end test "pusher error with code output" do - json = "{\"data\":{\"code\":123,\"message\":\"An error\"},\"event\":\"pusher:error\"}" + json = "{\"event\":\"pusher:error\",\"data\":{\"message\":\"An error\",\"code\":123}}" assert pusher_error("An error", 123) == json end test "pong output" do - json ="{\"data\":{},\"event\":\"pusher:pong\"}" - assert pong == json + json = "{\"event\":\"pusher:pong\",\"data\":{}}" + assert pong() == json end test "presence member added output" do - json ="{\"channel\":\"channel\",\"data\":\"{\\\"user_id\\\":\\\"userid\\\",\\\"user_info\\\":\\\"userinfo\\\"}\",\"event\":\"pusher_internal:member_added\"}" + json = "{\"event\":\"pusher_internal:member_added\",\"data\":\"{\\\"user_info\\\":\\\"userinfo\\\",\\\"user_id\\\":\\\"userid\\\"}\",\"channel\":\"channel\"}" assert presence_member_added("channel", "userid", "userinfo") == json end test "presence member removed output" do - json ="{\"channel\":\"channel\",\"data\":\"{\\\"user_id\\\":\\\"userid\\\"}\",\"event\":\"pusher_internal:member_removed\"}" + json = "{\"event\":\"pusher_internal:member_removed\",\"data\":\"{\\\"user_id\\\":\\\"userid\\\"}\",\"channel\":\"channel\"}" assert presence_member_removed("channel", "userid") == json end test "presence subscription succeeded" do - json = "{\"channel\":\"presence-channel\",\"data\":\"{\\\"presence\\\":{\\\"count\\\":1,\\\"hash\\\":{\\\"userid\\\":\\\"userinfo\\\"},\\\"ids\\\":[\\\"userid\\\"]}}\",\"event\":\"pusher_internal:subscription_succeeded\"}" + json = "{\"event\":\"pusher_internal:subscription_succeeded\",\"data\":\"{\\\"presence\\\":{\\\"ids\\\":[\\\"userid\\\"],\\\"hash\\\":{\\\"userid\\\":{\\\"user\\\":\\\"info\\\"}},\\\"count\\\":1}}\",\"channel\":\"presence-channel\"}" subscription = %Poxa.PresenceSubscription{channel: "presence-channel", - channel_data: [{"userid", "userinfo"}]} + channel_data: %{"userid" => %{ "user" => "info"}}} assert subscription_succeeded(subscription) == json end @@ -119,23 +119,23 @@ defmodule Poxa.PusherEventTest do end test "sending message to a channel" do - expect(Poxa.registry, :send!, [{[:msg, "channel123", self, nil], :ok}]) + expect(Poxa.registry, :send!, [{[:msg, "channel123", self(), nil], :ok}]) expected = %{channel: "channel123", data: "data", event: "event"} - expect(JSX, :encode!, [{[expected], :msg}]) + expect(Poison, :encode!, [{[expected], :msg}]) event = %PusherEvent{channels: ["channel123"], data: "data", name: "event"} assert publish(event) == :ok - assert validate [Poxa.registry, JSX] + assert validate [Poxa.registry, Poison] end test "sending message to channels excluding a socket id" do expected = %{channel: "channel123", data: %{}, event: "event"} - expect(JSX, :encode!, [{[expected], :msg}]) - expect(Poxa.registry, :send!, [{[:msg, "channel123", self, "SocketId"], :ok}]) + expect(Poison, :encode!, [{[expected], :msg}]) + expect(Poxa.registry, :send!, [{[:msg, "channel123", self(), "SocketId"], :ok}]) assert publish(%PusherEvent{data: %{}, channels: ["channel123"], name: "event", socket_id: "SocketId"}) == :ok - assert validate [Poxa.registry, JSX] + assert validate [Poxa.registry, Poison] end end diff --git a/test/socket_id_test.exs b/test/socket_id_test.exs index 231208d..e0ab1e4 100644 --- a/test/socket_id_test.exs +++ b/test/socket_id_test.exs @@ -6,7 +6,7 @@ defmodule Poxa.SocketIdTest do setup do new Poxa.registry - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/subscription_handler_test.exs b/test/subscription_handler_test.exs index 4353586..fec7803 100644 --- a/test/subscription_handler_test.exs +++ b/test/subscription_handler_test.exs @@ -7,11 +7,11 @@ defmodule Poxa.SubscriptionHandlerTest do setup_all do expect Event, :notify, fn event, event_data -> - send(self, {event, event_data}) + send(self(), {event, event_data}) :ok end - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/subscription_test.exs b/test/subscription_test.exs index 1b774ec..8258a8e 100644 --- a/test/subscription_test.exs +++ b/test/subscription_test.exs @@ -13,7 +13,7 @@ defmodule Poxa.SubscriptionTest do new PusherEvent new Channel, [:passthrough] new Poxa.registry - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/test_helper.exs b/test/test_helper.exs index 9944c39..bf1174a 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -3,7 +3,7 @@ ExUnit.configure(exclude: :pending) defmodule Connection do def connect do - {:ok, pid} = PusherClient.start_link("ws://localhost:8080", "app_key", "secret", stream_to: self) + {:ok, pid} = PusherClient.start_link("ws://localhost:8080", "app_key", "secret", stream_to: self()) socket_id = receive do %{channel: nil, event: "pusher:connection_established", data: %{"socket_id" => socket_id}} -> socket_id diff --git a/test/users_handler_test.exs b/test/users_handler_test.exs index 0e97680..f491118 100644 --- a/test/users_handler_test.exs +++ b/test/users_handler_test.exs @@ -5,10 +5,10 @@ defmodule Poxa.UsersHandlerTest do import Poxa.UsersHandler setup do - new JSX + new Poison new PresenceChannel new :cowboy_req - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -32,12 +32,12 @@ defmodule Poxa.UsersHandlerTest do test "get_json returns users of a presence channel" do expect(PresenceChannel, :users, 1, ["user1", "user2"]) expected = [users: [[id: "user1"], [id: "user2"]]] - expect(JSX, :encode!, [{[expected], :encoded_json}]) + expect(Poison, :encode!, [{[expected], :encoded_json}]) assert get_json(:req, "channel123") == {:encoded_json, :req, nil} assert validate PresenceChannel - assert validate JSX + assert validate Poison end end diff --git a/test/web_hook/dispatcher_test.exs b/test/web_hook/dispatcher_test.exs index d0e4f42..c26d2b9 100644 --- a/test/web_hook/dispatcher_test.exs +++ b/test/web_hook/dispatcher_test.exs @@ -13,12 +13,12 @@ defmodule Poxa.WebHook.DispatcherTest do new HTTPoison expect HTTPoison, :post, fn url, body, headers -> - args_map = %{url: url, body: JSX.decode!(body), headers: headers} - send(self, args_map) + args_map = %{url: url, body: Poison.decode!(body), headers: headers} + send(self(), args_map) {:ok, args_map} end - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/web_hook/event_table_test.exs b/test/web_hook/event_table_test.exs index 6f8ed15..6eefba1 100644 --- a/test/web_hook/event_table_test.exs +++ b/test/web_hook/event_table_test.exs @@ -14,40 +14,40 @@ defmodule Poxa.WebHook.EventTableTest do test "insert includes single event to the table" do result = insert("event") - assert result == all + assert result == all() end test "insert includes event list to the table" do result = insert(~w(event1 event2)) - assert result == all + assert result == all() end test "insert does not add channel_occupied event, it removes the corresponding channel_vacated event when it is in the table" do vacated_event = %{name: "channel_vacated", channel: "channel"} result = insert(vacated_event) - assert all == result + assert all() == result assert [] == insert(%{name: "channel_occupied", channel: "channel"}) - assert all == [] + assert all() == [] end test "insert does not add member_added event, it removes the corresponding member_removed event when it is in the table" do removed_event = %{name: "member_removed", user_id: "123", channel: "channel"} result = insert(removed_event) - assert all == result + assert all() == result assert [] == insert(%{name: "member_added", user_id: "123", channel: "channel"}) - assert all == [] + assert all() == [] end test "ready returns events ready to be sent" do result = insert(~w(ready_event), 0) - assert result == all - assert {_, ~w(ready_event)} = ready + assert result == all() + assert {_, ~w(ready_event)} = ready() end test "ready does not return events to be delivered in the future" do result = insert(~w(ready_event), 0) insert(~w(delayed_event), 10000) - assert ~w(delayed_event ready_event) == Enum.sort all - assert {_, ^result} = ready + assert ~w(delayed_event ready_event) == Enum.sort all() + assert {_, ^result} = ready() end end diff --git a/test/web_hook/handler_test.exs b/test/web_hook/handler_test.exs index 5ba0109..c8e32fa 100644 --- a/test/web_hook/handler_test.exs +++ b/test/web_hook/handler_test.exs @@ -14,7 +14,7 @@ defmodule Poxa.WebHook.HandlerTest do new Channel - on_exit fn -> unload end + on_exit fn -> unload() end :ok end diff --git a/test/websocket_handler_test.exs b/test/websocket_handler_test.exs index 24625cb..701bb24 100644 --- a/test/websocket_handler_test.exs +++ b/test/websocket_handler_test.exs @@ -19,7 +19,7 @@ defmodule Poxa.WebsocketHandlerTest do setup do new Poxa.registry - on_exit fn -> unload end + on_exit fn -> unload() end :ok end @@ -66,16 +66,16 @@ defmodule Poxa.WebsocketHandlerTest do end test "undefined pusher event websocket message" do - expect(JSX, :decode!, 1, %{"event" => "pushernil"}) + expect(Poison, :decode!, 1, %{"event" => "pushernil"}) assert websocket_handle({:text, :undefined_event_json}, :req, :state) == {:ok, :req, :state} - assert validate JSX + assert validate Poison end test "pusher ping event" do - expect(JSX, :decode!, 1, %{"event" => "pusher:ping"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:ping"}) expect(PusherEvent, :pong, 0, :pong) state = %State{socket_id: :socket_id} @@ -83,11 +83,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :ping_json}, :req, state) == {:reply, {:text, :pong}, :req, state} - assert validate [JSX, PusherEvent] + assert validate [Poison, PusherEvent] end test "subscribe private channel event" do - expect(JSX, :decode!, 1, %{"event" => "pusher:subscribe"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:subscribe"}) expect(Subscription, :subscribe!, 2, {:ok, :channel}) expect(PusherEvent, :subscription_succeeded, 1, :subscription_succeeded) expect(Event, :notify, [{[:subscribed, %{socket_id: :socket_id, channel: :channel}], :ok}]) @@ -97,11 +97,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :subscribe_json}, :req, state) == {:reply, {:text, :subscription_succeeded}, :req, state} - assert validate [JSX, PusherEvent, Subscription, Event] + assert validate [Poison, PusherEvent, Subscription, Event] end test "subscribe private channel event failing for bad authentication" do - expect(JSX, :decode!, 1, %{"event" => "pusher:subscribe"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:subscribe"}) expect(Subscription, :subscribe!, 2, {:error, :error_message}) state = %State{socket_id: :socket_id} @@ -109,11 +109,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :subscription_json}, :req, state) == {:reply, {:text, :error_message}, :req, state} - assert validate [JSX, Subscription] + assert validate [Poison, Subscription] end test "subscribe presence channel event" do - expect(JSX, :decode!, 1, %{"event" => "pusher:subscribe"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:subscribe"}) expect(Subscription, :subscribe!, 2, %PresenceSubscription{channel: :channel}) expect(PusherEvent, :subscription_succeeded, 1, :subscription_succeeded) expect(Event, :notify, [{[:subscribed, %{socket_id: :socket_id, channel: :channel}], :ok}]) @@ -123,11 +123,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :subscribe_json}, :req, state) == {:reply, {:text, :subscription_succeeded}, :req, state} - assert validate [JSX, PusherEvent, Subscription, Event] + assert validate [Poison, PusherEvent, Subscription, Event] end test "subscribe presence channel event failing for bad authentication" do - expect(JSX, :decode!, 1, %{"event" => "pusher:subscribe"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:subscribe"}) expect(Subscription, :subscribe!, 2, {:error, :error_message}) state = %State{socket_id: :socket_id} @@ -135,11 +135,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :subscription_json}, :req, state) == {:reply, {:text, :error_message}, :req, state} - assert validate [JSX, Subscription] + assert validate [Poison, Subscription] end test "subscribe public channel event" do - expect(JSX, :decode!, 1, %{"event" => "pusher:subscribe"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:subscribe"}) expect(Subscription, :subscribe!, 2, {:ok, :channel}) expect(PusherEvent, :subscription_succeeded, 1, :subscription_succeeded) expect(Event, :notify, [{[:subscribed, %{socket_id: :socket_id, channel: :channel}], :ok}]) @@ -149,11 +149,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :subscribe_json}, :req, state) == {:reply, {:text, :subscription_succeeded}, :req, state} - assert validate [JSX, PusherEvent, Subscription, Event] + assert validate [Poison, PusherEvent, Subscription, Event] end test "subscribe event on an already subscribed channel" do - expect(JSX, :decode!, 1, %{"event" => "pusher:subscribe"}) + expect(Poison, :decode!, 1, %{"event" => "pusher:subscribe"}) expect(Subscription, :subscribe!, 2, {:ok, :channel}) expect(PusherEvent, :subscription_succeeded, 1, :subscription_succeeded) expect(Event, :notify, [{[:subscribed, %{socket_id: :socket_id, channel: :channel}], :ok}]) @@ -163,11 +163,11 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :subscribe_json}, :req, state) == {:reply, {:text, :subscription_succeeded}, :req, state} - assert validate [JSX, PusherEvent, Subscription, Event] + assert validate [Poison, PusherEvent, Subscription, Event] end test "unsubscribe event" do - expect(JSX, :decode!, 1, %{"event" => "pusher:unsubscribe", "data" => :data}) + expect(Poison, :decode!, 1, %{"event" => "pusher:unsubscribe", "data" => :data}) expect(Subscription, :unsubscribe!, [{[:data], {:ok, :channel}}]) expect(Event, :notify, [{[:unsubscribed, %{socket_id: :socket_id, channel: :channel}], :ok}]) @@ -176,13 +176,13 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :unsubscribe_json}, :req, state) == {:ok, :req, state} - assert validate [JSX, Subscription, Event] + assert validate [Poison, Subscription, Event] end test "client event on presence channel" do decoded_json = %{"event" => "client-event"} event = %PusherEvent{channels: ["presence-channel"], name: "client-event"} - expect(JSX, :decode!, [{[:client_event_json], decoded_json}]) + expect(Poison, :decode!, [{[:client_event_json], decoded_json}]) expect(PusherEvent, :build_client_event, [{[decoded_json, :socket_id], {:ok, event}}]) expect(PusherEvent, :publish, 1, :ok) expect(Channel, :member?, 2, true) @@ -193,13 +193,13 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :client_event_json}, :req, state) == {:ok, :req, state} - assert validate [JSX, PusherEvent, Event] + assert validate [Poison, PusherEvent, Event] end test "client event on private channel" do decoded_json = %{"event" => "client-event"} event = %PusherEvent{channels: ["private-channel"], name: "client-event"} - expect(JSX, :decode!, [{[:client_event_json], decoded_json}]) + expect(Poison, :decode!, [{[:client_event_json], decoded_json}]) expect(PusherEvent, :build_client_event, [{[decoded_json, :socket_id], {:ok, event}}]) expect(PusherEvent, :publish, 1, :ok) expect(Channel, :member?, 2, true) @@ -210,13 +210,13 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :client_event_json}, :req, state) == {:ok, :req, state} - assert validate [JSX, PusherEvent, Event] + assert validate [Poison, PusherEvent, Event] end test "client event on not subscribed private channel" do decoded_json = %{"event" => "client-event"} event = %PusherEvent{channels: ["private-not-subscribed"], name: "client-event"} - expect(JSX, :decode!, [{[:client_event_json], decoded_json}]) + expect(Poison, :decode!, [{[:client_event_json], decoded_json}]) expect(PusherEvent, :build_client_event, [{[decoded_json, :socket_id], {:ok, event}}]) expect(Channel, :member?, 2, false) @@ -225,12 +225,12 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :client_event_json}, :req, state) == {:ok, :req, state} - assert validate [JSX, PusherEvent, Channel] + assert validate [Poison, PusherEvent, Channel] end test "client event on public channel" do event = %PusherEvent{channels: ["public-channel"], name: "client-event"} - expect(JSX, :decode!, 1, %{"event" => "client-event"}) + expect(Poison, :decode!, 1, %{"event" => "client-event"}) expect(PusherEvent, :build_client_event, 2, {:ok, event}) state = %State{socket_id: :socket_id} @@ -238,7 +238,7 @@ defmodule Poxa.WebsocketHandlerTest do assert websocket_handle({:text, :client_event_json}, :req, state) == {:ok, :req, state} - assert validate [JSX, PusherEvent] + assert validate [Poison, PusherEvent] end test "websocket init" do From 4cdf8b23a57b4c88087901e97b766251fa15e998 Mon Sep 17 00:00:00 2001 From: Eduardo Gurgel Date: Tue, 10 Oct 2017 22:34:47 +1300 Subject: [PATCH 2/3] Fix poxa.conf and schema --- Dockerfile | 16 ++++++------ README.md | 28 +++++++++++++++++++-- config/poxa.conf | 32 ------------------------ config/poxa.dev.conf | 44 +++++++++++++++++++++++++++++++++ config/poxa.schema.exs | 56 +++++++++++++++++++++++++++++------------- rel/relx.config | 1 - 6 files changed, 118 insertions(+), 59 deletions(-) delete mode 100644 config/poxa.conf create mode 100644 config/poxa.dev.conf delete mode 100644 rel/relx.config diff --git a/Dockerfile b/Dockerfile index 45e2513..090181b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,18 @@ -FROM msaraiva/elixir-dev:1.2.4 +FROM elixir:1.5.2-alpine ENV APP_NAME poxa +ENV MIX_ENV prod -RUN apk --update add erlang-xmerl erlang-crypto erlang-sasl && rm -rf /var/cache/apk/* +RUN apk --update add bash git erlang-xmerl erlang-crypto erlang-sasl && rm -rf /var/cache/apk/* COPY . /source WORKDIR /source RUN mix local.hex --force && mix local.rebar --force -RUN MIX_ENV=prod mix deps.get -RUN MIX_ENV=prod mix compile -RUN MIX_ENV=prod mix release --verbosity=verbose --no-confirm-missing -RUN mkdir /app && cp -r rel/$APP_NAME /app && rm -rf /source +RUN mix deps.get +RUN mix compile +RUN mix release -CMD trap exit TERM; /app/$APP_NAME/bin/$APP_NAME foreground & wait +RUN mkdir /app && cp -r _build/prod/rel/$APP_NAME /app && rm -rf /source + +CMD /app/$APP_NAME/bin/$APP_NAME foreground diff --git a/README.md b/README.md index cf1f1f5..aa1e732 100644 --- a/README.md +++ b/README.md @@ -137,14 +137,14 @@ MIX_ENV=prod mix do deps.get, compile, release Then you can run it using: ```console -$ ./rel/poxa/bin/poxa +$ _build/prod/rel/poxa/bin/poxa Usage: poxa {start|start_boot |foreground|stop|restart|reboot|ping|rpc []|console|console_clean|console_boot |attach|remote_console|upgrade} ``` To start as daemon you just need to: ```console -./rel/poxa/bin/poxa start +$ _build/prod/rel/poxa/bin/poxa start ``` ### Release configuration @@ -169,6 +169,30 @@ poxa.app_id = "app_id" You can change anything on this file and just start the release and this configuration will be used. +#### Environment variables + +The .conf file is not the only way to configure a release. The following environment variables are supported: + +* `PORT` +* `POXA_APP_KEY` +* `POXA_SECRET` +* `POXA_APP_ID` +* `POXA_REGISTRY_ADAPTER` +* `WEB_HOOK` +* `POXA_SSL` +* `SSL_PORT` +* `SSL_CACERTFILE` +* `SSL_CERTFILE` +* `SSL_KEYFILE` + +Even if the file is not used at all, an empty file must exist or you will get this error: + +``` +missing .conf, expected it at /Users/eduardo/workspace/poxa/_build/dev/rel/poxa/releases/0.7.0/poxa.conf +``` + +It is very important that the .conf file does not have the same configuration. For example if both `PORT` and `poxa.port` (inside the .conf file) are defined, then the file will have precedence. + ## Using Docker Docker images are automatically built by [Docker Hub](https://hub.docker.com/r/edgurgel/poxa-automated/builds/). They are available at Docker Hub: https://hub.docker.com/r/edgurgel/poxa-automated/tags/ diff --git a/config/poxa.conf b/config/poxa.conf deleted file mode 100644 index ed56514..0000000 --- a/config/poxa.conf +++ /dev/null @@ -1,32 +0,0 @@ -# HTTP port -poxa.port = 8080 - -# Pusher app key -poxa.app_key = "app_key" - -# Pusher secret -poxa.app_secret = "secret" - -# Pusher app id -poxa.app_id = "app_id" - -# Registry adapter -poxa.registry_adapter = "gproc" - -# Web hook endpoint -# poxa.web_hook = - -# HTTPS switch -# poxa.ssl.enabled = - -# HTTPS port -# poxa.ssl.port = - -# PEM-encoded CA certificate path -# poxa.ssl.cacertfile = - -# Path to user certificate -# poxa.ssl.certfile = - -# Path to the file containing the user's private PEM-encoded key -# poxa.ssl.keyfile = diff --git a/config/poxa.dev.conf b/config/poxa.dev.conf new file mode 100644 index 0000000..09c9279 --- /dev/null +++ b/config/poxa.dev.conf @@ -0,0 +1,44 @@ +# HTTP Port +# If not set, will use value of PORT environment variable +poxa.port = 8080 + +# Pusher app key +# If not set, will use value of POXA_APP_KEY environment variable +poxa.app_key = "app_key" + +# Pusher secret +# If not set, will use value of POXA_SECRET environment variable +poxa.app_secret = "secret" + +# Pusher app id +# If not set, will use value of POXA_APP_ID environment variable +poxa.app_id = "app_id" + +# Registry adapter +# If not set, will use value of POXA_REGISTRY_ADAPTER environment variable +poxa.registry_adapter = "gproc" + +# Web hook endpoint +# If not set, will use value of WEB_HOOK environment variable +# poxa.web_hook = + +# HTTPS switch +# If not set, will use value of POXA_SSL environment variable +poxa.ssl.enabled = false + +# HTTPS port +# If not set, will use value of SSL_PORT environment variable +# poxa.ssl.port = + +# PEM-encoded CA certificate path +# If not set, will use value of SSL_CACERTFILE environment variable +# poxa.ssl.cacertfile = + +# Path to user certificate +# If not set, will use value of SSL_CERTFILE environment variable +# poxa.ssl.certfile = + +# Path to the file containing the user's private PEM-encoded key +# If not set, will use value of SSL_KEYFILE environment variable +# poxa.ssl.keyfile = + diff --git a/config/poxa.schema.exs b/config/poxa.schema.exs index fbf88a2..a3877e4 100644 --- a/config/poxa.schema.exs +++ b/config/poxa.schema.exs @@ -1,32 +1,42 @@ [ + extends: [], + import: [], mappings: [ "poxa.port": [ - doc: "HTTP port", - to: "poxa.port", commented: false, datatype: :integer, - default: 8080 + default: 8080, + doc: "HTTP Port", + hidden: false, + env_var: "PORT", + to: "poxa.port" ], "poxa.app_key": [ - doc: "Pusher app key", - to: "poxa.app_key", commented: false, datatype: :binary, - default: "app_key" + default: "app_key", + doc: "Pusher app key", + hidden: false, + env_var: "POXA_APP_KEY", + to: "poxa.app_key" ], "poxa.app_secret": [ - doc: "Pusher secret", - to: "poxa.app_secret", commented: false, datatype: :binary, - default: "secret" + default: "secret", + doc: "Pusher secret", + hidden: false, + env_var: "POXA_SECRET", + to: "poxa.app_secret" ], "poxa.app_id": [ - doc: "Pusher app id", - to: "poxa.app_id", commented: false, datatype: :binary, - default: "app_id" + default: "app_id", + doc: "Pusher app id", + hidden: false, + env_var: "POXA_APP_ID", + to: "poxa.app_id" ], "poxa.registry_adapter": [ commented: false, @@ -34,42 +44,54 @@ default: "gproc", doc: "Registry adapter", hidden: false, + env_var: "POXA_REGISTRY_ADAPTER", to: "poxa.registry_adapter" ], "poxa.web_hook": [ - commented: true, - datatype: :atom, + commented: false, + datatype: :binary, doc: "Web hook endpoint", hidden: false, + default: "", + env_var: "WEB_HOOK", to: "poxa.web_hook" - ], + ], "poxa.ssl.enabled": [ doc: "HTTPS switch", to: "poxa.ssl.enabled", datatype: :boolean, + env_var: "POXA_SSL", default: false, ], "poxa.ssl.port": [ doc: "HTTPS port", to: "poxa.ssl.port", + env_var: "SSL_PORT", + default: 8443, datatype: :integer, ], "poxa.ssl.cacertfile": [ doc: "PEM-encoded CA certificate path", to: "poxa.ssl.cacertfile", + env_var: "SSL_CACERTFILE", + default: "", datatype: :binary, ], "poxa.ssl.certfile": [ doc: "Path to user certificate", to: "poxa.ssl.certfile", + env_var: "SSL_CERTFILE", + default: "", datatype: :binary, ], "poxa.ssl.keyfile": [ doc: "Path to the file containing the user's private PEM-encoded key", to: "poxa.ssl.keyfile", + env_var: "SSL_KEYFILE", + default: "", datatype: :binary, ] ], - translations: [ - ] + transforms: [], + validators: [] ] diff --git a/rel/relx.config b/rel/relx.config deleted file mode 100644 index b2a7ce1..0000000 --- a/rel/relx.config +++ /dev/null @@ -1 +0,0 @@ -{include_erts, false}. From 10ed6fefeccabf1c12463f3fb3e53f92dffabb13 Mon Sep 17 00:00:00 2001 From: Eduardo Gurgel Date: Thu, 12 Oct 2017 22:25:14 +1300 Subject: [PATCH 3/3] Update gproc & ex2ms --- mix.exs | 4 ++-- mix.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 0be88b8..f06bb36 100644 --- a/mix.exs +++ b/mix.exs @@ -25,14 +25,14 @@ defmodule Poxa.Mixfile do [ {:cowboy, "~> 1.1.2" }, {:poison, "~> 3.0"}, {:signaturex, "~> 1.3"}, - {:gproc, "~> 0.3.0"}, + {:gproc, "~> 0.6"}, {:meck, "~> 0.8.2", only: :test}, {:pusher_client, github: "edgurgel/pusher_client", only: :test}, {:pusher, "~> 0.1", only: :test}, {:distillery, "~> 1.4", runtime: false}, {:conform, "~> 2.0"}, {:httpoison, "~> 0.9"}, - {:ex2ms, "~> 1.4.0"}, + {:ex2ms, "~> 1.5"}, {:watcher, "~> 1.1.0"}, {:dialyxir, "~> 0.3", only: [:dev, :test]}] end diff --git a/mix.lock b/mix.lock index 9345bee..f4be2c1 100644 --- a/mix.lock +++ b/mix.lock @@ -4,9 +4,9 @@ "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"}, "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, "distillery": {:hex, :distillery, "1.5.2", "eec18b2d37b55b0bcb670cf2bcf64228ed38ce8b046bb30a9b636a6f5a4c0080", [:mix], [], "hexpm"}, - "ex2ms": {:hex, :ex2ms, "1.4.0", "e43b410888b45ba363ea6650db3736db3e455a0a412ec244ac633fede857bcb2", [:mix], [], "hexpm"}, + "ex2ms": {:hex, :ex2ms, "1.5.0", "19e27f9212be9a96093fed8cdfbef0a2b56c21237196d26760f11dfcfae58e97", [:mix], [], "hexpm"}, "exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, - "gproc": {:hex, :gproc, "0.3.1", "ec14f40cb941bde3f940de59c11e59beb2977e90dbae72fab3ddf77743fd4ea9", [:rebar], [], "hexpm"}, + "gproc": {:hex, :gproc, "0.6.1", "4579663e5677970758a05d8f65d13c3e9814ec707ad51d8dcef7294eda1a730c", [:rebar3], [], "hexpm"}, "hackney": {:hex, :hackney, "1.9.0", "51c506afc0a365868469dcfc79a9d0b94d896ec741cfd5bd338f49a5ec515bfe", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [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, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},