Skip to content
Snippets Groups Projects
Commit ae5ae0c4 authored by omkar podey's avatar omkar podey Committed by Adam G-H
Browse files

Issue #3293150 by omkar.podey, phenaproxima, yash.rode: Test that attended...

Issue #3293150 by omkar.podey, phenaproxima, yash.rode: Test that attended updates do apply and post-apply operations in separate requests
parent 144de76f
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,11 @@ services:
tags:
- { name: event_subscriber }
arguments: ['@state']
automatic_updates_test.request.time:
class: Drupal\automatic_updates_test\EventSubscriber\RequestTimeRecorder
tags:
- { name: event_subscriber }
arguments: ['@state', '@datetime.time']
automatic_updates_test.time:
class: Drupal\automatic_updates_test\Datetime\TestTime
decorates: datetime.time
......
<?php
namespace Drupal\automatic_updates_test\EventSubscriber;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\State\StateInterface;
use Drupal\package_manager\Event\PostApplyEvent;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\StageEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Records the request time during various events.
*/
class RequestTimeRecorder implements EventSubscriberInterface {
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a new instance.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(StateInterface $state, TimeInterface $time) {
$this->state = $state;
$this->time = $time;
}
/**
* Records the request time.
*
* @param \Drupal\package_manager\Event\StageEvent $event
* The event object.
*/
public function updateState(StageEvent $event) {
$key = get_class($event) . ' time';
$this->state->set($key, $this->time->getRequestMicroTime());
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
PreApplyEvent::class => 'updateState',
PostApplyEvent::class => 'updateState',
];
}
}
......@@ -584,6 +584,14 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$assert_session->pageTextContainsOnce('Update complete!');
// Confirm the site was returned to the original maintenance mode state.
$this->assertMaintenanceMode($maintenance_mode_on);
// Confirm that the apply and post-apply operations happened in
// separate requests.
// @see \Drupal\automatic_updates_test\EventSubscriber\RequestTimeRecorder
$pre_apply_time = $state->get('Drupal\package_manager\Event\PreApplyEvent time');
$post_apply_time = $state->get('Drupal\package_manager\Event\PostApplyEvent time');
$this->assertNotEmpty($pre_apply_time);
$this->assertNotEmpty($post_apply_time);
$this->assertNotSame($pre_apply_time, $post_apply_time);
}
/**
......
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