mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-19 15:19:55 +00:00
Fix test
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
package peer
|
package peer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -79,31 +79,30 @@ func TestConn_OnRemoteOffer(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
onNewOffeChan := make(chan struct{})
|
||||||
wg.Add(2)
|
|
||||||
go func() {
|
|
||||||
<-conn.handshaker.remoteOffersCh
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
conn.handshaker.AddOnNewOfferListener(func(remoteOfferAnswer *OfferAnswer) {
|
||||||
for {
|
onNewOffeChan <- struct{}{}
|
||||||
accepted := conn.OnRemoteOffer(OfferAnswer{
|
})
|
||||||
IceCredentials: IceCredentials{
|
|
||||||
UFrag: "test",
|
|
||||||
Pwd: "test",
|
|
||||||
},
|
|
||||||
WgListenPort: 0,
|
|
||||||
Version: "",
|
|
||||||
})
|
|
||||||
if accepted {
|
|
||||||
wg.Done()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Wait()
|
conn.OnRemoteOffer(OfferAnswer{
|
||||||
|
IceCredentials: IceCredentials{
|
||||||
|
UFrag: "test",
|
||||||
|
Pwd: "test",
|
||||||
|
},
|
||||||
|
WgListenPort: 0,
|
||||||
|
Version: "",
|
||||||
|
})
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-onNewOffeChan:
|
||||||
|
// success
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Error("expected to receive a new offer notification, but timed out")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConn_OnRemoteAnswer(t *testing.T) {
|
func TestConn_OnRemoteAnswer(t *testing.T) {
|
||||||
@@ -119,31 +118,29 @@ func TestConn_OnRemoteAnswer(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
onNewOffeChan := make(chan struct{})
|
||||||
wg.Add(2)
|
|
||||||
go func() {
|
|
||||||
<-conn.handshaker.remoteAnswerCh
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
conn.handshaker.AddOnNewOfferListener(func(remoteOfferAnswer *OfferAnswer) {
|
||||||
for {
|
onNewOffeChan <- struct{}{}
|
||||||
accepted := conn.OnRemoteAnswer(OfferAnswer{
|
})
|
||||||
IceCredentials: IceCredentials{
|
|
||||||
UFrag: "test",
|
|
||||||
Pwd: "test",
|
|
||||||
},
|
|
||||||
WgListenPort: 0,
|
|
||||||
Version: "",
|
|
||||||
})
|
|
||||||
if accepted {
|
|
||||||
wg.Done()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Wait()
|
conn.OnRemoteAnswer(OfferAnswer{
|
||||||
|
IceCredentials: IceCredentials{
|
||||||
|
UFrag: "test",
|
||||||
|
Pwd: "test",
|
||||||
|
},
|
||||||
|
WgListenPort: 0,
|
||||||
|
Version: "",
|
||||||
|
})
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-onNewOffeChan:
|
||||||
|
// success
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Error("expected to receive a new offer notification, but timed out")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConn_presharedKey(t *testing.T) {
|
func TestConn_presharedKey(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user