github.com/lingyao2333/mo-zero@v1.4.1/core/syncx/atomicfloat64_test.go (about)

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