atomicfloat64_test.go 351 B

123456789101112131415161718192021222324
  1. package syncx
  2. import (
  3. "sync"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestAtomicFloat64(t *testing.T) {
  8. f := ForAtomicFloat64(100)
  9. var wg sync.WaitGroup
  10. for i := 0; i < 5; i++ {
  11. wg.Add(1)
  12. go func() {
  13. for i := 0; i < 100; i++ {
  14. f.Add(1)
  15. }
  16. wg.Done()
  17. }()
  18. }
  19. wg.Wait()
  20. assert.Equal(t, float64(600), f.Load())
  21. }