Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 9f22f68

Browse files
authored
Add rounding fix for adaptive sampling unit test (#20)
Signed-off-by: Isaac Hier <[email protected]>
1 parent aeefccc commit 9f22f68

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/jaegertracing/samplers/ProbabilisticSampler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ProbabilisticSampler : public Sampler {
5555

5656
static uint64_t computeSamplingBoundary(long double samplingRate)
5757
{
58-
const long double maxRandNumber = kMaxRandomNumber;
58+
const auto maxRandNumber = static_cast<long double>(kMaxRandomNumber);
5959
const auto samplingBoundary = samplingRate * maxRandNumber;
6060

6161
// Protect against overflow in case samplingBoundary rounds

src/jaegertracing/samplers/SamplerTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ namespace {
3838
constexpr auto kTestOperationName = "op";
3939
constexpr auto kTestFirstTimeOperationName = "firstTimeOp";
4040
constexpr auto kTestDefaultSamplingProbability = 0.5;
41-
constexpr auto kTestMaxID = std::numeric_limits<uint64_t>::max() / 2 + 1;
41+
constexpr auto kTestMaxID =
42+
static_cast<long double>(std::numeric_limits<uint64_t>::max()) / 2.0 + 1;
4243
constexpr auto kTestDefaultMaxOperations = 10;
4344

4445
const Tag testProbablisticExpectedTags[] = {
@@ -216,7 +217,8 @@ TEST(Sampler, testAdaptiveSampler)
216217
ASSERT_FALSE(result.isSampled());
217218

218219
result =
219-
sampler.isSampled(TraceID(0, kTestMaxID), kTestFirstTimeOperationName);
220+
sampler.isSampled(TraceID(0, kTestMaxID - 20),
221+
kTestFirstTimeOperationName);
220222
ASSERT_TRUE(result.isSampled());
221223
CMP_TAGS(testProbablisticExpectedTags, result.tags());
222224
}

0 commit comments

Comments
 (0)