Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] reset kernel start time on reboot #27344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we do this only when we actually do something (i.e. when not booted, or when the booting again without a request stack size) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 9de5014

}

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
Original file line number Diff line number Diff line change
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