...

Source file src/go.mongodb.org/mongo-driver/internal/rand/race_test.go

Documentation: go.mongodb.org/mongo-driver/internal/rand

     1  // Copied from https://cs.opensource.google/go/x/exp/+/24438e51023af3bfc1db8aed43c1342817e8cfcd:rand/race_test.go
     2  
     3  // Copyright 2016 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package rand
     8  
     9  import (
    10  	"sync"
    11  	"testing"
    12  )
    13  
    14  // TestConcurrent exercises the rand API concurrently, triggering situations
    15  // where the race detector is likely to detect issues.
    16  func TestConcurrent(t *testing.T) {
    17  	const (
    18  		numRoutines = 10
    19  		numCycles   = 10
    20  	)
    21  	var wg sync.WaitGroup
    22  	defer wg.Wait()
    23  	wg.Add(numRoutines)
    24  	for i := 0; i < numRoutines; i++ {
    25  		go func(i int) {
    26  			defer wg.Done()
    27  			buf := make([]byte, 997)
    28  			for j := 0; j < numCycles; j++ {
    29  				var seed uint64
    30  				seed += uint64(ExpFloat64())
    31  				seed += uint64(Float32())
    32  				seed += uint64(Float64())
    33  				seed += uint64(Intn(Int()))
    34  				seed += uint64(Int31n(Int31()))
    35  				seed += uint64(Int63n(Int63()))
    36  				seed += uint64(NormFloat64())
    37  				seed += uint64(Uint32())
    38  				seed += uint64(Uint64())
    39  				for _, p := range Perm(10) {
    40  					seed += uint64(p)
    41  				}
    42  				Read(buf)
    43  				for _, b := range buf {
    44  					seed += uint64(b)
    45  				}
    46  				Seed(uint64(i*j) * seed)
    47  			}
    48  		}(i)
    49  	}
    50  }
    51  

View as plain text