Skip to content

Commit e116405

Browse files
committed
Fix mDNS connection tests on macOS
1 parent 2ebb566 commit e116405

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

peerconnection_go_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"math/big"
1717
"net"
1818
"regexp"
19+
"runtime"
1920
"slices"
2021
"strings"
2122
"sync"
@@ -810,6 +811,19 @@ func TestPopulateLocalCandidates(t *testing.T) {
810811
})
811812
}
812813

814+
func configureMulticastDNS(s *SettingEngine) {
815+
s.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
816+
if runtime.GOOS != "darwin" {
817+
return
818+
}
819+
820+
s.SetNetworkTypes([]NetworkType{NetworkTypeUDP4})
821+
s.SetIncludeLoopbackCandidate(true)
822+
s.SetIPFilter(func(ip net.IP) bool {
823+
return ip.IsLoopback() && ip.To4() != nil
824+
})
825+
}
826+
813827
// Assert that two agents that only generate mDNS candidates can connect.
814828
func TestMulticastDNSCandidates(t *testing.T) {
815829
lim := test.TimeOut(time.Second * 30)
@@ -819,20 +833,20 @@ func TestMulticastDNSCandidates(t *testing.T) {
819833
defer report()
820834

821835
s := SettingEngine{}
822-
s.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
836+
configureMulticastDNS(&s)
823837

824838
pcOffer, pcAnswer, err := NewAPI(WithSettingEngine(s)).newPair(Configuration{})
825-
assert.NoError(t, err)
826-
827-
assert.NoError(t, signalPair(pcOffer, pcAnswer))
839+
require.NoError(t, err)
840+
defer closePairNow(t, pcOffer, pcAnswer)
828841

829842
onDataChannel, onDataChannelCancel := context.WithCancel(context.Background())
843+
defer onDataChannelCancel()
830844
pcAnswer.OnDataChannel(func(*DataChannel) {
831845
onDataChannelCancel()
832846
})
833-
<-onDataChannel.Done()
834847

835-
closePairNow(t, pcOffer, pcAnswer)
848+
require.NoError(t, signalPair(pcOffer, pcAnswer))
849+
<-onDataChannel.Done()
836850
}
837851

838852
func TestMulticastDNSHostNameConnection(t *testing.T) {
@@ -849,11 +863,11 @@ func TestMulticastDNSHostNameConnection(t *testing.T) {
849863
}
850864

851865
offerSettingEngine := SettingEngine{}
852-
offerSettingEngine.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
866+
configureMulticastDNS(&offerSettingEngine)
853867
offerSettingEngine.SetMulticastDNSHostName(offerHostName)
854868

855869
answerSettingEngine := SettingEngine{}
856-
answerSettingEngine.SetICEMulticastDNSMode(ice.MulticastDNSModeQueryAndGather)
870+
configureMulticastDNS(&answerSettingEngine)
857871
answerSettingEngine.SetMulticastDNSHostName(answerHostName)
858872

859873
pcOffer, err := NewAPI(WithSettingEngine(offerSettingEngine)).NewPeerConnection(Configuration{})

0 commit comments

Comments
 (0)