Skip to content

Commit f2361bd

Browse files
author
Roman Ganin
committed
Merge pull request #95 from magento-troll/troll_s30
[Troll] Varnish updates and Unit Tests Coverage
2 parents dc51ad1 + 5059581 commit f2361bd

27 files changed

+2264
-11
lines changed

app/code/Magento/PageCache/etc/varnish3.vcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sub vcl_recv {
4848
}
4949

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

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

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ sub vcl_recv {
3939
if (req.method != "GET" && req.method != "HEAD") {
4040
return (pass);
4141
}
42-
42+
43+
# normalize url in case of leading HTTP scheme and domain
44+
set req.url = regsub(req.url, "^http[s]?://", "");
45+
46+
# collect all cookies
47+
std.collect(req.http.Cookie);
48+
49+
# static files are always cacheable. remove SSL flag and cookie
50+
if (req.url ~ "^/(pub/)?(media|static)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico|woff|svg)$") {
51+
unset req.http.Https;
52+
unset req.http.Cookie;
53+
}
54+
4355
return (hash);
4456
}
4557

dev/tests/performance/compare_reports.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
. ' -m - mainline report file' . PHP_EOL
1414
. ' -b - branch report file' . PHP_EOL
1515
. ' -o - output xml file' . PHP_EOL
16-
. ' -p - percent of measurements, that will be skipped (default = 15)' . PHP_EOL;
16+
. ' -p - percent of measurements, that will be skipped (default = 15)' . PHP_EOL
17+
. ' -t - plain text report file (optional)' . PHP_EOL
18+
. ' -d - threshold for improvement/degradation for plain-text report (default = 1.5)' . PHP_EOL;
1719

18-
$args = getopt('m:b:o:p::');
20+
$args = getopt('m:b:o:p:t:d:');
1921
if (empty($args)) {
2022
echo $usageMessage;
2123
exit(0);
@@ -24,13 +26,18 @@
2426
$mainlineFile = $args['m'];
2527
$branchFile = $args['b'];
2628
$outputFile = $args['o'];
29+
$plainReportFile = isset($args['t']) ? $args['t'] : false;
2730
$skipMeasurementsPercent = isset($args['p']) && $args['p'] != '' ? min(100, max(0, $args['p'])) : 15;
31+
$threshold = isset($args['d']) ? $args['d'] : 1.5;
2832

2933
try {
3034
$mainlineResults = readResponseTimeReport($mainlineFile);
3135
$branchResults = readResponseTimeReport($branchFile);
3236

3337
$result = new SimpleXMLElement('<testResults version="1.2" />');
38+
$plainResult = [
39+
['STEP', 'DIFFERENCE', '', 'RESULT']
40+
];
3441
foreach (array_keys($mainlineResults) as $sampleName) {
3542
$success = isset($mainlineResults[$sampleName]['success'])
3643
&& $mainlineResults[$sampleName]['success']
@@ -46,13 +53,39 @@
4653
$sample->addAttribute('s', $success ? 'true' : 'false');
4754
$sample->addAttribute('t', round($deviation * 1000));
4855
$sample->addAttribute('lb', $sampleName . ' degradation');
56+
57+
if (strpos($sampleName, 'Admin - ') === false) {
58+
$plainResult[] = [
59+
$sampleName,
60+
$success ?
61+
sprintf(
62+
'%+.1f%%',
63+
$deviation
64+
) :
65+
'',
66+
$success ?
67+
sprintf(
68+
'(%+.0fms)',
69+
-getImprovementInMilliseconds(
70+
$mainlineResults[$sampleName]['times'],
71+
$branchResults[$sampleName]['times']
72+
)
73+
) :
74+
'',
75+
$success ?
76+
($deviation < -$threshold ? 'improvement' : ($deviation > $threshold ? 'DEGRADATION' : 'ok')) :
77+
'FAILED'
78+
];
79+
}
4980
}
5081

5182
$dom = new DOMDocument("1.0");
5283
$dom->preserveWhiteSpace = false;
5384
$dom->formatOutput = true;
5485
$dom->loadXML($result->asXML());
5586
file_put_contents($outputFile, $dom->saveXML());
87+
88+
printPlainReport($plainResult, $plainReportFile);
5689
} catch (\Exception $e) {
5790
fwrite(STDERR, $e->getMessage() . "\n");
5891
exit(1);
@@ -89,3 +122,24 @@ function getDeviation(array $mainlineResults, array $branchResults)
89122
{
90123
return 100 * (getMeanValue($branchResults) / getMeanValue($mainlineResults) - 1);
91124
}
125+
126+
function getImprovementInMilliseconds(array $mainlineResults, array $branchResults)
127+
{
128+
return getMeanValue($mainlineResults) - getMeanValue($branchResults);
129+
}
130+
131+
function printPlainReport(array $plainReport, $plainReportFile)
132+
{
133+
$result = '';
134+
foreach ($plainReport as $sample) {
135+
$result .= sprintf('%-32s %10s %-10s %s' . PHP_EOL, $sample[0], $sample[1], $sample[2], $sample[3]);
136+
}
137+
echo PHP_EOL . PHP_EOL . PHP_EOL;
138+
echo "====================================================================" . PHP_EOL . PHP_EOL;
139+
echo $result . PHP_EOL;
140+
echo "====================================================================" . PHP_EOL;
141+
echo PHP_EOL . PHP_EOL . PHP_EOL;
142+
if ($plainReportFile !== false) {
143+
file_put_contents($plainReportFile, $result);
144+
}
145+
}

dev/tests/unit/testsuite/Magento/Indexer/App/IndexerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,31 @@ protected function setUp()
4242
$this->entryPoint = new Indexer('reportDir', $this->filesystem, $this->processor, $this->_response);
4343
}
4444

45-
public function testExecute()
45+
/**
46+
* @param bool $isExist
47+
* @param array $callCount
48+
* @dataProvider executeProvider
49+
*/
50+
public function testExecute($isExist, $callCount)
4651
{
4752
$this->_response->expects($this->once())->method('setCode')->with(0);
4853
$this->_response->expects($this->once())->method('getCode')->will($this->returnValue(0));
4954
$dir = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
5055
$dir->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
56+
$dir->expects($this->once())->method('isExist')->will($this->returnValue($isExist));
57+
$dir->expects($this->exactly($callCount))->method('delete')->will($this->returnValue(true));
5158
$this->filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($dir));
5259
$this->processor->expects($this->once())->method('reindexAll');
5360
$this->assertEquals(0, $this->entryPoint->launch()->getCode());
5461
}
5562

63+
public function executeProvider(){
64+
return [
65+
'set1' => ['isExist' => true, 'expectsValue' => 1],
66+
'set1' => ['delete' => false, 'expectsValue' => 0]
67+
];
68+
}
69+
5670
public function testCatchException()
5771
{
5872
$bootstrap = $this->getMock('Magento\Framework\App\Bootstrap', [], [], '', false);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Indexer\Block\Backend;
7+
8+
class ContainerTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function testPseudoConstruct()
11+
{
12+
$headerText = __('Indexer Management');
13+
$buttonList = $this->getMock('\Magento\Backend\Block\Widget\Button\ButtonList', ['remove', 'add'], [], '', false);
14+
$buttonList->expects($this->once())->method('add');
15+
$buttonList->expects($this->once())->method('remove')->with('add');
16+
$urlBuilderMock = $this->getMock('\Magento\Framework\UrlInterface', [], [], '', false);
17+
$contextMock = $this->getMock('\Magento\Backend\Block\Widget\Context', ['getUrlBuilder', 'getButtonList'], [], '', false);
18+
19+
$contextMock->expects($this->once())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock));
20+
$contextMock->expects($this->once())->method('getButtonList')->will($this->returnValue($buttonList));
21+
22+
$block = new Container($contextMock);
23+
24+
$this->assertEquals($block->getHeaderText(), $headerText);
25+
}
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;
7+
8+
class ScheduledTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @param bool $rowValue
12+
* @param string $class
13+
* @param string $text
14+
* @dataProvider typeProvider
15+
*/
16+
public function testRender($rowValue, $class, $text)
17+
{
18+
$html = '<span class="' . $class . '"><span>' . $text . '</span></span>';
19+
$row = new \Magento\Framework\Object();
20+
$column = new \Magento\Framework\Object();
21+
$context = $this->getMockBuilder('\Magento\Backend\Block\Context')
22+
->disableOriginalConstructor()
23+
->getMock();
24+
25+
$model = new Scheduled($context);
26+
$column->setGetter('getValue');
27+
$row->setValue($rowValue);
28+
$model->setColumn($column);
29+
30+
$result = $model->render($row);
31+
$this->assertEquals($result, $html);
32+
}
33+
34+
public function typeProvider()
35+
{
36+
return [
37+
[true, 'grid-severity-notice', __('Update by Schedule')],
38+
[false, 'grid-severity-major', __('Update on Save')],
39+
['', 'grid-severity-major', __('Update on Save')],
40+
];
41+
}
42+
43+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;
7+
8+
class StatusTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @param array $indexValues
12+
* @param string $expectedResult
13+
* @dataProvider renderDataProvider
14+
*/
15+
public function testRender($indexValues, $expectedResult)
16+
{
17+
$context = $this->getMockBuilder('\Magento\Backend\Block\Context')
18+
->disableOriginalConstructor()
19+
->getMock();
20+
$model = new Status($context);
21+
$obj = new \Magento\Framework\Object();
22+
$obj->setGetter(null);
23+
$obj->setDefault('');
24+
$obj->setValue('');
25+
$obj->setIndex($indexValues[0]);
26+
$obj->setData($indexValues[0], $indexValues[0]);
27+
$model->setColumn($obj);
28+
$model->setIndex($indexValues[0]);
29+
$result = $model->render($obj);
30+
$this->assertEquals($result, '<span class="' . $expectedResult['class'] . '"><span>' . $expectedResult['text'] . '</span></span>');
31+
}
32+
33+
public function renderDataProvider()
34+
{
35+
return [
36+
'set1' => [
37+
[\Magento\Indexer\Model\Indexer\State::STATUS_INVALID],
38+
['class' => 'grid-severity-critical', 'text' => 'Reindex required']
39+
],
40+
'set2' => [
41+
[\Magento\Indexer\Model\Indexer\State::STATUS_VALID],
42+
['class' => 'grid-severity-notice', 'text' => 'Ready']
43+
],
44+
'set3' => [
45+
[\Magento\Indexer\Model\Indexer\State::STATUS_WORKING],
46+
['class' => 'grid-severity-major', 'text' => 'Processing']
47+
]
48+
];
49+
}
50+
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;
7+
8+
class UpdatedTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @param string $defaultValue
12+
* @param string $assert
13+
* @dataProvider renderProvider
14+
*/
15+
public function testRender($defaultValue, $assert)
16+
{
17+
$context = $this->getMockBuilder('\Magento\Backend\Block\Context')
18+
->disableOriginalConstructor()
19+
->getMock();
20+
$model = new Updated($context);
21+
$obj = new \Magento\Framework\Object();
22+
$obj->setGetter('getValue');
23+
$obj->setDefault($defaultValue);
24+
$obj->setValue('');
25+
$model->setColumn($obj);
26+
$result = $model->render($obj);
27+
$this->assertEquals($result, $assert);
28+
}
29+
30+
public function renderProvider()
31+
{
32+
return [
33+
['true', 'true'],
34+
['', __('Never')]
35+
];
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Indexer\Block\Backend\Grid;
7+
8+
class ItemsUpdaterTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @param bool $argument
12+
* @dataProvider updateDataProvider
13+
*/
14+
public function testUpdate($argument)
15+
{
16+
$params = ['change_mode_onthefly' => 1, 'change_mode_changelog' => 2];
17+
18+
$auth = $this->getMockBuilder('Magento\Framework\AuthorizationInterface')
19+
->disableOriginalConstructor()
20+
->getMock();
21+
$auth->expects($this->once())->method('isAllowed')->with('Magento_Indexer::changeMode')->will($this->returnValue($argument));
22+
23+
$model = new ItemsUpdater($auth);
24+
$params = $model->update($params);
25+
$this->assertEquals($argument, (isset($params['change_mode_onthefly']) && isset($params['change_mode_changelog'])));
26+
}
27+
28+
/**
29+
* @return array
30+
*/
31+
public function updateDataProvider()
32+
{
33+
return [
34+
[true],
35+
[false]
36+
];
37+
}
38+
}

0 commit comments

Comments
 (0)