(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestSharedBufferConcurrent(t *testing.T) { |
| 76 | const threads = 10 |
| 77 | const iters = 200 |
| 78 | |
| 79 | buf := NewSharedBuffer(3) |
| 80 | done := make(chan bool) |
| 81 | |
| 82 | for i := 0; i < threads; i++ { |
| 83 | go func() { |
| 84 | ch := buf.NewChannel() |
| 85 | for i := 0; i < iters; i++ { |
| 86 | ch.In() <- i |
| 87 | val := <-ch.Out() |
| 88 | if val.(int) != i { |
| 89 | t.Error("Mismatched value out of channel") |
| 90 | } |
| 91 | } |
| 92 | ch.Close() |
| 93 | done <- true |
| 94 | }() |
| 95 | } |
| 96 | |
| 97 | for i := 0; i < threads; i++ { |
| 98 | <-done |
| 99 | } |
| 100 | close(done) |
| 101 | buf.Close() |
| 102 | } |
| 103 | |
| 104 | func ExampleSharedBuffer() { |
| 105 | // never more than 3 elements in the pipeline at once |
nothing calls this directly
no test coverage detected
searching dependent graphs…