(t *testing.T)
| 71 | } |
| 72 | |
| 73 | func TestBuffer_Concurrent(t *testing.T) { |
| 74 | t.Parallel() |
| 75 | var b Buffer |
| 76 | var wg sync.WaitGroup |
| 77 | |
| 78 | const writers = 100 |
| 79 | for i := range writers { |
| 80 | wg.Go(func() { |
| 81 | _, _ = b.Write(fmt.Appendf(nil, "%03d", i)) |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | // Concurrent readers should not race with writers. |
| 86 | for range 50 { |
| 87 | wg.Go(func() { |
| 88 | _ = b.String() |
| 89 | _ = b.Len() |
| 90 | _ = b.Bytes() |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | wg.Wait() |
| 95 | assert.Equal(t, writers*3, b.Len()) |
| 96 | } |