| 110 | } |
| 111 | |
| 112 | func TestWaitBuffer_ConcurrentWrites(t *testing.T) { |
| 113 | t.Parallel() |
| 114 | |
| 115 | wb := testutil.NewWaitBuffer() |
| 116 | var wg sync.WaitGroup |
| 117 | const writers = 10 |
| 118 | const iterations = 100 |
| 119 | wg.Add(writers) |
| 120 | for i := range writers { |
| 121 | go func() { |
| 122 | defer wg.Done() |
| 123 | for j := range iterations { |
| 124 | _, _ = wb.Write([]byte(fmt.Sprintf("w%d-%d ", i, j))) |
| 125 | } |
| 126 | }() |
| 127 | } |
| 128 | wg.Wait() |
| 129 | |
| 130 | // Every write should have landed; verify no data was lost by |
| 131 | // checking the length is at least as large as expected. |
| 132 | assert.GreaterOrEqual(t, len(wb.Bytes()), writers*iterations) |
| 133 | } |
| 134 | |
| 135 | func TestWaitBuffer_WaitFor_BackgroundGoroutine(t *testing.T) { |
| 136 | t.Parallel() |