Skip to content
Snippets Groups Projects
Commit 35fd4e35 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3257845 by phenaproxima: Clear readiness stored readiness check results...

Issue #3257845 by phenaproxima: Clear readiness stored readiness check results after an update is applied
parent 50a752f8
No related branches found
No related tags found
1 merge request!181Issue #3257845: Clear readiness stored readiness check results after an update is applied
......@@ -9,6 +9,8 @@ services:
- '@automatic_updates.cron_updater'
- '@config.factory'
- 24
tags:
- { name: event_subscriber }
automatic_updates.updater:
class: Drupal\automatic_updates\Updater
arguments:
......
......@@ -9,12 +9,14 @@ use Drupal\automatic_updates\UpdateRecommender;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
use Drupal\package_manager\Event\PostApplyEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Defines a manager to run readiness validation.
*/
class ReadinessValidationManager {
class ReadinessValidationManager implements EventSubscriberInterface {
/**
* The key/value expirable storage.
......@@ -213,6 +215,13 @@ class ReadinessValidationManager {
return NULL;
}
/**
* Deletes any stored readiness validation results.
*/
public function clearStoredResults(): void {
$this->keyValueExpirable->delete('readiness_validation_last_run');
}
/**
* Gets the timestamp of the last run.
*
......@@ -224,4 +233,13 @@ class ReadinessValidationManager {
return $this->keyValueExpirable->get('readiness_check_timestamp');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
PostApplyEvent::class => 'clearStoredResults',
];
}
}
......@@ -70,6 +70,21 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$this->drupalLogin($this->reportViewerUser);
}
/**
* {@inheritdoc}
*/
protected function disableValidators(): array {
$disable_validators = parent::disableValidators();
// Because all actual staging operations are bypassed by
// package_manager_bypass, disable this validator because it will complain
// if there's no actual Composer data to inspect.
// @todo Do this in ::testStoredResultsClearedAfterUpdate() only once
// https://www.drupal.org/project/automatic_updates/issues/3260698 is
// fixed.
$disable_validators[] = 'automatic_updates.staged_projects_validator';
return $disable_validators;
}
/**
* Tests readiness checkers on status report page.
*/
......@@ -369,6 +384,53 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$assert->pageTextNotContains($expected_results_1[0]->getMessages()[0]);
}
/**
* Tests that stored validation results are deleted after an update.
*/
public function testStoredResultsClearedAfterUpdate(): void {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->checkerRunnerUser);
// The current release is 9.8.1 (see ::setUp()), so ensure we're on an older
// version.
$this->setCoreVersion('9.8.0');
// Flag a validation warning, which will be displayed in the messages area,
// but not block or abort the update.
$results = $this->testResults['checker_1']['1 warning'];
TestChecker1::setTestResult($results, ReadinessCheckEvent::class);
$message = $results[0]->getMessages()[0];
$this->container->get('module_installer')->install([
'automatic_updates',
'automatic_updates_test',
'package_manager_bypass',
]);
// The warning should be persistently visible, even after the checker stops
// flagging it.
$this->drupalGet('/admin/structure');
$assert_session->pageTextContains($message);
TestChecker1::setTestResult(NULL, ReadinessCheckEvent::class);
$this->getSession()->reload();
$assert_session->pageTextContains($message);
// Do the update; we don't expect any errors or special conditions to appear
// during it.
$this->drupalGet('/admin/modules/automatic-update');
$page->pressButton('Update');
$this->checkForMetaRefresh();
$this->assertUpdateReady();
$page->pressButton('Continue');
$this->checkForMetaRefresh();
$assert_session->pageTextContains('Update complete!');
// The warning should not be visible anymore.
$this->drupalGet('/admin/structure');
$assert_session->pageTextNotContains($message);
}
/**
* Asserts that the readiness requirement displays no errors or warnings.
*
......
......@@ -23,6 +23,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
protected static $modules = [
'automatic_updates_test',
'package_manager',
'package_manager_bypass',
'user',
];
......@@ -233,4 +234,45 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
$this->assertSame(Updater::class, $stage_class);
}
/**
* Tests that stored validation results are deleted after an update.
*/
public function testStoredResultsDeletedPostApply(): void {
$this->container->get('module_installer')
->install(['automatic_updates']);
// Ensure there's a simulated core release to update to.
$this->setReleaseMetadata(__DIR__ . '/../../../fixtures/release-history/drupal.9.8.1.xml');
// The readiness checker should raise a warning, so that the update is not
// blocked or aborted.
$results = $this->testResults['checker_1']['1 warning'];
TestChecker1::setTestResult($results, ReadinessCheckEvent::class);
// Ensure that the validation manager collects the warning.
/** @var \Drupal\automatic_updates\Validation\ReadinessValidationManager $manager */
$manager = $this->container->get('automatic_updates.readiness_validation_manager')
->run();
TestChecker1::setTestResult(NULL, ReadinessCheckEvent::class);
// Even though the checker no longer returns any results, the previous
// results should be stored.
$this->assertValidationResultsEqual($results, $manager->getResults());
// Don't validate staged projects because actual staging operations are
// bypassed by package_manager_bypass, which will make this validator
// complain that there is no actual Composer data for it to inspect.
$validator = $this->container->get('automatic_updates.staged_projects_validator');
$this->container->get('event_dispatcher')->removeSubscriber($validator);
/** @var \Drupal\automatic_updates\Updater $updater */
$updater = $this->container->get('automatic_updates.updater');
$updater->begin(['drupal' => '9.8.1']);
$updater->stage();
$updater->apply();
$updater->destroy();
// The readiness validation manager shouldn't have any stored results.
$this->assertEmpty($manager->getResults());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment