Skip to content

Commit fb8e5da

Browse files
committed
Add nomination failure test
1 parent d9bf764 commit fb8e5da

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

test/priv/ice_agent_test.exs

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ defmodule ExICE.Priv.ICEAgentTest do
303303
ice_agent = put_in(ice_agent.local_cands[cand.base.id], cand)
304304

305305
[pair] = Map.values(ice_agent.checklist)
306-
pair = %{pair | state: :failed}
306+
pair = %{pair | state: :failed, valid?: false}
307307
ice_agent = put_in(ice_agent.checklist[pair.id], pair)
308308

309309
# try to feed data on closed candidate, it should be ignored
@@ -363,7 +363,7 @@ defmodule ExICE.Priv.ICEAgentTest do
363363

364364
assert ice_agent.state == :closed
365365
assert ice_agent.gathering_state == :complete
366-
assert [%{state: :failed} = pair] = Map.values(ice_agent.checklist)
366+
assert [%{state: :failed, valid?: false} = pair] = Map.values(ice_agent.checklist)
367367
assert [%{base: %{closed?: true}}] = Map.values(ice_agent.local_cands)
368368
# make sure that sockets and remote cands were not cleared
369369
assert [_remote_cand] = Map.values(ice_agent.remote_cands)
@@ -454,7 +454,7 @@ defmodule ExICE.Priv.ICEAgentTest do
454454

455455
# mark pair as failed
456456
[pair] = Map.values(ice_agent.checklist)
457-
ice_agent = put_in(ice_agent.checklist[pair.id], %{pair | state: :failed})
457+
ice_agent = put_in(ice_agent.checklist[pair.id], %{pair | state: :failed, valid?: false})
458458

459459
# clear ta_timer, ignore outgoing binding request that has been generated
460460
ice_agent = ICEAgent.handle_ta_timeout(ice_agent)
@@ -512,8 +512,7 @@ defmodule ExICE.Priv.ICEAgentTest do
512512

513513
# mark pair as failed
514514
[pair] = Map.values(ice_agent.checklist)
515-
ice_agent = put_in(ice_agent.checklist[pair.id], %{pair | state: :failed})
516-
515+
ice_agent = put_in(ice_agent.checklist[pair.id], %{pair | state: :failed, valid?: false})
517516
# clear ta_timer, ignore outgoing binding request that has been generated
518517
ice_agent = ICEAgent.handle_ta_timeout(ice_agent)
519518
assert ice_agent.ta_timer == nil
@@ -1246,6 +1245,7 @@ defmodule ExICE.Priv.ICEAgentTest do
12461245
end
12471246

12481247
@conn_check_byte_size 92
1248+
@conn_check_with_nomination_byte_size 96
12491249

12501250
describe "connectivity check" do
12511251
setup do
@@ -1518,7 +1518,7 @@ defmodule ExICE.Priv.ICEAgentTest do
15181518
resp
15191519
)
15201520

1521-
assert [%CandidatePair{state: :failed}] = Map.values(ice_agent.checklist)
1521+
assert [%CandidatePair{state: :failed, valid?: false}] = Map.values(ice_agent.checklist)
15221522
assert [new_pair] = Map.values(ice_agent.checklist)
15231523
assert new_pair.state == :failed
15241524
assert new_pair.responses_received == pair.responses_received
@@ -1609,6 +1609,53 @@ defmodule ExICE.Priv.ICEAgentTest do
16091609

16101610
assert ice_agent.state == :failed
16111611
end
1612+
1613+
test "failure on send, when nominating" do
1614+
# 1. make ice agent connected
1615+
# 2. replace candidate with the mock one that always fails to send data
1616+
# 3. assert that after unsuccessful nomination sending, ice_agent moves conn pair to the failed state
1617+
1618+
ice_agent =
1619+
ICEAgent.new(
1620+
controlling_process: self(),
1621+
role: :controlling,
1622+
if_discovery_module: IfDiscovery.Mock,
1623+
transport_module: Transport.Mock
1624+
)
1625+
|> ICEAgent.set_remote_credentials("someufrag", "somepwd")
1626+
|> ICEAgent.gather_candidates()
1627+
|> ICEAgent.add_remote_candidate(@remote_cand)
1628+
1629+
assert ice_agent.gathering_state == :complete
1630+
1631+
# make ice_agent connected
1632+
ice_agent = connect(ice_agent)
1633+
1634+
# replace candidate with the mock one
1635+
[local_cand] = Map.values(ice_agent.local_cands)
1636+
mock_cand = %Candidate.Mock{base: local_cand.base}
1637+
ice_agent = %{ice_agent | local_cands: %{mock_cand.base.id => mock_cand}}
1638+
1639+
# trigger pair nomination
1640+
ice_agent = ICEAgent.end_of_candidates(ice_agent)
1641+
1642+
# assert that the candidate pair has moved to a failed state
1643+
# and that the state was updated after the packet was discarded
1644+
assert [
1645+
%{
1646+
state: :failed,
1647+
valid?: false,
1648+
packets_discarded_on_send: 1,
1649+
bytes_discarded_on_send: @conn_check_with_nomination_byte_size
1650+
}
1651+
] = Map.values(ice_agent.checklist)
1652+
1653+
assert ice_agent.state == :connected
1654+
1655+
ice_agent = ICEAgent.handle_ta_timeout(ice_agent)
1656+
1657+
assert ice_agent.state == :failed
1658+
end
16121659
end
16131660

16141661
describe "connectivity check with aggressive nomination" do
@@ -1989,7 +2036,7 @@ defmodule ExICE.Priv.ICEAgentTest do
19892036
ice_agent = ICEAgent.handle_pair_timeout(ice_agent)
19902037

19912038
# assert that the pair is marked as failed
1992-
assert [%CandidatePair{state: :failed}] = Map.values(ice_agent.checklist)
2039+
assert [%CandidatePair{state: :failed, valid?: false}] = Map.values(ice_agent.checklist)
19932040

19942041
# trigger eoc timeout
19952042
ice_agent = ICEAgent.handle_eoc_timeout(ice_agent)
@@ -2019,7 +2066,7 @@ defmodule ExICE.Priv.ICEAgentTest do
20192066

20202067
# mark pair as failed
20212068
[pair] = Map.values(ice_agent.checklist)
2022-
ice_agent = put_in(ice_agent.checklist[pair.id], %{pair | state: :failed})
2069+
ice_agent = put_in(ice_agent.checklist[pair.id], %{pair | state: :failed, valid?: false})
20232070

20242071
# set eoc flag
20252072
failed_ice_agent = ICEAgent.end_of_candidates(ice_agent)

0 commit comments

Comments
 (0)