@@ -317,7 +317,7 @@ defmodule ExICE.Priv.ICEAgentTest do
317
317
ice_agent = put_in ( ice_agent . local_cands [ cand . base . id ] , cand )
318
318
319
319
[ pair ] = Map . values ( ice_agent . checklist )
320
- pair = % { pair | state: :failed }
320
+ pair = % { pair | state: :failed , valid?: false }
321
321
ice_agent = put_in ( ice_agent . checklist [ pair . id ] , pair )
322
322
323
323
# try to feed data on closed candidate, it should be ignored
@@ -377,7 +377,7 @@ defmodule ExICE.Priv.ICEAgentTest do
377
377
378
378
assert ice_agent . state == :closed
379
379
assert ice_agent . gathering_state == :complete
380
- assert [ % { state: :failed } = pair ] = Map . values ( ice_agent . checklist )
380
+ assert [ % { state: :failed , valid?: false } = pair ] = Map . values ( ice_agent . checklist )
381
381
assert [ % { base: % { closed?: true } } ] = Map . values ( ice_agent . local_cands )
382
382
# make sure that sockets and remote cands were not cleared
383
383
assert [ _remote_cand ] = Map . values ( ice_agent . remote_cands )
@@ -468,7 +468,7 @@ defmodule ExICE.Priv.ICEAgentTest do
468
468
469
469
# mark pair as failed
470
470
[ pair ] = Map . values ( ice_agent . checklist )
471
- ice_agent = put_in ( ice_agent . checklist [ pair . id ] , % { pair | state: :failed } )
471
+ ice_agent = put_in ( ice_agent . checklist [ pair . id ] , % { pair | state: :failed , valid?: false } )
472
472
473
473
# clear ta_timer, ignore outgoing binding request that has been generated
474
474
ice_agent = ICEAgent . handle_ta_timeout ( ice_agent )
@@ -526,8 +526,7 @@ defmodule ExICE.Priv.ICEAgentTest do
526
526
527
527
# mark pair as failed
528
528
[ pair ] = Map . values ( ice_agent . checklist )
529
- ice_agent = put_in ( ice_agent . checklist [ pair . id ] , % { pair | state: :failed } )
530
-
529
+ ice_agent = put_in ( ice_agent . checklist [ pair . id ] , % { pair | state: :failed , valid?: false } )
531
530
# clear ta_timer, ignore outgoing binding request that has been generated
532
531
ice_agent = ICEAgent . handle_ta_timeout ( ice_agent )
533
532
assert ice_agent . ta_timer == nil
@@ -1259,6 +1258,9 @@ defmodule ExICE.Priv.ICEAgentTest do
1259
1258
end
1260
1259
end
1261
1260
1261
+ @ conn_check_byte_size 92
1262
+ @ conn_check_with_nomination_byte_size 96
1263
+
1262
1264
describe "connectivity check" do
1263
1265
setup do
1264
1266
ice_agent =
@@ -1592,7 +1594,7 @@ defmodule ExICE.Priv.ICEAgentTest do
1592
1594
resp
1593
1595
)
1594
1596
1595
- assert [ % CandidatePair { state: :failed } ] = Map . values ( ice_agent . checklist )
1597
+ assert [ % CandidatePair { state: :failed , valid?: false } ] = Map . values ( ice_agent . checklist )
1596
1598
assert [ new_pair ] = Map . values ( ice_agent . checklist )
1597
1599
assert new_pair . state == :failed
1598
1600
assert new_pair . responses_received == pair . responses_received
@@ -1639,6 +1641,89 @@ defmodule ExICE.Priv.ICEAgentTest do
1639
1641
1640
1642
assert ice_agent . state == :completed
1641
1643
end
1644
+
1645
+ test "failure on send" do
1646
+ # 1. replace candidate with the mock one that always fails to send data
1647
+ # 2. assert that after unsuccessful conn check sending, ice_agent moves conn pair to the failed state
1648
+
1649
+ ice_agent =
1650
+ ICEAgent . new (
1651
+ controlling_process: self ( ) ,
1652
+ role: :controlling ,
1653
+ if_discovery_module: IfDiscovery.MockSingle ,
1654
+ transport_module: Transport.Mock
1655
+ )
1656
+ |> ICEAgent . set_remote_credentials ( "someufrag" , "somepwd" )
1657
+ |> ICEAgent . gather_candidates ( )
1658
+ |> ICEAgent . add_remote_candidate ( @ remote_cand )
1659
+ |> ICEAgent . end_of_candidates ( )
1660
+
1661
+ assert ice_agent . gathering_state == :complete
1662
+
1663
+ # replace candidate with the mock one
1664
+ [ local_cand ] = Map . values ( ice_agent . local_cands )
1665
+ mock_cand = % Candidate.Mock { base: local_cand . base }
1666
+ ice_agent = % { ice_agent | local_cands: % { mock_cand . base . id => mock_cand } }
1667
+
1668
+ # try to send conn check
1669
+ ice_agent = ICEAgent . handle_ta_timeout ( ice_agent )
1670
+
1671
+ # assert that the candidate pair has moved to a failed state
1672
+ # and that the state was updated after the packet was discarded
1673
+ assert [
1674
+ % {
1675
+ state: :failed ,
1676
+ valid?: false ,
1677
+ packets_discarded_on_send: 1 ,
1678
+ bytes_discarded_on_send: @ conn_check_byte_size
1679
+ }
1680
+ ] = Map . values ( ice_agent . checklist )
1681
+
1682
+ assert ice_agent . state == :failed
1683
+ end
1684
+
1685
+ test "failure on send, when nominating" do
1686
+ # 1. make ice agent connected
1687
+ # 2. replace candidate with the mock one that always fails to send data
1688
+ # 3. assert that after unsuccessful nomination sending, ice_agent moves conn pair to the failed state
1689
+
1690
+ ice_agent =
1691
+ ICEAgent . new (
1692
+ controlling_process: self ( ) ,
1693
+ role: :controlling ,
1694
+ if_discovery_module: IfDiscovery.MockSingle ,
1695
+ transport_module: Transport.Mock
1696
+ )
1697
+ |> ICEAgent . set_remote_credentials ( "someufrag" , "somepwd" )
1698
+ |> ICEAgent . gather_candidates ( )
1699
+ |> ICEAgent . add_remote_candidate ( @ remote_cand )
1700
+
1701
+ assert ice_agent . gathering_state == :complete
1702
+
1703
+ # make ice_agent connected
1704
+ ice_agent = connect ( ice_agent )
1705
+
1706
+ # replace candidate with the mock one
1707
+ [ local_cand ] = Map . values ( ice_agent . local_cands )
1708
+ mock_cand = % Candidate.Mock { base: local_cand . base }
1709
+ ice_agent = % { ice_agent | local_cands: % { mock_cand . base . id => mock_cand } }
1710
+
1711
+ # trigger pair nomination
1712
+ ice_agent = ICEAgent . end_of_candidates ( ice_agent )
1713
+
1714
+ # assert that the candidate pair has moved to a failed state
1715
+ # and that the state was updated after the packet was discarded
1716
+ assert [
1717
+ % {
1718
+ state: :failed ,
1719
+ valid?: false ,
1720
+ packets_discarded_on_send: 1 ,
1721
+ bytes_discarded_on_send: @ conn_check_with_nomination_byte_size
1722
+ }
1723
+ ] = Map . values ( ice_agent . checklist )
1724
+
1725
+ assert ice_agent . state == :failed
1726
+ end
1642
1727
end
1643
1728
1644
1729
describe "connectivity check with aggressive nomination" do
@@ -2019,7 +2104,7 @@ defmodule ExICE.Priv.ICEAgentTest do
2019
2104
ice_agent = ICEAgent . handle_pair_timeout ( ice_agent )
2020
2105
2021
2106
# assert that the pair is marked as failed
2022
- assert [ % CandidatePair { state: :failed } ] = Map . values ( ice_agent . checklist )
2107
+ assert [ % CandidatePair { state: :failed , valid?: false } ] = Map . values ( ice_agent . checklist )
2023
2108
2024
2109
# trigger eoc timeout
2025
2110
ice_agent = ICEAgent . handle_eoc_timeout ( ice_agent )
@@ -2049,7 +2134,7 @@ defmodule ExICE.Priv.ICEAgentTest do
2049
2134
2050
2135
# mark pair as failed
2051
2136
[ pair ] = Map . values ( ice_agent . checklist )
2052
- ice_agent = put_in ( ice_agent . checklist [ pair . id ] , % { pair | state: :failed } )
2137
+ ice_agent = put_in ( ice_agent . checklist [ pair . id ] , % { pair | state: :failed , valid?: false } )
2053
2138
2054
2139
# set eoc flag
2055
2140
failed_ice_agent = ICEAgent . end_of_candidates ( ice_agent )
@@ -2568,8 +2653,8 @@ defmodule ExICE.Priv.ICEAgentTest do
2568
2653
test "candidate fails to send data when ice is connected" do
2569
2654
# 1. make ice agent connected
2570
2655
# 2. replace candidate with the mock one that always fails to send data
2571
- # 3. assert that after unsuccessful data sending, ice_agent moves to the failed state
2572
- # as there are no other pairs
2656
+ # 3. assert that after unsuccessful data sending, ice_agent doesn't move to the failed state
2657
+ # even when there is only one pair
2573
2658
2574
2659
ice_agent =
2575
2660
ICEAgent . new (
@@ -2595,10 +2680,18 @@ defmodule ExICE.Priv.ICEAgentTest do
2595
2680
# try to send some data
2596
2681
ice_agent = ICEAgent . send_data ( ice_agent , "somedata" )
2597
2682
2598
- # assert that local cand has been closed and the agent moved to the failed state
2599
- assert [ % { base: % { closed?: true } } ] = Map . values ( ice_agent . local_cands )
2600
- assert ice_agent . state == :failed
2601
- assert [ % { state: :failed } ] = Map . values ( ice_agent . checklist )
2683
+ # assert that the local candidate hasn't been closed and that the agent hasn't moved to a failed state
2684
+ assert [ % { base: % { closed?: false } } ] = Map . values ( ice_agent . local_cands )
2685
+ assert ice_agent . state == :connected
2686
+
2687
+ # assert that the local candidate's state was updated after the packet was discarded
2688
+ assert [
2689
+ % {
2690
+ state: :succeeded ,
2691
+ packets_discarded_on_send: 1 ,
2692
+ bytes_discarded_on_send: 8
2693
+ }
2694
+ ] = Map . values ( ice_agent . checklist )
2602
2695
end
2603
2696
2604
2697
test "relay connection" do
0 commit comments