diff options
author | Andrew Dolgov <[email protected]> | 2023-04-09 20:50:33 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2023-04-09 20:50:33 +0300 |
commit | 8f3646a9c93a06f76f6abb31020fdb74b4b1fc59 (patch) | |
tree | 4e6c9f39e0623ef70bedfee014f1bd20603f89ad /vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php | |
parent | a37eab2610a0a2bcb655258781c1c7e925dc94c0 (diff) |
exp: jaeger tracing
Diffstat (limited to 'vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php')
-rw-r--r-- | vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php new file mode 100644 index 000000000..2840ebf8c --- /dev/null +++ b/vendor/jonahgeorge/jaeger-client-php/tests/Jaeger/Sampler/ProbablisticSamplerTest.php @@ -0,0 +1,68 @@ +<?php + +namespace Jaeger\Tests\Sampler; + +use Jaeger\Sampler\ProbabilisticSampler; +use OutOfBoundsException; +use PHPUnit\Framework\TestCase; +use const Jaeger\SAMPLER_PARAM_TAG_KEY; +use const Jaeger\SAMPLER_TYPE_PROBABILISTIC; +use const Jaeger\SAMPLER_TYPE_TAG_KEY; + +class ProbablisticSamplerTest extends TestCase +{ + /** + * @test + * @dataProvider samplerProvider + * @param float $rate + * @param mixed $traceId + * @param bool $decision + */ + public function shouldDetermineWhetherOrTraceShouldBeSampled($rate, $traceId, $decision) + { + $sampler = new ProbabilisticSampler($rate); + + list($sampled, $tags) = $sampler->isSampled($traceId); + + $this->assertEquals($decision, $sampled); + $this->assertEquals([ + SAMPLER_TYPE_TAG_KEY => SAMPLER_TYPE_PROBABILISTIC, + SAMPLER_PARAM_TAG_KEY => $rate, + ], $tags); + + $sampler->close(); + } + + public function samplerProvider() + { + return [ + [1.0, PHP_INT_MAX-1, true], + [0, 0, false], + [0.5, PHP_INT_MIN + 10, true], + [0.5, PHP_INT_MAX - 10, false], + ]; + } + + /** + * @test + * @dataProvider rateProvider + * @param mixed $rate + */ + public function shouldThrowOutOfBoundsExceptionInCaseOfInvalidRate($rate) + { + $this->expectException(OutOfBoundsException::class); + $this->expectExceptionMessage('Sampling rate must be between 0.0 and 1.0.'); + + new ProbabilisticSampler($rate); + } + + public function rateProvider() + { + return [ + [1.1], + [-0.1], + [PHP_INT_MAX], + [PHP_INT_MIN], + ]; + } +} |