X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fincludes%2Flibs%2FSamplingStatsdClientTest.php;h=9a489303a7a3d9db4b94cd441d927e2b5e845042;hb=f40e4c6b367fcf0e3e10b1d08d716f3382f4b755;hp=1ebe55110f99bc13c630c9462244462a7fe21ff1;hpb=734ca2b4d2a1246fb0ea1e54b861ab423ab5e257;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php index 1ebe55110f..9a489303a7 100644 --- a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php +++ b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php @@ -32,12 +32,35 @@ class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase { return [ // $data, $sampleRate, $seed, $expectWrite - [ $unsampled, 1, 0 /*0.44*/, $unsampled ], - [ $sampled, 1, 0 /*0.44*/, null ], - [ $sampled, 1, 4 /*0.03*/, $sampled ], - [ $unsampled, 0.1, 4 /*0.03*/, $sampled ], - [ $sampled, 0.5, 0 /*0.44*/, null ], - [ $sampled, 0.5, 4 /*0.03*/, $sampled ], + [ $unsampled, 1, 0 /*0.44*/, true ], + [ $sampled, 1, 0 /*0.44*/, false ], + [ $sampled, 1, 4 /*0.03*/, true ], + [ $unsampled, 0.1, 0 /*0.44*/, false ], + [ $sampled, 0.5, 0 /*0.44*/, false ], + [ $sampled, 0.5, 4 /*0.03*/, false ], ]; } + + public function testSetSamplingRates() { + $matching = new StatsdData(); + $matching->setKey( 'foo.bar' ); + $matching->setValue( 1 ); + + $nonMatching = new StatsdData(); + $nonMatching->setKey( 'oof.bar' ); + $nonMatching->setValue( 1 ); + + $sender = $this->getMock( 'Liuggio\StatsdClient\Sender\SenderInterface' ); + $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) ); + $sender->expects( $this->once() )->method( 'write' )->with( $this->anything(), + $this->equalTo( $nonMatching ) ); + + $client = new SamplingStatsdClient( $sender ); + $client->setSamplingRates( [ 'foo.*' => 0.2 ] ); + + mt_srand( 0 ); // next random is 0.44 + $client->send( $matching ); + mt_srand( 0 ); + $client->send( $nonMatching ); + } }