cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
h2mux/bytes_counter_test.go
23lines · modecode
| 1 | package h2mux |
| 2 | |
| 3 | import ( |
| 4 | "sync" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/stretchr/testify/assert" |
| 8 | ) |
| 9 | |
| 10 | func TestCounter(t *testing.T) { |
| 11 | var wg sync.WaitGroup |
| 12 | wg.Add(dataPoints) |
| 13 | c := AtomicCounter{} |
| 14 | for i := 0; i < dataPoints; i++ { |
| 15 | go func() { |
| 16 | defer wg.Done() |
| 17 | c.IncrementBy(uint64(1)) |
| 18 | }() |
| 19 | } |
| 20 | wg.Wait() |
| 21 | assert.Equal(t, uint64(dataPoints), c.Count()) |
| 22 | assert.Equal(t, uint64(0), c.Count()) |
| 23 | } |