Skip to content

Commit

Permalink
Merge pull request #95 from magento-troll/troll_s30
Browse files Browse the repository at this point in the history
[Troll] Varnish updates and Unit Tests Coverage
  • Loading branch information
Roman Ganin committed Feb 17, 2015
2 parents dc51ad1 + 5059581 commit f2361bd
Show file tree
Hide file tree
Showing 27 changed files with 2,264 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/PageCache/etc/varnish3.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sub vcl_recv {
}

# normalize url in case of leading HTTP scheme and domain
set req.url = regsub(req.url, "^http[s]?://[^/]+", "");
set req.url = regsub(req.url, "^http[s]?://", "");

# collect all cookies
std.collect(req.http.Cookie);
Expand Down
14 changes: 13 additions & 1 deletion app/code/Magento/PageCache/etc/varnish4.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ sub vcl_recv {
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
}


# normalize url in case of leading HTTP scheme and domain
set req.url = regsub(req.url, "^http[s]?://", "");

# collect all cookies
std.collect(req.http.Cookie);

# static files are always cacheable. remove SSL flag and cookie
if (req.url ~ "^/(pub/)?(media|static)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico|woff|svg)$") {
unset req.http.Https;
unset req.http.Cookie;
}

return (hash);
}

Expand Down
58 changes: 56 additions & 2 deletions dev/tests/performance/compare_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
. ' -m - mainline report file' . PHP_EOL
. ' -b - branch report file' . PHP_EOL
. ' -o - output xml file' . PHP_EOL
. ' -p - percent of measurements, that will be skipped (default = 15)' . PHP_EOL;
. ' -p - percent of measurements, that will be skipped (default = 15)' . PHP_EOL
. ' -t - plain text report file (optional)' . PHP_EOL
. ' -d - threshold for improvement/degradation for plain-text report (default = 1.5)' . PHP_EOL;

$args = getopt('m:b:o:p::');
$args = getopt('m:b:o:p:t:d:');
if (empty($args)) {
echo $usageMessage;
exit(0);
Expand All @@ -24,13 +26,18 @@
$mainlineFile = $args['m'];
$branchFile = $args['b'];
$outputFile = $args['o'];
$plainReportFile = isset($args['t']) ? $args['t'] : false;
$skipMeasurementsPercent = isset($args['p']) && $args['p'] != '' ? min(100, max(0, $args['p'])) : 15;
$threshold = isset($args['d']) ? $args['d'] : 1.5;

try {
$mainlineResults = readResponseTimeReport($mainlineFile);
$branchResults = readResponseTimeReport($branchFile);

$result = new SimpleXMLElement('<testResults version="1.2" />');
$plainResult = [
['STEP', 'DIFFERENCE', '', 'RESULT']
];
foreach (array_keys($mainlineResults) as $sampleName) {
$success = isset($mainlineResults[$sampleName]['success'])
&& $mainlineResults[$sampleName]['success']
Expand All @@ -46,13 +53,39 @@
$sample->addAttribute('s', $success ? 'true' : 'false');
$sample->addAttribute('t', round($deviation * 1000));
$sample->addAttribute('lb', $sampleName . ' degradation');

if (strpos($sampleName, 'Admin - ') === false) {
$plainResult[] = [
$sampleName,
$success ?
sprintf(
'%+.1f%%',
$deviation
) :
'',
$success ?
sprintf(
'(%+.0fms)',
-getImprovementInMilliseconds(
$mainlineResults[$sampleName]['times'],
$branchResults[$sampleName]['times']
)
) :
'',
$success ?
($deviation < -$threshold ? 'improvement' : ($deviation > $threshold ? 'DEGRADATION' : 'ok')) :
'FAILED'
];
}
}

$dom = new DOMDocument("1.0");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($result->asXML());
file_put_contents($outputFile, $dom->saveXML());

printPlainReport($plainResult, $plainReportFile);
} catch (\Exception $e) {
fwrite(STDERR, $e->getMessage() . "\n");
exit(1);
Expand Down Expand Up @@ -89,3 +122,24 @@ function getDeviation(array $mainlineResults, array $branchResults)
{
return 100 * (getMeanValue($branchResults) / getMeanValue($mainlineResults) - 1);
}

function getImprovementInMilliseconds(array $mainlineResults, array $branchResults)
{
return getMeanValue($mainlineResults) - getMeanValue($branchResults);
}

function printPlainReport(array $plainReport, $plainReportFile)
{
$result = '';
foreach ($plainReport as $sample) {
$result .= sprintf('%-32s %10s %-10s %s' . PHP_EOL, $sample[0], $sample[1], $sample[2], $sample[3]);
}
echo PHP_EOL . PHP_EOL . PHP_EOL;
echo "====================================================================" . PHP_EOL . PHP_EOL;
echo $result . PHP_EOL;
echo "====================================================================" . PHP_EOL;
echo PHP_EOL . PHP_EOL . PHP_EOL;
if ($plainReportFile !== false) {
file_put_contents($plainReportFile, $result);
}
}
16 changes: 15 additions & 1 deletion dev/tests/unit/testsuite/Magento/Indexer/App/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,31 @@ protected function setUp()
$this->entryPoint = new Indexer('reportDir', $this->filesystem, $this->processor, $this->_response);
}

public function testExecute()
/**
* @param bool $isExist
* @param array $callCount
* @dataProvider executeProvider
*/
public function testExecute($isExist, $callCount)
{
$this->_response->expects($this->once())->method('setCode')->with(0);
$this->_response->expects($this->once())->method('getCode')->will($this->returnValue(0));
$dir = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
$dir->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
$dir->expects($this->once())->method('isExist')->will($this->returnValue($isExist));
$dir->expects($this->exactly($callCount))->method('delete')->will($this->returnValue(true));
$this->filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($dir));
$this->processor->expects($this->once())->method('reindexAll');
$this->assertEquals(0, $this->entryPoint->launch()->getCode());
}

public function executeProvider(){
return [
'set1' => ['isExist' => true, 'expectsValue' => 1],
'set1' => ['delete' => false, 'expectsValue' => 0]
];
}

public function testCatchException()
{
$bootstrap = $this->getMock('Magento\Framework\App\Bootstrap', [], [], '', false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Block\Backend;

class ContainerTest extends \PHPUnit_Framework_TestCase
{
public function testPseudoConstruct()
{
$headerText = __('Indexer Management');
$buttonList = $this->getMock('\Magento\Backend\Block\Widget\Button\ButtonList', ['remove', 'add'], [], '', false);
$buttonList->expects($this->once())->method('add');
$buttonList->expects($this->once())->method('remove')->with('add');
$urlBuilderMock = $this->getMock('\Magento\Framework\UrlInterface', [], [], '', false);
$contextMock = $this->getMock('\Magento\Backend\Block\Widget\Context', ['getUrlBuilder', 'getButtonList'], [], '', false);

$contextMock->expects($this->once())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock));
$contextMock->expects($this->once())->method('getButtonList')->will($this->returnValue($buttonList));

$block = new Container($contextMock);

$this->assertEquals($block->getHeaderText(), $headerText);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;

class ScheduledTest extends \PHPUnit_Framework_TestCase
{
/**
* @param bool $rowValue
* @param string $class
* @param string $text
* @dataProvider typeProvider
*/
public function testRender($rowValue, $class, $text)
{
$html = '<span class="' . $class . '"><span>' . $text . '</span></span>';
$row = new \Magento\Framework\Object();
$column = new \Magento\Framework\Object();
$context = $this->getMockBuilder('\Magento\Backend\Block\Context')
->disableOriginalConstructor()
->getMock();

$model = new Scheduled($context);
$column->setGetter('getValue');
$row->setValue($rowValue);
$model->setColumn($column);

$result = $model->render($row);
$this->assertEquals($result, $html);
}

public function typeProvider()
{
return [
[true, 'grid-severity-notice', __('Update by Schedule')],
[false, 'grid-severity-major', __('Update on Save')],
['', 'grid-severity-major', __('Update on Save')],
];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;

class StatusTest extends \PHPUnit_Framework_TestCase
{
/**
* @param array $indexValues
* @param string $expectedResult
* @dataProvider renderDataProvider
*/
public function testRender($indexValues, $expectedResult)
{
$context = $this->getMockBuilder('\Magento\Backend\Block\Context')
->disableOriginalConstructor()
->getMock();
$model = new Status($context);
$obj = new \Magento\Framework\Object();
$obj->setGetter(null);
$obj->setDefault('');
$obj->setValue('');
$obj->setIndex($indexValues[0]);
$obj->setData($indexValues[0], $indexValues[0]);
$model->setColumn($obj);
$model->setIndex($indexValues[0]);
$result = $model->render($obj);
$this->assertEquals($result, '<span class="' . $expectedResult['class'] . '"><span>' . $expectedResult['text'] . '</span></span>');
}

public function renderDataProvider()
{
return [
'set1' => [
[\Magento\Indexer\Model\Indexer\State::STATUS_INVALID],
['class' => 'grid-severity-critical', 'text' => 'Reindex required']
],
'set2' => [
[\Magento\Indexer\Model\Indexer\State::STATUS_VALID],
['class' => 'grid-severity-notice', 'text' => 'Ready']
],
'set3' => [
[\Magento\Indexer\Model\Indexer\State::STATUS_WORKING],
['class' => 'grid-severity-major', 'text' => 'Processing']
]
];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;

class UpdatedTest extends \PHPUnit_Framework_TestCase
{
/**
* @param string $defaultValue
* @param string $assert
* @dataProvider renderProvider
*/
public function testRender($defaultValue, $assert)
{
$context = $this->getMockBuilder('\Magento\Backend\Block\Context')
->disableOriginalConstructor()
->getMock();
$model = new Updated($context);
$obj = new \Magento\Framework\Object();
$obj->setGetter('getValue');
$obj->setDefault($defaultValue);
$obj->setValue('');
$model->setColumn($obj);
$result = $model->render($obj);
$this->assertEquals($result, $assert);
}

public function renderProvider()
{
return [
['true', 'true'],
['', __('Never')]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Indexer\Block\Backend\Grid;

class ItemsUpdaterTest extends \PHPUnit_Framework_TestCase
{
/**
* @param bool $argument
* @dataProvider updateDataProvider
*/
public function testUpdate($argument)
{
$params = ['change_mode_onthefly' => 1, 'change_mode_changelog' => 2];

$auth = $this->getMockBuilder('Magento\Framework\AuthorizationInterface')
->disableOriginalConstructor()
->getMock();
$auth->expects($this->once())->method('isAllowed')->with('Magento_Indexer::changeMode')->will($this->returnValue($argument));

$model = new ItemsUpdater($auth);
$params = $model->update($params);
$this->assertEquals($argument, (isset($params['change_mode_onthefly']) && isset($params['change_mode_changelog'])));
}

/**
* @return array
*/
public function updateDataProvider()
{
return [
[true],
[false]
];
}
}
Loading

0 comments on commit f2361bd

Please sign in to comment.