(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func TestGaugeConcurrency(t *testing.T) { |
| 48 | it := func(n uint32) bool { |
| 49 | mutations := int(n % 10000) |
| 50 | concLevel := int(n%15 + 1) |
| 51 | |
| 52 | var start, end sync.WaitGroup |
| 53 | start.Add(1) |
| 54 | end.Add(concLevel) |
| 55 | |
| 56 | sStream := make(chan float64, mutations*concLevel) |
| 57 | result := make(chan float64) |
| 58 | done := make(chan struct{}) |
| 59 | |
| 60 | go listenGaugeStream(sStream, result, done) |
| 61 | go func() { |
| 62 | end.Wait() |
| 63 | close(done) |
| 64 | }() |
| 65 | |
| 66 | gge := NewGauge(GaugeOpts{ |
| 67 | Name: "test_gauge", |
| 68 | Help: "no help can be found here", |
| 69 | }) |
| 70 | for i := 0; i < concLevel; i++ { |
| 71 | vals := make([]float64, mutations) |
| 72 | for j := 0; j < mutations; j++ { |
| 73 | vals[j] = rand.Float64() - 0.5 |
| 74 | } |
| 75 | |
| 76 | go func(vals []float64) { |
| 77 | start.Wait() |
| 78 | for _, v := range vals { |
| 79 | sStream <- v |
| 80 | gge.Add(v) |
| 81 | } |
| 82 | end.Done() |
| 83 | }(vals) |
| 84 | } |
| 85 | start.Done() |
| 86 | |
| 87 | if expected, got := <-result, math.Float64frombits(gge.(*gauge).valBits); math.Abs(expected-got) > 0.000001 { |
| 88 | t.Fatalf("expected approx. %f, got %f", expected, got) |
| 89 | return false |
| 90 | } |
| 91 | return true |
| 92 | } |
| 93 | |
| 94 | if err := quick.Check(it, nil); err != nil { |
| 95 | t.Fatal(err) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func TestGaugeVecConcurrency(t *testing.T) { |
| 100 | it := func(n uint32) bool { |
nothing calls this directly
no test coverage detected