Repository: pion/ice
Pull request #289 (2020-10-11 06:11:03)

Add failing test for #288
ICE-lite Agent doesn't detect disconnects


codecov[bot]: # [Codecov](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=h1) Report
> Merging [#289](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=desc) into [master](https://codecov.io/gh/pion/ice/commit/9f7fab666f67a9493ba98d388451ee9e17f5d7b7?el=desc) will **decrease** coverage by `50.52%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pion/ice/pull/289/graphs/tree.svg?width=650&height=150&src=pr&token=1ivIyHDzva)](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master     #289       +/-   ##
===========================================
- Coverage   79.41%   28.88%   -50.53%     
===========================================
  Files          31       31               
  Lines        2283     2292        +9     
===========================================
- Hits         1813      662     -1151     
- Misses        332     1602     +1270     
+ Partials      138       28      -110     
```

| Flag | Coverage Δ | |
|---|---|---|
| #go | `?` | |
| #wasm | `28.88% <ø> (-0.12%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [candidate\_peer\_reflexive.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-Y2FuZGlkYXRlX3BlZXJfcmVmbGV4aXZlLmdv) | `0.00% <0.00%> (-84.62%)` | :arrow_down: |
| [agent\_config.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-YWdlbnRfY29uZmlnLmdv) | `0.00% <0.00%> (-84.38%)` | :arrow_down: |
| [transport.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-dHJhbnNwb3J0Lmdv) | `0.00% <0.00%> (-82.70%)` | :arrow_down: |
| [agent\_stats.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-YWdlbnRfc3RhdHMuZ28=) | `0.00% <0.00%> (-82.36%)` | :arrow_down: |
| [agent.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-YWdlbnQuZ28=) | `0.00% <0.00%> (-81.70%)` | :arrow_down: |
| [stun.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-c3R1bi5nbw==) | `0.00% <0.00%> (-75.00%)` | :arrow_down: |
| [selection.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-c2VsZWN0aW9uLmdv) | `0.00% <0.00%> (-74.25%)` | :arrow_down: |
| [gather.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-Z2F0aGVyLmdv) | `0.00% <0.00%> (-70.59%)` | :arrow_down: |
| [mdns.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-bWRucy5nbw==) | `0.00% <0.00%> (-66.67%)` | :arrow_down: |
| [context.go](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree#diff-Y29udGV4dC5nbw==) | `0.00% <0.00%> (-66.67%)` | :arrow_down: |
| ... and [9 more](https://codecov.io/gh/pion/ice/pull/289/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=footer). Last update [9f7fab6...8caa623](https://codecov.io/gh/pion/ice/pull/289?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index f28eda0..788a292 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
 * [Kory Miller](https://github.com/korymiller1489)
 * [ZHENK](https://github.com/scorpionknifes)
 * [Assad Obaid](https://github.com/assadobaid)
+* [Antoine Baché](https://github.com/Antonito)
 
 ### License
 MIT License - see [LICENSE](LICENSE) for full text
diff --git a/selection.go b/selection.go
index df5d1f9..e0cfb10 100644
--- a/selection.go
+++ b/selection.go
@@ -281,5 +281,7 @@ func (s *liteSelector) ContactCandidates() {
 		// TODO: implement lite controlling agent. For now falling back to full agent.
 		// This only happens if both peers are lite. See RFC 8445 S6.1.1 and S6.2
 		s.pairCandidateSelector.ContactCandidates()
+	} else if v, ok := s.pairCandidateSelector.(*controlledSelector); ok {
+		v.agent.validateSelectedPair()
 	}
 }


Test patch:
diff --git a/agent_test.go b/agent_test.go
index b635cd6..05361f3 100644
--- a/agent_test.go
+++ b/agent_test.go
@@ -5,6 +5,7 @@ package ice
 import (
 	"context"
 	"errors"
+	"fmt"
 	"net"
 	"strconv"
 	"sync"
@@ -1626,3 +1627,62 @@ func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
 	assert.NoError(t, aAgent.Close())
 	assert.NoError(t, bAgent.Close())
 }
+
+// Assert that a Lite agent goes to disconnected and failed
+func TestLiteLifecycle(t *testing.T) {
+	report := test.CheckRoutines(t)
+	defer report()
+
+	lim := test.TimeOut(time.Second * 30)
+	defer lim.Stop()
+
+	aNotifier, aConnected := onConnected()
+
+	aAgent, err := NewAgent(&AgentConfig{
+		NetworkTypes:     supportedNetworkTypes(),
+		MulticastDNSMode: MulticastDNSModeDisabled,
+	})
+	require.NoError(t, err)
+	require.NoError(t, aAgent.OnConnectionStateChange(aNotifier))
+
+	disconnectedDuration := time.Second
+	failedDuration := time.Second
+	KeepaliveInterval := time.Duration(0)
+	bAgent, err := NewAgent(&AgentConfig{
+		Lite:                true,
+		CandidateTypes:      []CandidateType{CandidateTypeHost},
+		NetworkTypes:        supportedNetworkTypes(),
+		MulticastDNSMode:    MulticastDNSModeDisabled,
+		DisconnectedTimeout: &disconnectedDuration,
+		FailedTimeout:       &failedDuration,
+		KeepaliveInterval:   &KeepaliveInterval,
+		checkInterval:       500 * time.Millisecond,
+	})
+	require.NoError(t, err)
+
+	bConnected := make(chan interface{})
+	bDisconnected := make(chan interface{})
+	bFailed := make(chan interface{})
+
+	require.NoError(t, bAgent.OnConnectionStateChange(func(c ConnectionState) {
+		fmt.Println(c)
+		switch c {
+		case ConnectionStateConnected:
+			close(bConnected)
+		case ConnectionStateDisconnected:
+			close(bDisconnected)
+		case ConnectionStateFailed:
+			close(bFailed)
+		}
+	}))
+
+	connectWithVNet(bAgent, aAgent)
+
+	<-aConnected
+	<-bConnected
+	assert.NoError(t, aAgent.Close())
+
+	<-bDisconnected
+	<-bFailed
+	assert.NoError(t, bAgent.Close())
+}