Make onNegotiationNeeded conform to spec

- Removes non-canon logic
This commit is contained in:
Eric Daniels
2024-06-24 10:54:41 -04:00
parent d56bead6a6
commit 1bb9fa9020
5 changed files with 66 additions and 96 deletions

View File

@@ -4,19 +4,31 @@
package webrtc
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOperations_Enqueue(t *testing.T) {
ops := newOperations()
for i := 0; i < 100; i++ {
updateNegotiationNeededFlagOnEmptyChain := &atomicBool{}
onNegotiationNeededCalledCount := 0
var onNegotiationNeededCalledCountMu sync.Mutex
ops := newOperations(updateNegotiationNeededFlagOnEmptyChain, func() {
onNegotiationNeededCalledCountMu.Lock()
onNegotiationNeededCalledCount++
onNegotiationNeededCalledCountMu.Unlock()
})
for resultSet := 0; resultSet < 100; resultSet++ {
results := make([]int, 16)
resultSetCopy := resultSet
for i := range results {
func(j int) {
ops.Enqueue(func() {
results[j] = j * j
if resultSetCopy > 50 {
updateNegotiationNeededFlagOnEmptyChain.set(true)
}
})
}(i)
}
@@ -26,9 +38,13 @@ func TestOperations_Enqueue(t *testing.T) {
assert.Equal(t, len(expected), len(results))
assert.Equal(t, expected, results)
}
onNegotiationNeededCalledCountMu.Lock()
defer onNegotiationNeededCalledCountMu.Unlock()
assert.NotEqual(t, onNegotiationNeededCalledCount, 0)
}
func TestOperations_Done(*testing.T) {
ops := newOperations()
ops := newOperations(&atomicBool{}, func() {
})
ops.Done()
}