Page MenuHomePhabricator

Run ApiStructureTest with CommunityConfiguration extension enabled
Closed, ResolvedPublic2 Estimated Story Points

Description

As part of T369709: Switch `GEUseCommunityConfigurationExtension` to `true` in extension.json, I noticed ApiStructureTest is failing when GrowthSuggestedEdits has a defined validator (and when MediaWiki-extensions-CommunityConfiguration is in use) The failure is as follows:

13:18:13 1) ApiStructureTest::testParameters with data set "Module visualeditoredit, argset for help" ('visualeditoredit', 'for help', array(1), MediaWiki\Api\ApiMain Object (...))
13:18:13 Wikimedia\Services\ContainerDisabledException: Container disabled!
13:18:13 
13:18:13 /workspace/src/vendor/wikimedia/services/src/ServiceContainer.php:398
13:18:13 /workspace/src/includes/MediaWikiServices.php:357
13:18:13 /workspace/src/vendor/wikimedia/services/src/ServiceContainer.php:414
13:18:13 /workspace/src/vendor/wikimedia/object-factory/src/ObjectFactory.php:204
13:18:13 /workspace/src/vendor/wikimedia/object-factory/src/ObjectFactory.php:149
13:18:13 /workspace/src/extensions/GrowthExperiments/includes/NewcomerTasks/TaskType/TaskTypeHandlerRegistry.php:142
13:18:13 /workspace/src/extensions/GrowthExperiments/includes/NewcomerTasks/TaskType/TaskTypeHandlerRegistry.php:48
13:18:13 /workspace/src/extensions/GrowthExperiments/includes/NewcomerTasks/ConfigurationLoader/AbstractDataConfigurationLoader.php:208
13:18:13 /workspace/src/extensions/GrowthExperiments/includes/NewcomerTasks/ConfigurationLoader/AbstractDataConfigurationLoader.php:140
13:18:13 /workspace/src/extensions/GrowthExperiments/includes/NewcomerTasks/ConfigurationLoader/ConfigurationLoaderTrait.php:35
13:18:13 /workspace/src/extensions/GrowthExperiments/includes/VisualEditorHooks.php:172
13:18:13 /workspace/src/includes/HookContainer/HookContainer.php:159
13:18:13 /workspace/src/includes/api/ApiHookRunner.php:107
13:18:13 /workspace/src/includes/api/ApiBase.php:1986
13:18:13 /workspace/src/tests/phpunit/structure/ApiStructureTest.php:176
13:18:13 phpvfscomposer:///workspace/src/vendor/phpunit/phpunit/phpunit:106

I managed to workaround this issue by adding the following code to CommunityConfigurationHooks::onCommunityConfigurationProvider_initList:

private function isCalledFromBrokenTest() {
	if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
		return false;
	}

	$trace = ( new \RuntimeException() )->getTraceAsString();
	return str_contains( $trace, 'ApiStructureTest' );
}


// HACK: Do not break ApiStructureTest
// TODO: Figure out why ApiStructureTest is failing with a validator defined here and
// remove this (T380585)
if (
	isset( $providers['GrowthSuggestedEdits'] ) &&
	$this->isCalledFromBrokenTest()
) {
	$providers['GrowthSuggestedEdits']['validator'] = [
		'type' => 'noop',
	];
}

However, this is not a viable long-term solution and we figure out why the test is failing and remove the hack.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
KStoller-WMF set the point value for this task to 2.Dec 10 2024, 5:29 PM
Urbanecm_WMF renamed this task from Figure out why a validator for GrowthSuggestedEdits is breaking ApiStructureTest to Run ApiStructureTest with CommunityConfiguration extension enabled.Jan 10 2025, 1:45 PM
KStoller-WMF lowered the priority of this task from High to Medium.Jan 15 2025, 5:32 PM

These are notes I took when looking last into this on Feb 25th, before I had to look into other things:

  • the container seems to actually be destroyed, as placing a breakpoint on the exception being thrown reveals
  • I do not know why that container is destroyed
  • there are two variants for each test executed, plain and with ApiBase::GET_VALUES_FOR_HELP and only the latter encounters these issues
  • If I move the test out of the data-provider, then it no longer errors out! => could there somehow be a contamination from a different test?
  • if I reverse the order of the tests in the data-provider, then that does not make a difference
  • next thing to try for me: only return the data for this particular api-endpoint from the data-provider

Looking more into it now.

A few more observations:

  • the error still occurs if I narrow the provider down to only return the two test-cases for the 'visualeditoredit' path.
    • => so it is not a contamination from any other API endpoint
  • the error goes away if I switch around the two values in
ApiStructureTest.php
$argsets = [
	'plain' => [],
	'for help' => [ ApiBase::GET_VALUES_FOR_HELP ],
];
  • => so it is about *something* happening in the first case that affects the second
  • the error also goes away If I ensure that there is a new ApiMain instance every time by doing something like
self::$main = null;
$main = self::getMain();
  • => so somehow something somewhere is holding on to an old instance of the services?
  • the error goes away if I comment out 'plain' => [], or reverse the order, and add additional paths; the same is true if I comment out 'plain' => [], but duplicate 'for help' => [ ApiBase::GET_VALUES_FOR_HELP ],
    • => so it is not "something runs before our for help" test-case, but specifically 'plain' => [], for the same 'visualeditoredit' endpoint runs before it.

Further debugging revealed that the GrowthExperimentsTaskTypeHandlerRegistry is not being instantiated a second time when running only the tests for 'visualeditoredit', thus using a service container that was destroyed in the teardown of the first testcase with 'plain'. But why?

Change #1125153 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/core@master] test(ApiStructureTest): use a fresh ApiMain instance for each test

https://gerrit.wikimedia.org/r/1125153

Change #1125155 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/GrowthExperiments@master] test(ApiStructureTest): reenable test for visualeditoredit integration

https://gerrit.wikimedia.org/r/1125155

Change #1125153 merged by jenkins-bot:

[mediawiki/core@master] test(ApiStructureTest): use a fresh ApiMain instance for each test

https://gerrit.wikimedia.org/r/1125153

Change #1125155 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] test(ApiStructureTest): reenable test for visualeditoredit integration

https://gerrit.wikimedia.org/r/1125155

There should be no production impact from this, it mainly touched test-files.