Merge "Rework broken echo test to make less assumptions"

This commit is contained in:
jenkins-bot 2015-01-30 00:50:27 +00:00 committed by Gerrit Code Review
commit df2d335261

View file

@ -21,29 +21,40 @@ class EchoTitleLocalCacheTest extends MediaWikiTestCase {
* @depends testCreate * @depends testCreate
*/ */
public function testGet( $cache ) { public function testGet( $cache ) {
$lruMap = new MapCacheLRU( EchoLocalCache::TARGET_MAX_NUM );
$titleIds = array();
$res = $this->insertPage( "EchoTitleLocalCacheTest_testGet" );
$titleIds[$res['id']] = $res['id'];
// First title included in cache
$lruMap->set( $res['id'], $res['title'] );
// second title not in internal cache, resolves from db.
$res = $this->insertPage( "EchoTitleLocalCacheTest_testGet2" );
$titleIds[$res['id']] = $res['id'];
$object = new \ReflectionObject( $cache ); $object = new \ReflectionObject( $cache );
// Load our generated MapCacheLRU in as the targets(known mapping from
// title id to title object) into $cache
$targets = $object->getProperty( 'targets' ); $targets = $object->getProperty( 'targets' );
$targets->setAccessible( true ); $targets->setAccessible( true );
$lruMap = new MapCacheLRU( EchoLocalCache::TARGET_MAX_NUM );
$lruMap->set( 1, $this->mockTitle() );
$targets->setValue( $cache, $lruMap ); $targets->setValue( $cache, $lruMap );
// Load both of the titles we are curious about into the list of titles
// to be looked up
$lookups = $object->getProperty( 'lookups' ); $lookups = $object->getProperty( 'lookups' );
$lookups->setAccessible( true ); $lookups->setAccessible( true );
$lookups->setValue( $cache, array( '1' => '1', '2' => '2' ) ); $lookups->setValue( $cache, $titleIds );
# A second page in addition to MediaWikiTestPage 'UTPage' since // Requesting the first object, which is within the known targets, should
# TitleLocalCache internally invokes Title::newFromIDs() // not resolve the pending lookups.
$this->insertPage('EchoTitleLocalCacheTest_testGet'); $this->assertInstanceOf( 'Title', $cache->get( reset( $titleIds ) ) );
$titles = Title::newFromIDs( array( '1', '2' ) ); $this->assertGreaterThan( 0, count( $cache->getLookups() ) );
$this->assertEquals( 2, count( $titles ), "Must have at least two pages" );
$this->assertEquals( array(1 => '1', 2 => '2' ), $cache->getLookups() ); // Requesting the second object, which is not within the known targets, should
// resolve the pending lookups and reset the list to lookup.
// MapCacheLRU should treat key 1 same as '1' $this->assertInstanceOf( 'Title', $cache->get( end( $titleIds ) ) );
$this->assertInstanceOf( 'Title', $cache->get( '1' ) ); $this->assertEquals( 0, count( $cache->getLookups() ) );
$this->assertTrue( count( $cache->getLookups() ) > 0 );
$this->assertInstanceOf( 'Title', $cache->get( 2 ) );
$this->assertTrue( count( $cache->getLookups() ) == 0 );
} }
/** /**