Merge "Revert "Make enhanced recent changes and extended watchlist default""
[lhc/web/wiklou.git] / tests / phpunit / includes / cache / RedisBloomCacheTest.php
1 <?php
2
3 /**
4 * Test for BloomCacheRedis class.
5 *
6 * @TODO: some generic base "redis test server conf" for all testing?
7 *
8 * @covers BloomCacheRedis
9 * @group Cache
10 */
11 class BloomCacheRedisTest extends MediaWikiTestCase {
12 private static $suffix;
13
14 protected function setUp() {
15 parent::setUp();
16
17 self::$suffix = self::$suffix ? : mt_rand();
18
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.' );
24 }
25 }
26
27 public function testBloomCache() {
28 $key = "unit-testing-" . self::$suffix;
29 $fcache = BloomCache::get( 'main' );
30 $count = 1500;
31
32 $this->assertTrue( $fcache->delete( $key ), "OK delete of filter '$key'." );
33 $this->assertTrue( $fcache->init( $key, $count, .001 ), "OK init of filter '$key'." );
34
35 $members = array();
36 for ( $i = 0; $i < $count; ++$i ) {
37 $members[] = "$i-value-$i";
38 }
39 $this->assertTrue( $fcache->add( $key, $members ), "Addition of members to '$key' OK." );
40
41 for ( $i = 0; $i < $count; ++$i ) {
42 $this->assertTrue( $fcache->isHit( $key, "$i-value-$i" ), "Hit on member '$i-value-$i'." );
43 }
44
45 $falsePositives = array();
46 for ( $i = $count; $i < 2 * $count; ++$i ) {
47 if ( $fcache->isHit( $key, "value$i" ) ) {
48 $falsePositives[] = "value$i";
49 }
50 }
51
52 $eFalsePositives = array(
53 'value1763',
54 'value2245',
55 'value2353',
56 'value2791',
57 'value2898',
58 'value2975'
59 );
60 $this->assertEquals( $eFalsePositives, $falsePositives,
61 "Correct number of false positives found." );
62 }
63
64 protected function tearDown() {
65 parent::tearDown();
66
67 $fcache = BloomCache::get( 'main' );
68 if ( $fcache instanceof BloomCacheRedis ) {
69 $fcache->delete( "unit-testing-" . self::$suffix );
70 }
71 }
72 }