parallel_test.go 431 B

123456789101112131415161718192021222324
  1. package fx
  2. import (
  3. "sync/atomic"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestParallel(t *testing.T) {
  9. var count int32
  10. Parallel(func() {
  11. time.Sleep(time.Millisecond * 100)
  12. atomic.AddInt32(&count, 1)
  13. }, func() {
  14. time.Sleep(time.Millisecond * 100)
  15. atomic.AddInt32(&count, 2)
  16. }, func() {
  17. time.Sleep(time.Millisecond * 100)
  18. atomic.AddInt32(&count, 3)
  19. })
  20. assert.Equal(t, int32(6), count)
  21. }