Skip to content

Commit

Permalink
Eliminate goroutine leak in histogram stress test (#547)
Browse files Browse the repository at this point in the history
Update copyright date to when file was created (2020)
Create random numbers between 0 and 100 to more evenly match the
buckets defined in the histogram test (25, 50, 75)
  • Loading branch information
evantorrie authored Mar 12, 2020
1 parent 2ccddfe commit 46ac030
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sdk/metric/histogram_stress_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019, OpenTelemetry Authors
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,10 +33,17 @@ func TestStressInt64Histogram(t *testing.T) {
desc := metric.NewDescriptor("some_metric", metric.MeasureKind, nil, "", "", core.Int64NumberKind)
h := histogram.New(desc, []core.Number{core.NewInt64Number(25), core.NewInt64Number(50), core.NewInt64Number(75)})

ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
go func() {
rnd := rand.New(rand.NewSource(time.Now().Unix()))
for {
_ = h.Update(context.Background(), core.NewInt64Number(rnd.Int63()), desc)
select {
case <-ctx.Done():
return
default:
_ = h.Update(ctx, core.NewInt64Number(rnd.Int63()%100), desc)
}
}
}()

Expand Down

0 comments on commit 46ac030

Please sign in to comment.