Skip to content

Commit

Permalink
bug #27344 [HttpKernel] reset kernel start time on reboot (kiler129)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.4 branch (closes #27344).

Discussion
----------

[HttpKernel] reset kernel start time on reboot

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27319
| License       | MIT
| Doc PR        | n/a

I created branch from 3.4, since the furthest thing I could find for the reboot feature was a4fc492 and it originated during stabilization phase of 3.4.

ping @nicolas-grekas

Commits
-------

b7feef0 [HttpKernel] reset kernel start time on reboot
  • Loading branch information
nicolas-grekas committed May 25, 2018
2 parents 7064a77 + b7feef0 commit 79bd461
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -87,18 +87,10 @@ public function __construct($environment, $debug)
$this->debug = (bool) $debug;
$this->rootDir = $this->getRootDir();
$this->name = $this->getName();

if ($this->debug) {
$this->startTime = microtime(true);
}
}

public function __clone()
{
if ($this->debug) {
$this->startTime = microtime(true);
}

$this->booted = false;
$this->container = null;
$this->requestStackSize = 0;
Expand All @@ -110,6 +102,10 @@ public function __clone()
*/
public function boot()
{
if ($this->debug) {
$this->startTime = microtime(true);
}

if (true === $this->booted) {
if (!$this->requestStackSize && $this->resetServices) {
if ($this->container->has('services_resetter')) {
Expand Down
19 changes: 17 additions & 2 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -901,6 +901,21 @@ public function testServicesResetter()
$this->assertEquals(1, ResettableService::$counter);
}

/**
* @group time-sensitive
*/
public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel()
{
$kernel = $this->getKernelForTest(array('initializeBundles'), true);
$kernel->boot();
$preReBoot = $kernel->getStartTime();

sleep(3600); //Intentionally large value to detect if ClockMock ever breaks
$kernel->boot();

$this->assertGreaterThan($preReBoot, $kernel->getStartTime());
}

/**
* Returns a mock for the BundleInterface.
*
Expand Down Expand Up @@ -970,10 +985,10 @@ protected function getKernel(array $methods = array(), array $bundles = array())
return $kernel;
}

protected function getKernelForTest(array $methods = array())
protected function getKernelForTest(array $methods = array(), $debug = false)
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->setConstructorArgs(array('test', false))
->setConstructorArgs(array('test', $debug))
->setMethods($methods)
->getMock();
$p = new \ReflectionProperty($kernel, 'rootDir');
Expand Down

0 comments on commit 79bd461

Please sign in to comment.