2020-03-25 23:47:17 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2020-03-11 20:12:23 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package metric_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-06-13 09:55:01 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-09-27 17:51:47 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/metrictest"
|
2020-11-11 17:24:12 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/number"
|
2021-08-12 01:02:28 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/sdkapi"
|
2020-03-11 20:12:23 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStressInt64Histogram(t *testing.T) {
|
2021-09-27 17:51:47 +02:00
|
|
|
desc := metrictest.NewDescriptor("some_metric", sdkapi.HistogramInstrumentKind, number.Int64Kind)
|
2020-06-13 09:55:01 +02:00
|
|
|
|
2021-01-16 01:29:02 +02:00
|
|
|
alloc := histogram.New(2, &desc, histogram.WithExplicitBoundaries([]float64{25, 50, 75}))
|
2020-06-13 09:55:01 +02:00
|
|
|
h, ckpt := &alloc[0], &alloc[1]
|
2020-03-11 20:12:23 +02:00
|
|
|
|
2020-03-13 00:37:06 +02:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
2020-03-11 20:12:23 +02:00
|
|
|
go func() {
|
|
|
|
rnd := rand.New(rand.NewSource(time.Now().Unix()))
|
|
|
|
for {
|
2020-03-13 00:37:06 +02:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
2020-11-11 17:24:12 +02:00
|
|
|
_ = h.Update(ctx, number.NewInt64Number(rnd.Int63()%100), &desc)
|
2020-03-13 00:37:06 +02:00
|
|
|
}
|
2020-03-11 20:12:23 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
startTime := time.Now()
|
|
|
|
for time.Since(startTime) < time.Second {
|
2020-06-23 19:41:11 +02:00
|
|
|
require.NoError(t, h.SynchronizedMove(ckpt, &desc))
|
2020-03-11 20:12:23 +02:00
|
|
|
|
2020-06-13 09:55:01 +02:00
|
|
|
b, _ := ckpt.Histogram()
|
|
|
|
c, _ := ckpt.Count()
|
2020-03-11 20:12:23 +02:00
|
|
|
|
2021-01-06 09:17:20 +02:00
|
|
|
var realCount uint64
|
2020-03-11 20:12:23 +02:00
|
|
|
for _, c := range b.Counts {
|
2021-01-06 09:17:20 +02:00
|
|
|
realCount += c
|
2020-03-11 20:12:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if realCount != c {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|