mirror of
https://github.com/pion/webrtc.git
synced 2025-12-24 11:51:03 +08:00
Fix concurrent pc.GracefulClose
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -180,7 +182,7 @@ func TestPeerConnection_Close_DuringICE(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerConnection_CloseWithIncomingMessages(t *testing.T) {
|
||||
func TestPeerConnection_GracefulCloseWithIncomingMessages(t *testing.T) {
|
||||
// Limit runtime in case of deadlocks
|
||||
lim := test.TimeOut(time.Second * 20)
|
||||
defer lim.Stop()
|
||||
@@ -287,3 +289,41 @@ func TestPeerConnection_GracefulCloseWhileOpening(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerConnection_GracefulCloseConcurrent(t *testing.T) {
|
||||
// Limit runtime in case of deadlocks
|
||||
lim := test.TimeOut(time.Second * 10)
|
||||
defer lim.Stop()
|
||||
|
||||
for _, mixed := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("mixed_graceful=%t", mixed), func(t *testing.T) {
|
||||
report := test.CheckRoutinesStrict(t)
|
||||
defer report()
|
||||
|
||||
pc, err := NewPeerConnection(Configuration{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
const gracefulCloseConcurrency = 50
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(gracefulCloseConcurrency)
|
||||
for i := 0; i < gracefulCloseConcurrency; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
assert.NoError(t, pc.GracefulClose())
|
||||
}()
|
||||
}
|
||||
if !mixed {
|
||||
if err := pc.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if err := pc.GracefulClose(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user