(t *testing.T)
| 1007 | } |
| 1008 | |
| 1009 | func TestNativeHistogramConcurrency(t *testing.T) { |
| 1010 | if testing.Short() { |
| 1011 | t.Skip("Skipping test in short mode.") |
| 1012 | } |
| 1013 | |
| 1014 | rand.New(rand.NewSource(42)) |
| 1015 | |
| 1016 | it := func(n uint32) bool { |
| 1017 | ts := time.Now().Add(30 * time.Second).Unix() |
| 1018 | |
| 1019 | mutations := int(n%1e4 + 1e4) |
| 1020 | concLevel := int(n%5 + 1) |
| 1021 | total := mutations * concLevel |
| 1022 | |
| 1023 | var start, end sync.WaitGroup |
| 1024 | start.Add(1) |
| 1025 | end.Add(concLevel) |
| 1026 | |
| 1027 | his := NewHistogram(HistogramOpts{ |
| 1028 | Name: "test_native_histogram", |
| 1029 | Help: "This help is sparse.", |
| 1030 | NativeHistogramBucketFactor: 1.05, |
| 1031 | NativeHistogramZeroThreshold: 0.0000001, |
| 1032 | NativeHistogramMaxBucketNumber: 50, |
| 1033 | NativeHistogramMinResetDuration: time.Hour, // Comment out to test for totals below. |
| 1034 | NativeHistogramMaxZeroThreshold: 0.001, |
| 1035 | now: func() time.Time { |
| 1036 | return time.Unix(atomic.LoadInt64(&ts), 0) |
| 1037 | }, |
| 1038 | }) |
| 1039 | |
| 1040 | allVars := make([]float64, total) |
| 1041 | var sampleSum float64 |
| 1042 | for i := 0; i < concLevel; i++ { |
| 1043 | vals := make([]float64, mutations) |
| 1044 | for j := 0; j < mutations; j++ { |
| 1045 | v := rand.NormFloat64() |
| 1046 | vals[j] = v |
| 1047 | allVars[i*mutations+j] = v |
| 1048 | sampleSum += v |
| 1049 | } |
| 1050 | |
| 1051 | go func(vals []float64) { |
| 1052 | start.Wait() |
| 1053 | for i, v := range vals { |
| 1054 | // An observation every 1 to 10 seconds. |
| 1055 | atomic.AddInt64(&ts, rand.Int63n(10)+1) |
| 1056 | if i%2 == 0 { |
| 1057 | his.Observe(v) |
| 1058 | } else { |
| 1059 | his.(ExemplarObserver).ObserveWithExemplar(v, Labels{"foo": "bar"}) |
| 1060 | } |
| 1061 | } |
| 1062 | end.Done() |
| 1063 | }(vals) |
| 1064 | } |
| 1065 | sort.Float64s(allVars) |
| 1066 | start.Done() |
nothing calls this directly
no test coverage detected