8000 [HttpKernel] reset kernel start time on reboot · symfony/symfony@b7feef0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7feef0

Browse files
kiler129nicolas-grekas
authored andcommitted
[HttpKernel] reset kernel start time on reboot
1 parent c2f15af commit b7feef0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,10 @@ public function __construct($environment, $debug)
8787
$this->debug = (bool) $debug;
8888
$this->rootDir = $this->getRootDir();
8989
$this->name = $this->getName();
90-
91-
if ($this->debug) {
92-
$this->startTime = microtime(true);
93-
}
9490
}
9591

9692
public function __clone()
9793
{
98-
if ($this->debug) {
99-
$this->startTime = microtime(true);
100-
}
101-
10294
$this->booted = false;
10395
$this->container = null;
10496
$this->requestStackSize = 0;
@@ -110,6 +102,10 @@ public function __clone()
110102
*/
111103
public function boot()
112104
{
105+
if ($this->debug) {
106+
$this->startTime = microtime(true);
107+
}
108+
113109
if (true === $this->booted) {
114110
if (!$this->requestStackSize && $this->resetServices) {
115111
if ($this->container->has('services_resetter')) {

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,21 @@ public function testServicesResetter()
901901
$this->assertEquals(1, ResettableService::$counter);
902902
}
903903

904+
/**
905+
* @group time-sensitive
906+
*/
907+
public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel()
908+
{
909+
$kernel = $this->getKernelForTest(array('initializeBundles'), true);
910+
$kernel->boot();
911+
$preReBoot = $kernel->getStartTime();
912+
913+
sleep(3600); //Intentionally large value to detect if ClockMock ever breaks
914+
$kernel->boot();
915+
916+
$this->assertGreaterThan($preReBoot, $kernel->getStartTime());
917+
}
918+
904919
/**
905920
* Returns a mock for the BundleInterface.
906921
*
@@ -970,10 +985,10 @@ protected function getKernel(array $methods = array(), array $bundles = array())
970985
return $kernel;
971986
}
972987

973-
protected function getKernelForTest(array $methods = array())
988+
protected function getKernelForTest(array $methods = array(), $debug = false)
974989
{
975990
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
976-
->setConstructorArgs(array('test', false))
991+
->setConstructorArgs(array('test', $debug))
977992
->setMethods($methods)
978993
->getMock();
979994
$p = new \ReflectionProperty($kernel, 'rootDir');

0 commit comments

Comments
 (0)
0