Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
savonarola committed Jul 23, 2023
1 parent 25eb2b4 commit 2dbd942
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 15 deletions.
6 changes: 3 additions & 3 deletions test/esme/sync_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule SMPPEX.ESME.SyncTest do

mc_with_opts = fn handler, opts ->
test_pid = self()

start_supervised!({
MC,
session: {Support.Session, {callback_agent, handler, test_pid}},
Expand Down Expand Up @@ -224,6 +225,7 @@ defmodule SMPPEX.ESME.SyncTest do
esme,
SMPPEX.Pdu.Factory.bind_transmitter("system_id", "too_long_password")
)

send(pid, :done)
end)

Expand All @@ -235,7 +237,6 @@ defmodule SMPPEX.ESME.SyncTest do
end

test "wait_for_pdus, resp", ctx do

test_pid = self()

ctx[:mc].(fn
Expand Down Expand Up @@ -297,7 +298,6 @@ defmodule SMPPEX.ESME.SyncTest do
esme = ctx[:esme].()

assert :timeout = ESMESync.wait_for_pdus(esme, 5)

end

test "stop", ctx do
Expand Down Expand Up @@ -335,6 +335,6 @@ defmodule SMPPEX.ESME.SyncTest do

Session.send_pdu(mc_session, SMPPEX.Pdu.Factory.bind_transmitter("system_id", "password"))

assert wait_match fn -> [pdu: _] = ESMESync.pdus(esme) end
assert wait_match(fn -> [pdu: _] = ESMESync.pdus(esme) end)
end
end
12 changes: 10 additions & 2 deletions test/esme_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ defmodule SMPPEX.ESMETest do
handler = fn {:init, _socket, _transport}, st -> {:ok, st} end

assert {:ok, _} =
ESME.start_link('localhost', Server.port(server), {SupportSession, {pid, handler, self()}})
ESME.start_link(
'localhost',
Server.port(server),
{SupportSession, {pid, handler, self()}}
)
end

test "start_link by hostname as a string" do
Expand All @@ -38,7 +42,11 @@ defmodule SMPPEX.ESMETest do
handler = fn {:init, _socket, _transport}, st -> {:ok, st} end

assert {:ok, _} =
ESME.start_link("localhost", Server.port(server), {SupportSession, {pid, handler, self()}})
ESME.start_link(
"localhost",
Server.port(server),
{SupportSession, {pid, handler, self()}}
)
end

test "start_link when MC is down" do
Expand Down
9 changes: 6 additions & 3 deletions test/integration/socket_edge_cases_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ defmodule SMPPEX.Integration.SocketEdgeCasesTest do

accept = fn ->
send(pid, {:accept, self()})

receive do
{:accept, res} -> res
after
Expand All @@ -57,6 +58,7 @@ defmodule SMPPEX.Integration.SocketEdgeCasesTest do

delay = fn ->
send(pid, {:esme_pid, self()})

receive do
:continue -> :ok
after
Expand All @@ -66,12 +68,13 @@ defmodule SMPPEX.Integration.SocketEdgeCasesTest do
end

start_supervised!({MC, {port, "good.rubybox.dev", accept}})
spawn_link fn -> ESME.start_link(port, "good.rubybox.dev", delay) end
spawn_link(fn -> ESME.start_link(port, "good.rubybox.dev", delay) end)

receive do
{:accept, mc_pid} ->
mref = :erlang.monitor(:process, mc_pid)
send(mc_pid, {:accept, {:stop, :ooops}})

receive do
{:DOWN, ^mref, :process, ^mc_pid, :ooops} -> :ok
after
Expand All @@ -87,17 +90,17 @@ defmodule SMPPEX.Integration.SocketEdgeCasesTest do
{:esme_pid, esme_pid} ->
mref = :erlang.monitor(:process, esme_pid)
send(esme_pid, :continue)

receive do
{:DOWN, ^mref, :process, ^esme_pid, :socket_closed} -> :ok
{:DOWN, ^mref, :process, ^esme_pid, {:socket_error, :closed}} -> :ok
after
1000 ->
flunk("ESME should have been terminated")
end
after
after
1000 ->
flunk("ESME should have received :continue")
end

end
end
3 changes: 2 additions & 1 deletion test/pdu_storage_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ defmodule SMPPEX.PduStorageTest do
storage1 = PduStorage.store(storage0, pdu1)
Klotho.Mock.warp_by(500)
storage2 = PduStorage.store(storage1, pdu2)
Klotho.Mock.warp_by(750) # 1250
# 1250
Klotho.Mock.warp_by(750)

assert_received {:expire_pdus, @id}

Expand Down
1 change: 0 additions & 1 deletion test/session_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,6 @@ defmodule SMPPEX.SessionTest do
{:ok, action_pdu_data} = SMPPEX.Protocol.build(action_pdu)
Server.send(ctx[:server], action_pdu_data)


assert wait_match(fn ->
{:ok, {:pdu, _bind_pdu}, rest} =
Server.received_data(ctx[:server]) |> SMPPEX.Protocol.parse()
Expand Down
1 change: 1 addition & 0 deletions test/support/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ defmodule Support.Session do
Agent.update(agent_pid, fn callbacks ->
[callback_info | callbacks]
end)

send(test_pid, callback_info)
handler.(callback_info, st)
end
Expand Down
1 change: 1 addition & 0 deletions test/support/smpp_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Support.SMPPSession do
Agent.update(st.callbacks_received, fn callbacks ->
[{name, args} | callbacks]
end)

send(st.starter_pid, {name, args})
st
end
Expand Down
2 changes: 2 additions & 0 deletions test/support/ssl/mc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ defmodule Support.SSL.MC do
cond do
accept == true ->
{:ok, 0}

accept == false ->
{:stop, :ooops}

true ->
accept.()
end
Expand Down
11 changes: 6 additions & 5 deletions test/transport_session_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ defmodule SMPPEX.TransportSessionTest do

context[:session] |> SMPPSession.stop(:some_reason)

assert wait_match fn -> [{:tcp_closed, _}] = Server.messages(context[:server]) end
assert wait_match(fn -> [{:tcp_closed, _}] = Server.messages(context[:server]) end)
end

test "handle_send_pdu_result, single pdu", context do
Expand All @@ -184,7 +184,7 @@ defmodule SMPPEX.TransportSessionTest do
context[:session] |> SMPPSession.send_pdus([pdu])

{:ok, pdu_data} = SMPPEX.Protocol.build(pdu)
assert wait_match fn -> ^pdu_data = Server.received_data(context[:server]) end
assert wait_match(fn -> ^pdu_data = Server.received_data(context[:server]) end)
end

test "handle_pdu returning send_pdus", context do
Expand All @@ -195,9 +195,10 @@ defmodule SMPPEX.TransportSessionTest do
{:ok, pdu_tx_data} = SMPPEX.Protocol.build(pdu_tx)
{:ok, pdu_rx_data} = SMPPEX.Protocol.build(pdu_rx)
pdu_data = pdu_tx_data <> pdu_rx_data
assert wait_match fn ->
^pdu_data = Server.received_data(context[:server])
end

assert wait_match(fn ->
^pdu_data = Server.received_data(context[:server])
end)
end

test "reply", context do
Expand Down

0 comments on commit 2dbd942

Please sign in to comment.