MCPcopy
hub / github.com/uber-go/zap / TestNew_Race

Function TestNew_Race

internal/pool/pool_test.go:78–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

76}
77
78func TestNew_Race(t *testing.T) {
79 p := pool.New(func() *pooledValue[int] {
80 return &pooledValue[int]{
81 value: -1,
82 }
83 })
84
85 var wg sync.WaitGroup
86 defer wg.Wait()
87
88 // Run a number of goroutines that read and write pool object fields to
89 // tease out races.
90 for i := 0; i < 1_000; i++ {
91 i := i
92
93 wg.Add(1)
94 go func() {
95 defer wg.Done()
96
97 x := p.Get()
98 defer p.Put(x)
99
100 // Must both read and write the field.
101 if n := x.value; n >= -1 {
102 x.value = i
103 }
104 }()
105 }
106}

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
PutMethod · 0.80
AddMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected