Skip to content

Commit b6a5e5a

Browse files
committed
Actually use random values
1 parent ca6778b commit b6a5e5a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponential_bucket_histogram_aggregation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import random as insecure_random
15+
from random import Random, randrange
16+
from inspect import currentframe
1617
from itertools import permutations
1718
from logging import WARNING
1819
from math import ldexp
19-
from sys import float_info
20+
from sys import float_info, maxsize
2021
from types import MethodType
2122
from unittest.mock import Mock, patch
2223

@@ -1092,10 +1093,17 @@ def collect_and_validate() -> None:
10921093
assert result.zero_count == len([v for v in values if v == 0])
10931094
assert scale >= 3
10941095

1095-
random = insecure_random.Random("opentelemetry2")
1096+
seed = randrange(maxsize)
1097+
# This test case is executed with random values every time. In order to
1098+
# run this test case with the same values used in a previous execution,
1099+
# check the value printed by that previous execution of this test case
1100+
# and use the same value for the seed variable in the line below.
1101+
# seed = 4539544373807492135
1102+
print(f"seed for {currentframe().f_code.co_name} is {seed}")
1103+
10961104
values = []
10971105
for i in range(2000):
1098-
value = random.randint(0, 1000)
1106+
value = Random(seed).randint(0, 1000)
10991107
values.append(value)
11001108
histogram.aggregate(Measurement(value, Mock()))
11011109
if i % 20 == 0:

0 commit comments

Comments
 (0)