github.com/pion/webrtc/v3@v3.2.24/operations_test.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestOperations_Enqueue(t *testing.T) {
    13  	ops := newOperations()
    14  	for i := 0; i < 100; i++ {
    15  		results := make([]int, 16)
    16  		for i := range results {
    17  			func(j int) {
    18  				ops.Enqueue(func() {
    19  					results[j] = j * j
    20  				})
    21  			}(i)
    22  		}
    23  
    24  		ops.Done()
    25  		expected := []int{0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225}
    26  		assert.Equal(t, len(expected), len(results))
    27  		assert.Equal(t, expected, results)
    28  	}
    29  }
    30  
    31  func TestOperations_Done(*testing.T) {
    32  	ops := newOperations()
    33  	ops.Done()
    34  }