X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2FSamplingStatsdClientTest.php;h=9a489303a7a3d9db4b94cd441d927e2b5e845042;hb=7874fc4bec845ad92960b07e969c65f3c3fe74f2;hp=be6732d52f50f0d77809a55d31d1c7fab6cee79e;hpb=e56f7b6c63acbb579888c0abf1c70c06f296d612;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php index be6732d52f..9a489303a7 100644 --- a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php +++ b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php @@ -30,14 +30,37 @@ class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase { $sampled->setValue( 1 ); $sampled->setSampleRate( '0.1' ); - return array( + return [ // $data, $sampleRate, $seed, $expectWrite - array( $unsampled, 1, 0 /*0.44*/, $unsampled ), - array( $sampled, 1, 0 /*0.44*/, null ), - array( $sampled, 1, 4 /*0.03*/, $sampled ), - array( $unsampled, 0.1, 4 /*0.03*/, $sampled ), - array( $sampled, 0.5, 0 /*0.44*/, null ), - array( $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 ); } }