Created
May 24, 2017 23:00
-
-
Save adkron/bbf6c88a15deb0f53e644719499e974f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Zwave.Inclusion.Process.Test do | |
use ExUnit.Case, async: true | |
alias Zwave.Inclusion.{Command, Response} | |
use Zwave.Status | |
@subject Zwave.Inclusion.Procedure | |
@node_timeout_in_ms 60 * 1000 | |
setup do | |
Zwave.Registry.subscribe(:sent) | |
:ok | |
end | |
def assert_sent_to_controller({command_name, _wire_protocol}) do | |
assert_receive({:sent, ^command_name}) | |
end | |
test "initiator\1" do | |
expected_initator = self() | |
state = @subject.initialize(expected_initator) | |
assert expected_initator == @subject.initiator(state) | |
end | |
@tag timeout: 70 * 1000 | |
test "good inclusion" do | |
node_id = Enum.random(1..232) | |
start_command = Command.start | |
completed_command = Command.completed | |
stop_command = Command.stop | |
acknowledge_response = Status.acknowledge | |
initiator = self() | |
with state <- @subject.initialize(initiator), | |
_ <- assert_sent_to_controller(start_command), | |
{:ok, state} <- @subject.received(state, Status.Acknowledge), | |
{:ok, state} <- @subject.received(state, %Response{status: :ready}), | |
_ <- assert_sent_to_controller(acknowledge_response), | |
{:ok, state} <- @subject.received(state, %Response{status: :node_found}), | |
_ <- assert_sent_to_controller(acknowledge_response), | |
{:ok, state} <- @subject.received(state, | |
%Response{status: :adding_slave, node_id: node_id}), | |
_ <- assert_sent_to_controller(acknowledge_response), | |
{:ok, state} <- @subject.received(state, | |
%Response{status: :protocol_done, node_id: node_id}), | |
_ <- assert_sent_to_controller(acknowledge_response), | |
_ <- assert_sent_to_controller(completed_command), | |
{:fin, final_state} <- @subject.received(state, Status.Acknowledge), | |
_ <- assert_sent_to_controller(stop_command) | |
do | |
assert %@subject{state: :fin, data: %@subject.Data{initiator: initiator, node_id: node_id}} == final_state | |
refute_receive {:timeout, :node}, @node_timeout_in_ms + 10 | |
else | |
error -> flunk inspect(error) | |
end | |
end | |
test "protocol ready timeout" do | |
protocol_ready_timeout_in_ms = 10 * 1000 | |
@subject.initialize(self()) | |
assert_receive {:timeout, :protocol_ready}, protocol_ready_timeout_in_ms + 10 | |
end | |
@tag timeout: 70 * 1000 | |
test "node timeout" do | |
with state <- @subject.initialize(self()), | |
{:ok, state} <- @subject.received(state, Status.Acknowledge), | |
{:ok, _state} <- @subject.received(state, %Response{status: :ready}) | |
do | |
assert_receive {:timeout, :node}, @node_timeout_in_ms + 10 | |
else | |
error -> flunk inspect(error) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment