jenkins-bot has submitted this change and it was merged. Change subject: Refactoring of the cache data architecture ......................................................................
Refactoring of the cache data architecture Architecture: * At the beginning cache was only for config files, then it was added the LocalSettings, then it was added an 'existence' cache file. The cache data architecture is here refactored to (expectedly): 1a/ boost the case where the requested wiki is existant and has a cached configuration (LS.php) 1b/ while always be sure of the freshness of the origin files, and with second objectives: 2/ not harm too much the performance of nonexistant wiki or nonfresh cached files, 3/ reasonably distribute the write operation on cached files to prefer long-lived small cached files over a short-lived big cached file. * Given these objectives, the just-previously-introduced [cache]/versions.php, which answers globally to objective 1a (avoid recomputing the farm config to directly get the version and test the freshness of the origin files), is split in one-per-wiki cached files with almost the same content (objective 3). This file is self-consistent (objective 1b) to self-check its freshness for the existence operation ('coreconfig' parameter containing the origin files for this file) and is self-sufficient to regenerate the cached config (LS.php) in case this one is not fresh (in this case only LS.php is regenerated, objectives 1b and 2). * I considered the following alternatives: * A global existence cache file similar to [cache]/versions.php, but restricted to the version of each wiki and the origin files for the existence and config operations. This was not further considered because of objectives 2 (any change in existence or config origin files implies recomputing the whole farm configuration) and 3 (any change in existence or config origin files implies rewriting this cache file). * An existence file like it is here implemented (one-per-wiki existence cache file), but only with the wiki version and the existence origin files, with other variables stored in the beginning of LS.php (wikiID, suffix, data, config files), in order to directly define this cached LS.php without further evaluation during existence operation. But, when the cached config becomes nonfresh (it would be itself aware of it because it know its origin files), it should recompute the new config and write it in its own file. The PHP engine would currently correctly behave, but HHVM will not (bug #4797 on GitHub), and anyway this operation is quite risky. Anyway this would only move some instructions from the existence to the config operation and there is no performance gain; with the adoption solution, all farm variables are consistently stored in the existence cache file. * The cache directory is slightly reorganised by namespaces: * 'config': directly corresponding to origin config files, * 'wikis': per-wiki existence/coreconfig files, * 'LocalSettings': per-wiki config files. * Note that, with the current way of computing the variables (it was not explicitely constructed but it is finally quite good), the only data sources for the variables are in the host regex and the version, nothing else. When a variable is defined from another variable, it could be equivalently expanded with the variables from the host regex and, for $DATA, $VERSION, $CODE, and config files and keys, the version and version directory. E.g. if $SUFFIX='$family' and $WIKIID='$lang$SUFFIX', the second could have been written $WIKIID='$lang$family'. Saying this, intermediary variables are useful to shorten definition and improve their understanding. Code: * Removed the farm variable '$HTTP404' coming from farm config 'HTTP404'; it is now only computed when required (when a wiki is “soft-missing” = existing farm, nonexistant wiki) to avoid pollute the variables (reduce a bit the existence cache file explained just above) and I don’t think it would be required for any other variable. * Removed the old subarray MediaWikiFarm::$config['general'] unused since some time (replaced by the two subarrays 'settings' and 'arrays'). * Removed execution of execFiles in MediaWikiFarm::loadMediaWikiConfig to avoid execution in a restricted scope, and it is already executed in LS.php or src/main.php. * Sanitised host in MediaWikiFarm::__construct: now it is checked if the host has some corresponding file on the file system, so avoid any surprise (previously it was checked against a finite list of existing hosts). * Cached LS.php now has only the host name as cache key, no more version: I don’t see any advantage in keeping the version, and on the long term it would pollute a bit the cache directory. * In the cache directory, if some parent directory is missing, it is created. Previously only some were created. * MediaWikiFarm::cacheFile is now static and public, and the directory is now required. * MediaWikiFarm::cacheFile now accepts a string (used to write the cached LS.php and avoid a file_put_contents in getMediaWikiConfig). * The cached file 'config-$SERVER.php' is deactivated but kept: unused for now, but could be used in the future to get a structured configuration. Bugs: * When a core config file was modified, the cached LS.php was not updated, and it could have hard consequences, e.g. if version is changed or a config file is added. Tests: * Adapted tests according to this new architecture; * Code coverage is still missing for the existence cache file feature. Change-Id: I61004820c644d629552c85c92d8dcfcb36d0cc66 --- M src/MediaWikiFarm.php M tests/phpunit/ConfigurationTest.php M tests/phpunit/ConstructionTest.php M tests/phpunit/InstallationIndependantTest.php M tests/phpunit/MonoversionInstallationTest.php 5 files changed, 92 insertions(+), 113 deletions(-) Approvals: Seb35: Looks good to me, approved jenkins-bot: Verified diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php index 8a324ad..18e871a 100644 --- a/src/MediaWikiFarm.php +++ b/src/MediaWikiFarm.php @@ -71,7 +71,6 @@ /** @var array Configuration parameters for this wiki. */ protected $configuration = array( - 'general' => array(), 'settings' => array(), 'arrays' => array(), 'skins' => array(), @@ -173,7 +172,6 @@ * Get MediaWiki configuration. * * This associative array contains four sections: - * - 'general': associative array of MediaWiki configuration (e.g. 'wgServer' => '//example.org'); * - 'settings': associative array of MediaWiki configuration (e.g. 'wgServer' => '//example.org'); * - 'arrays': associative array of MediaWiki configuration of type array (e.g. 'wgGroupPermissions' => array( 'edit' => false )); * - 'skins': associative array of skins configuration (e.g. 'Vector' => 'wfLoadSkin' ); @@ -240,8 +238,11 @@ $httpProto = array_key_exists( 'SERVER_PROTOCOL', $_SERVER ) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1' ? 'HTTP/1.1' : 'HTTP/1.0'; // @codeCoverageIgnore header( "$httpProto 404 Not Found" ); // @codeCoverageIgnore } - if( $entryPoint == 'index.php' && array_key_exists( '$HTTP404', $wgMediaWikiFarm->variables ) && is_file( $wgMediaWikiFarm->variables['$HTTP404'] ) ) { - include $wgMediaWikiFarm->variables['$HTTP404']; + if( $entryPoint == 'index.php' && array_key_exists( 'HTTP404', $wgMediaWikiFarm->farmConfig ) ) { + $file404 = $wgMediaWikiFarm->replaceVariables( $wgMediaWikiFarm->farmConfig['HTTP404'] ); + if( is_file( $file404 ) ) { + include $file404; + } } return 404; } @@ -288,9 +289,6 @@ return true; } - # Set HTTP 404 early in case it is needed - $this->setVariable( 'HTTP404' ); - # Replace variables in the host name and possibly retrieve the version if( !$this->checkHostVariables() ) { return false; @@ -313,12 +311,7 @@ $variables = $this->variables; $variables['$CORECONFIG'] = $this->farmConfig['coreconfig']; $variables['$CONFIG'] = $this->farmConfig['config']; - $versions = $this->readFile( 'versions.php', dirname( $this->cacheDir ), false ); - if( !is_array( $versions ) ) { - $versions = array(); - } - $versions[$this->variables['$SERVER']] = $variables; - $this->cacheFile( $versions, 'versions.php', dirname( $this->cacheDir ) ); + self::cacheFile( $variables, $this->variables['$SERVER'] . '.php', $this->cacheDir . '/wikis' ); } return true; @@ -348,7 +341,7 @@ */ function loadMediaWikiConfig() { - if( count( $this->configuration['general'] ) == 0 && count( $this->configuration['settings'] ) == 0 && count( $this->configuration['arrays'] ) == 0 ) { + if( count( $this->configuration['settings'] ) == 0 && count( $this->configuration['arrays'] ) == 0 ) { $this->getMediaWikiConfig(); } @@ -405,16 +398,6 @@ wfLoadExtension( $extension ); } } - - # Execute PHP files - foreach( $this->configuration['execFiles'] as $execFile ) { - - if( !is_file( $execFile ) ) { - continue; - } - - include $execFile; - } } /** @@ -451,13 +434,7 @@ return $this->farmDir . '/src/main.php'; } - if( $this->variables['$VERSION'] ) { - $localSettingsFile = $this->replaceVariables( 'LocalSettings-$VERSION-$SUFFIX-$WIKIID.php' ); - } else { - $localSettingsFile = $this->replaceVariables( 'LocalSettings-$SUFFIX-$WIKIID.php' ); - } - - return $this->cacheDir . '/' . $localSettingsFile; + return $this->cacheDir . '/LocalSettings/' . $this->variables['$SERVER'] . '.php'; } @@ -523,6 +500,9 @@ } } + # Sanitise host + $host = preg_replace( '/[^a-zA-Z0-9\\._-]/', '', $host ); + # Set parameters $this->farmDir = dirname( dirname( __FILE__ ) ); $this->configDir = $configDir; @@ -533,18 +513,11 @@ 'ExtensionRegistry' => null, ), $parameters ); - # Create cache directory - if( $this->cacheDir && !is_dir( $this->cacheDir ) ) { - mkdir( $this->cacheDir ); - } - # Shortcut loading - // @codingStandardsIgnoreStart - if( $this->cacheDir && ( $result = $this->readFile( 'versions.php', $this->cacheDir, false ) ) && array_key_exists( $host, $result ) ) { - // @codingStandardsIgnoreEnd - $result = $result[$host]; + // @codingStandardsIgnoreLine + if( $this->cacheDir && ( $result = $this->readFile( $host . '.php', $this->cacheDir . '/wikis', false ) ) ) { $fresh = true; - $myfreshness = filemtime( $this->cacheDir . '/versions.php' ); + $myfreshness = filemtime( $this->cacheDir . '/wikis/' . $host . '.php' ); foreach( $result['$CORECONFIG'] as $coreconfig ) { if( filemtime( $this->configDir . '/' . $coreconfig ) > $myfreshness ) { $fresh = false; @@ -556,8 +529,9 @@ unset( $result['$CONFIG'] ); unset( $result['$CORECONFIG'] ); $this->variables = $result; - $this->cacheDir .= '/' . $result['$FARM']; return; + } elseif( is_file( $this->cacheDir . '/LocalSettings/' . $host . '.php' ) ) { + unlink( $this->cacheDir . '/LocalSettings/' . $host . '.php' ); } } @@ -568,12 +542,6 @@ if( $result['farm'] ) { $this->farmConfig = array_merge( $result['config'], $this->farmConfig ); $this->variables = array_merge( $result['variables'], $this->variables ); - if( $this->cacheDir ) { - $this->cacheDir .= '/' . $result['farm']; - } - if( $this->cacheDir && !is_dir( $this->cacheDir ) ) { - mkdir( $this->cacheDir ); - } $this->variables['$SERVER'] = $result['host']; $this->variables['$FARM'] = $result['farm']; return; @@ -856,7 +824,7 @@ # Update the deployment file $deployments[$this->variables['$WIKIID']] = $version; - $this->cacheFile( $deployments, $this->variables['$DEPLOYMENTS'], $this->configDir ); + self::cacheFile( $deployments, $this->variables['$DEPLOYMENTS'], $this->configDir ); } /** @@ -872,11 +840,7 @@ return false; } - if( $this->variables['$VERSION'] ) { - $localSettingsFile = $this->cacheDir . '/' . $this->replaceVariables( 'LocalSettings-$VERSION-$SUFFIX-$WIKIID.php' ); - } else { - $localSettingsFile = $this->cacheDir . '/' . $this->replaceVariables( 'LocalSettings-$SUFFIX-$WIKIID.php' ); - } + $localSettingsFile = $this->cacheDir . '/LocalSettings/' . $this->variables['$SERVER'] . '.php'; # Check there is a LocalSettings.php file if( !is_file( $localSettingsFile ) ) { @@ -906,8 +870,7 @@ * configuration; it is rebuilt when origin configuration files are changed. * * The returned array has the following format: - * array( 'general' => array( 'wgSitename' => 'Foo', ... ), - * 'settings' => array( 'wgSitename' => 'Foo', ... ), + * array( 'settings' => array( 'wgSitename' => 'Foo', ... ), * 'arrays' => array( 'wgGroupPermission' => array(), ... ), * 'skins' => 'wfLoadSkin'|'require_once', * 'extensions' => 'wfLoadExtension'|'require_once', @@ -925,20 +888,15 @@ return; } - if( $this->variables['$VERSION'] ) { - $localSettingsFile = $this->cacheDir . '/' . $this->replaceVariables( 'LocalSettings-$VERSION-$SUFFIX-$WIKIID.php' ); - $cacheFile = $this->replaceVariables( 'config-$VERSION-$SUFFIX-$WIKIID.php' ); - } - else { - $localSettingsFile = $this->cacheDir . '/' . $this->replaceVariables( 'LocalSettings-$SUFFIX-$WIKIID.php' ); - $cacheFile = $this->replaceVariables( 'config-$SUFFIX-$WIKIID.php' ); - } + // if( is_string( $this->cacheDir ) ) { + // $cacheFile = $this->cacheDir . '/LocalSettings/' . 'config-' . $this->variables['$SERVER'] . '.php'; + // } # Populate from cache - if( !$force && $this->cacheDir && is_file( $this->cacheDir . '/' . $cacheFile ) ) { - $this->configuration = $this->readFile( $cacheFile, $this->cacheDir ); - return; - } + // if( !$force && $this->cacheDir && is_file( $this->cacheDir . '/LocalSettings/' . $cacheFile ) ) { + // $this->configuration = $this->readFile( $cacheFile, $this->cacheDir . '/LocalSettings', false ); + // return; + // } # Get specific configuration for this wiki $this->populateSettings(); @@ -948,10 +906,14 @@ # Save this configuration in a PHP file if( is_string( $this->cacheDir ) && !count( $this->errors ) ) { - $this->cacheFile( $this->configuration, $cacheFile ); - if( file_put_contents( $localSettingsFile . '.tmp', $this->createLocalSettings( $this->configuration ) ) ) { - rename( $localSettingsFile . '.tmp', $localSettingsFile ); - } + // self::cacheFile( $this->configuration, + // 'config-' . $this->variables['$SERVER'] . '.php', + // $this->cacheDir . '/LocalSettings' + // ); + self::cacheFile( $this->createLocalSettings( $this->configuration ), + $this->variables['$SERVER'] . '.php', + $this->cacheDir . '/LocalSettings' + ); } } @@ -1479,7 +1441,7 @@ # Check the file exists $prefixedFile = $directory ? $directory . '/' . $filename : $filename; - $cachedFile = $this->cacheDir !== false && $cache ? $this->cacheDir . '/' . $filename . '.php' : false; + $cachedFile = $this->cacheDir !== false && $cache ? $this->cacheDir . '/config/' . $filename . '.php' : false; if( !is_file( $prefixedFile ) ) { $format = null; } @@ -1506,7 +1468,7 @@ # Cached version elseif( $cachedFile && is_string( $format ) && is_file( $cachedFile ) && filemtime( $cachedFile ) >= filemtime( $prefixedFile ) ) { - return $this->readFile( $filename . '.php', $this->cacheDir ); + return $this->readFile( $filename . '.php', $this->cacheDir . '/config', false ); } # Format YAML @@ -1565,14 +1527,14 @@ $this->errors[] = 'Unreadable file ' . $filename; - return $this->readFile( $filename . '.php', $this->cacheDir ); + return $this->readFile( $filename . '.php', $this->cacheDir . '/config', false ); } # Regular return for arrays if( is_array( $array ) ) { - if( $cachedFile && $directory != $this->cacheDir && ( !is_file( $cachedFile ) || ( filemtime( $cachedFile ) < filemtime( $prefixedFile ) ) ) ) { - $this->cacheFile( $array, $filename.'.php' ); + if( $cachedFile && $directory != $this->cacheDir . '/config' && ( !is_file( $cachedFile ) || ( filemtime( $cachedFile ) < filemtime( $prefixedFile ) ) ) ) { + self::cacheFile( $array, $filename . '.php', $this->cacheDir . '/config' ); } return $array; @@ -1588,28 +1550,41 @@ * @mediawikifarm-const * @mediawikifarm-idempotent * - * @param array $array Array of the data to be cached. + * @param array|string $array Array of the data to be cached. * @param string $filename Name of the cache file; this filename must have an extension '.php' else no cache file is saved. - * @param string|null $directory Name of the parent directory; null for default cache directory + * @param string $directory Name of the parent directory; null for default cache directory * @return void */ - protected function cacheFile( $array, $filename, $directory = null ) { + static function cacheFile( $array, $filename, $directory ) { - if( !is_string( $directory ) ) { - $directory = $this->cacheDir; + if( !preg_match( '/\.php$/', $filename ) ) { + return; } $prefixedFile = $directory . '/' . $filename; - - # Create temporary file $tmpFile = $prefixedFile . '.tmp'; - if( preg_match( '/\.php$/', $filename ) ) { - if( !is_dir( dirname( $tmpFile ) ) ) { - mkdir( dirname( $tmpFile ) ); + + # Prepare string + if( is_array( $array ) ) { + $php = "<?php\n\n// WARNING: file automatically generated: do not modify.\n\nreturn " . var_export( $array, true ) . ';'; + } else { + $php = (string) $array; + } + + # Create parent directories + if( !is_dir( dirname( $tmpFile ) ) ) { + $path = ''; + foreach( explode( '/', dirname( $prefixedFile ) ) as $dir ) { + $path .= '/' . $dir; + if( !is_dir( $path ) ) { + mkdir( $path ); + } } - if( file_put_contents( $tmpFile, "<?php\n\n// WARNING: file automatically generated: do not modify.\n\nreturn ".var_export( $array, true ).';' ) ) { - rename( $tmpFile, $prefixedFile ); - } + } + + # Create temporary file and move it to final file + if( file_put_contents( $tmpFile, $php ) ) { + rename( $tmpFile, $prefixedFile ); } } diff --git a/tests/phpunit/ConfigurationTest.php b/tests/phpunit/ConfigurationTest.php index 7e4b13d..8133726 100644 --- a/tests/phpunit/ConfigurationTest.php +++ b/tests/phpunit/ConfigurationTest.php @@ -83,7 +83,6 @@ 'execFiles' => array( 0 => dirname( __FILE__ ) . '/data/config/LocalSettings.php', ), - 'general' => array(), ); $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org', @@ -99,7 +98,6 @@ $this->assertEquals( $result['skins'], $farm->getConfiguration( 'skins' ) ); $this->assertEquals( $result['extensions'], $farm->getConfiguration( 'extensions' ) ); $this->assertEquals( $result['execFiles'], $farm->getConfiguration( 'execFiles' ) ); - $this->assertEquals( $result['general'], $farm->getConfiguration( 'general' ) ); $this->assertEquals( $result, $farm->getConfiguration() ); } @@ -202,6 +200,7 @@ * @covers MediaWikiFarm::createLocalSettings * @covers MediaWikiFarm::writeArrayAssignment * @covers MediaWikiFarm::getConfigFile + * @covers MediaWikiFarm::cacheFile * @uses MediaWikiFarm::__construct * @uses MediaWikiFarm::selectFarm * @uses MediaWikiFarm::checkExistence @@ -214,7 +213,6 @@ * @uses MediaWikiFarm::setVariable * @uses MediaWikiFarm::replaceVariables * @uses MediaWikiFarm::readFile - * @uses MediaWikiFarm::cacheFile * @uses MediaWikiFarm::arrayMerge * @uses MediaWikiFarm::isMediaWiki * @uses AbstractMediaWikiFarmScript::rmdirr @@ -252,8 +250,7 @@ $this->assertFalse( $config['wgUseExtensionConfirmEditQuestyCaptcha'] ); $this->assertEquals( - self::$wgMediaWikiFarmCacheDir . '/testfarm-multiversion-test-extensions' - . '/LocalSettings-vstub-testextensionsfarm-btestextensionsfarm.php', + self::$wgMediaWikiFarmCacheDir . '/LocalSettings/b.testfarm-multiversion-test-extensions.example.org.php', $farm->getConfigFile() ); } @@ -268,6 +265,7 @@ * @covers MediaWikiFarm::createLocalSettings * @covers MediaWikiFarm::writeArrayAssignment * @covers MediaWikiFarm::getConfigFile + * @covers MediaWikiFarm::cacheFile * @uses MediaWikiFarm::__construct * @uses MediaWikiFarm::selectFarm * @uses MediaWikiFarm::checkExistence @@ -279,7 +277,6 @@ * @uses MediaWikiFarm::setVariable * @uses MediaWikiFarm::replaceVariables * @uses MediaWikiFarm::readFile - * @uses MediaWikiFarm::cacheFile * @uses MediaWikiFarm::arrayMerge * @uses AbstractMediaWikiFarmScript::rmdirr */ @@ -299,7 +296,7 @@ $this->assertEquals( 200000, $config['wgMemCachedTimeout'] ); # Re-load to use config cache - AbstractMediaWikiFarmScript::rmdirr( self::$wgMediaWikiFarmCacheDir . '/versions.php' ); + AbstractMediaWikiFarmScript::rmdirr( self::$wgMediaWikiFarmCacheDir . '/wikis/a.testfarm-monoversion.example.org.php' ); $farm = new MediaWikiFarm( 'a.testfarm-monoversion.example.org', self::$wgMediaWikiFarmConfigDir, null, self::$wgMediaWikiFarmCacheDir, array( 'EntryPoint' => 'index.php' ) @@ -310,6 +307,6 @@ $config = $farm->getConfiguration( 'settings' ); $this->assertEquals( 200000, $config['wgMemCachedTimeout'] ); - $this->assertEquals( self::$wgMediaWikiFarmCacheDir . '/testfarm-monoversion/LocalSettings-testfarm-atestfarm.php', $farm->getConfigFile() ); + $this->assertEquals( self::$wgMediaWikiFarmCacheDir . '/LocalSettings/a.testfarm-monoversion.example.org.php', $farm->getConfigFile() ); } } diff --git a/tests/phpunit/ConstructionTest.php b/tests/phpunit/ConstructionTest.php index 8e33ea8..b891665 100644 --- a/tests/phpunit/ConstructionTest.php +++ b/tests/phpunit/ConstructionTest.php @@ -405,9 +405,7 @@ self::$wgMediaWikiFarmCacheDir, array( 'EntryPoint' => 'index.php' ) ); - $this->assertEquals( self::$wgMediaWikiFarmCacheDir . '/testfarm-multiversion', $farm->getCacheDir() ); - $this->assertTrue( is_dir( self::$wgMediaWikiFarmCacheDir ) ); - $this->assertTrue( is_dir( self::$wgMediaWikiFarmCacheDir . '/testfarm-multiversion' ) ); + $this->assertEquals( self::$wgMediaWikiFarmCacheDir, $farm->getCacheDir() ); } /** @@ -568,7 +566,7 @@ } /** - * Test the 'loading' function with non-existant wiki. + * Test the 'loading' function with nonexistant wiki in an existant farm. * * @backupGlobals enabled * @covers MediaWikiFarm::load @@ -580,24 +578,27 @@ * @uses MediaWikiFarm::setVariable * @uses MediaWikiFarm::replaceVariables */ - function testLoadingNonExistant() { + function testLoadingSoftMissingError() { $this->backupAndSetGlobalVariable( 'wgMediaWikiFarm', null ); $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmConfigDir', self::$wgMediaWikiFarmConfigDir ); $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCodeDir', null ); $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCacheDir', false ); $this->backupAndSetGlobalSubvariable( '_SERVER', 'HTTP_HOST', null ); - $this->backupAndSetGlobalSubvariable( '_SERVER', 'SERVER_NAME', 'c.testfarm-monoversion-with-file-variable-without-version.example.org' ); + $this->backupAndSetGlobalSubvariable( '_SERVER', 'SERVER_NAME', 'z.testfarm-monoversion-with-file-variable-without-version.example.org' ); $this->backupAndUnsetGlobalVariable( 'wgMediaWikiFarmHTTP404Executed' ); $code = MediaWikiFarm::load( 'index.php' ); - $this->assertEquals( 404, $code ); - $this->assertTrue( $GLOBALS['wgMediaWikiFarmHTTP404Executed'] ); + $this->assertEquals( 404, $code, 'The host was not evaluated as “soft-missing” (existing farm, nonexistant wiki).' ); + $this->assertTrue( + array_key_exists( 'wgMediaWikiFarmHTTP404Executed', $GLOBALS ) && $GLOBALS['wgMediaWikiFarmHTTP404Executed'] === true, + 'The PHP file corresponding to HTTP errors “404 Not Found” was not executed.' + ); } /** - * Test the 'loading' function with farm error. + * Test the 'loading' function with a nonexistant farm. * * @backupGlobals enabled * @covers MediaWikiFarm::load @@ -605,16 +606,16 @@ * @uses MediaWikiFarm::selectFarm * @uses MediaWikiFarm::readFile */ - function testLoadingError() { + function testLoadingHardMissingError() { $this->backupAndSetGlobalVariable( 'wgMediaWikiFarm', null ); $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmConfigDir', self::$wgMediaWikiFarmConfigDir ); $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCodeDir', null ); $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCacheDir', false ); - $this->backupAndSetGlobalSubvariable( '_SERVER', 'HTTP_HOST', 'a.testfarm-missing.example.org' ); + $this->backupAndSetGlobalSubvariable( '_SERVER', 'HTTP_HOST', 'a.testfarm-nonexistant.example.org' ); $code = MediaWikiFarm::load( 'index.php' ); - $this->assertEquals( 500, $code ); + $this->assertEquals( 500, $code, 'The host was not evaluated as “hard-missing” (nonexistant farm).' ); } } diff --git a/tests/phpunit/InstallationIndependantTest.php b/tests/phpunit/InstallationIndependantTest.php index 25cdce5..80b130b 100644 --- a/tests/phpunit/InstallationIndependantTest.php +++ b/tests/phpunit/InstallationIndependantTest.php @@ -301,6 +301,9 @@ /** * Test cache file. * + * @todo This test targets mainly MediaWikiFarm::cacheFile. This function was previously protected, so it was tested through + * MediaWikiFarm::readFile. Now it is public-static, hence this test should be rewritten to directly test it. + * * @covers MediaWikiFarm::readFile * @covers MediaWikiFarm::cacheFile * @uses MediaWikiFarm::__construct @@ -315,7 +318,7 @@ # Read original file and check the cached version is written $farm->readFile( 'testreading2.json', self::$wgMediaWikiFarmConfigDir ); - $this->assertTrue( is_file( self::$wgMediaWikiFarmCacheDir . '/testfarm-monoversion/testreading2.json.php' ) ); + $this->assertTrue( is_file( self::$wgMediaWikiFarmCacheDir . '/config/testreading2.json.php' ) ); # Read cached version $result = $farm->readFile( 'testreading2.json', self::$wgMediaWikiFarmConfigDir ); @@ -340,7 +343,11 @@ unlink( self::$wgMediaWikiFarmConfigDir . '/testreading2.json' ); $farm->readFile( 'subdir/testreading2.json', self::$wgMediaWikiFarmConfigDir ); - $this->assertTrue( is_file( self::$wgMediaWikiFarmCacheDir . '/testfarm-monoversion/subdir/testreading2.json.php' ) ); + $this->assertTrue( is_file( self::$wgMediaWikiFarmCacheDir . '/config/subdir/testreading2.json.php' ) ); + + # Test when it is requested to cache non-PHP file + MediaWikiFarm::cacheFile( array(), 'nonexistant.json', self::$wgMediaWikiFarmCacheDir ); + $this->assertFalse( is_file( self::$wgMediaWikiFarmCacheDir . '/nonexistant.json' ) ); } /** diff --git a/tests/phpunit/MonoversionInstallationTest.php b/tests/phpunit/MonoversionInstallationTest.php index 90057f8..584445b 100644 --- a/tests/phpunit/MonoversionInstallationTest.php +++ b/tests/phpunit/MonoversionInstallationTest.php @@ -72,7 +72,6 @@ '$SERVER' => 'a.testfarm-monoversion.example.org', '$SUFFIX' => 'testfarm', '$WIKIID' => 'atestfarm', - '$HTTP404' => 'phpunitHTTP404.php', '$VERSION' => '', '$CODE' => $IP, ), -- To view, visit https://gerrit.wikimedia.org/r/325306 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I61004820c644d629552c85c92d8dcfcb36d0cc66 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiFarm Gerrit-Branch: master Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com> Gerrit-Reviewer: Hashar <has...@free.fr> Gerrit-Reviewer: Seb35 <seb35wikipe...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits