operations_test.go 684 B

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