Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / cache / RedisBloomCacheTest.php
blob868d6c298cdcaba1e343547b131d14e8c1ed34be
1 <?php
3 /**
4 * Test for BloomCacheRedis class.
6 * @TODO: some generic base "redis test server conf" for all testing?
8 * @covers BloomCacheRedis
9 * @group Cache
11 class BloomCacheRedisTest extends MediaWikiTestCase {
12 private static $suffix;
14 protected function setUp() {
15 parent::setUp();
17 self::$suffix = self::$suffix ? : mt_rand();
19 $fcache = BloomCache::get( 'main' );
20 if ( $fcache instanceof BloomCacheRedis ) {
21 $fcache->delete( "unit-testing-" . self::$suffix );
22 } else {
23 $this->markTestSkipped( 'The main bloom cache is not redis.' );
27 public function testBloomCache() {
28 $key = "unit-testing-" . self::$suffix;
29 $fcache = BloomCache::get( 'main' );
30 $count = 1500;
32 $this->assertTrue( $fcache->delete( $key ), "OK delete of filter '$key'." );
33 $this->assertTrue( $fcache->init( $key, $count, .001 ), "OK init of filter '$key'." );
35 $members = array();
36 for ( $i = 0; $i < $count; ++$i ) {
37 $members[] = "$i-value-$i";
39 $this->assertTrue( $fcache->add( $key, $members ), "Addition of members to '$key' OK." );
41 for ( $i = 0; $i < $count; ++$i ) {
42 $this->assertTrue( $fcache->isHit( $key, "$i-value-$i" ), "Hit on member '$i-value-$i'." );
45 $falsePositives = array();
46 for ( $i = $count; $i < 2 * $count; ++$i ) {
47 if ( $fcache->isHit( $key, "value$i" ) ) {
48 $falsePositives[] = "value$i";
52 $eFalsePositives = array(
53 'value1763',
54 'value2245',
55 'value2353',
56 'value2791',
57 'value2898',
58 'value2975'
60 $this->assertEquals( $eFalsePositives, $falsePositives,
61 "Correct number of false positives found." );
64 protected function tearDown() {
65 parent::tearDown();
67 $fcache = BloomCache::get( 'main' );
68 if ( $fcache instanceof BloomCacheRedis ) {
69 $fcache->delete( "unit-testing-" . self::$suffix );