Page MenuHomePhabricator

MediaWikiIntegrationTestCase::setMwGlobals doesn't affect the service locator for certain globals
Closed, ResolvedPublic

Description

Certain globals, such as $wgObjectCaches, $wgMainCacheType and $wgJobTypeConf cannot be properly set using setMwGlobals. The actual global value is changed, but because makeTestConfig creates a configuration that defines these configuration settings, the actual global value isn't picked up.

This causes tests that change a cache by calling $this->setMwGlobals( 'wgMainCacheType', 'hash' ); to stop working once the cache uses the service locator.

Affected change: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/566083 (T243233: MediaWiki should provide a LocalClusterObjectCache service)

Event Timeline

Krinkle edited projects, added: Performance-Team; removed: MediaWiki-libs-BagOStuff.
Krinkle subscribed.

These services are set to hashes by MediaWikiIntegrationTestCase (via TestSetup).

If you change globals that require services to be reinitialised, you need to call MediaWikiIntegrationTestCase->resetServices(), or alternatively use setService() to construct the affected services directly in the way you want (without relying on ServiceWiring and globals), or better yet construct the services locally within the test and pass them to the code under test directly if possible.

These services are set to hashes by MediaWikiIntegrationTestCase (via TestSetup).

That's not what I see at MediaWikiIntegrationTestCase::makeTestConfig, it explicitly initializes $wgMainCacheType as CACHE_NONE.

If you change globals that require services to be reinitialised, you need to call MediaWikiIntegrationTestCase->resetServices(), or alternatively use setService() to construct the affected services directly in the way you want (without relying on ServiceWiring and globals), or better yet construct the services locally within the test and pass them to the code under test directly if possible.

I've done that in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/566083, but there I was told that These changes should not be needed..