diff --git a/datachannel_test.go b/datachannel_test.go index 5969da815d4..4901faa3285 100644 --- a/datachannel_test.go +++ b/datachannel_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + "github.com/pion/ice/v3" "github.com/pion/transport/v3/test" "github.com/stretchr/testify/assert" ) @@ -360,6 +361,17 @@ func TestDataChannel_Close(t *testing.T) { assert.NoError(t, dc.Close()) closePairNow(t, offerPC, answerPC) }) + + t.Run("Close after PeerConnection With Mux Closed", func(t *testing.T) { + offerPC, answerPC, err := newPairWithMux() + assert.NoError(t, err) + + dc, err := offerPC.CreateDataChannel(expectedLabel, nil) + assert.NoError(t, err) + + closePairNow(t, offerPC, answerPC) + assert.NoError(t, dc.Close()) + }) } func TestDataChannelParameters(t *testing.T) { @@ -518,3 +530,30 @@ func TestDataChannelParameters(t *testing.T) { closeReliabilityParamTest(t, offerPC, answerPC, done) }) } + +func newPairWithMux() (*PeerConnection, *PeerConnection, error) { + settingEngine := SettingEngine{} + + // Configure our SettingEngine to use our UDPMux. By default a PeerConnection has + // no global state. The API+SettingEngine allows the user to share state between them. + // In this case we are sharing our listening port across many. + // Listen on UDP Port 8443, will be used for all WebRTC traffic + mux, err := ice.NewMultiUDPMuxFromPort(8443) + if err != nil { + panic(err) + } + + settingEngine.SetICEUDPMux(mux) + api := NewAPI(WithSettingEngine(settingEngine)) + pca, err := api.NewPeerConnection(Configuration{}) + if err != nil { + return nil, nil, err + } + + pcb, err := NewPeerConnection(Configuration{}) + if err != nil { + return nil, nil, err + } + + return pca, pcb, nil +}