Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 8b18bbe

Browse files
authored
Merge pull request #62 from magento/varnish-tests
Varnish tests
2 parents 988a00d + 56485cb commit 8b18bbe

10 files changed

+135
-57
lines changed

etc/config.yaml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ repository_url:
2323
# - "git@github.com:magento/magento2-sample-data.git"
2424
# - "git@github.com:magento/magento2-sample-data-ee.git"
2525
# - "git@github.com:magento/magento2b2b.git"
26+
# If set to 1, shallow clone will be used to speed up the project initialization. Custom branches will not be available if shallow clone used
27+
shallow_clone: 0
2628

2729
guest:
2830
# [To apply changes: init_project.sh -f] NFS will be used for folder synchronization on *nix and OSX hosts by default.
@@ -41,7 +43,7 @@ environment:
4143
php_version: "7.0"
4244
composer_prefer_source: 0
4345
# [To apply changes: m-reinstall OR m-varnish enable/disable]
44-
use_varnish: 0
46+
use_varnish: 1
4547
# [To apply changes: m-reinstall] Possible values: mysql, elasticsearch
4648
search_engine: "elasticsearch"
4749

init_project.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ repository_url_ee="$(bash "${devbox_dir}/scripts/get_config_value.sh" "repositor
3434
composer_project_name="$(bash "${devbox_dir}/scripts/get_config_value.sh" "composer_project_name")"
3535
composer_project_url="$(bash "${devbox_dir}/scripts/get_config_value.sh" "composer_project_url")"
3636
checkout_source_from="$(bash "${devbox_dir}/scripts/get_config_value.sh" "checkout_source_from")"
37+
use_git_shallow_clone="$(bash "${devbox_dir}/scripts/get_config_value.sh" "repository_url_shallow_clone")"
3738

3839
function checkoutSourceCodeFromGit()
3940
{
@@ -119,13 +120,17 @@ function initGitRepository()
119120
fi
120121
directory="${magento_ce_dir}/${BASH_REMATCH[1]}"
121122
fi
122-
git clone ${repo} "${directory}" 2> >(logError) > >(log)
123123

124-
if [[ -n ${branch} ]]; then
125-
status "Checking out branch ${branch} of ${repository_name} repository"
126-
cd "${directory}"
127-
git fetch 2> >(logError) > >(log)
128-
git checkout ${branch} 2> >(log) > >(log)
124+
if [[ ${use_git_shallow_clone} -eq 1 ]] ; then
125+
git clone --depth 1 ${repo} "${directory}" 2> >(logError) > >(log)
126+
else
127+
git clone ${repo} "${directory}" 2> >(logError) > >(log)
128+
if [[ -n ${branch} ]]; then
129+
status "Checking out branch ${branch} of ${repository_name} repository"
130+
cd "${directory}"
131+
git fetch 2> >(logError) > >(log)
132+
git checkout ${branch} 2> >(log) > >(log)
133+
fi
129134
fi
130135
cd "${devbox_dir}"
131136
}

m-varnish

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ arguments=$@
1818
cd "${devbox_dir}"
1919
executeInMagento2Container "${devbox_dir}/scripts/guest/m-varnish" -- ${arguments} 2> >(logError)
2020

21-
bash "${devbox_dir}/k-rebuild-environment" "$@" 2> >(logError)
21+
bash "${devbox_dir}/k-rebuild-environment" 2> >(logError)
22+
23+
# TODO: Remove when MySQL state is persisted between rebuilds
24+
bash "${devbox_dir}/m-reinstall" 2> >(logError)
2225

2326
info "$(regular)See details in $(bold)${devbox_dir}/log/${current_script_name}.log$(regular). For debug output set $(bold)debug:devbox_project$(regular) to $(bold)1$(regular) in $(bold)etc/config.yaml$(regular)"

scripts/guest/configure_varnish

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,10 @@ restart_services=0
2020
use_varnish="$(bash "${devbox_dir}/scripts/get_config_value.sh" "environment_use_varnish")"
2121
if [[ $use_varnish == 1 ]]; then
2222
status "Updating Magento database to use varnish FPC"
23-
# TODO: Make credentials configurable
24-
mysql -u"root" -p"123123q" -h"magento2-mysql" -D magento -e "INSERT INTO core_config_data
25-
( scope, scope_id, path, value ) VALUES
26-
( 'default', '0', 'system/full_page_cache/caching_application', '2' )
27-
ON DUPLICATE KEY UPDATE value = 2
28-
;"
23+
"${DEVBOX_ROOT}/scripts/guest/update_magento_config" 'system/full_page_cache/caching_application' '2'
2924
else
3025
status "Updating Magento database to not use varnish FPC"
31-
mysql -u"root" -p"123123q" -h"magento2-mysql" -D magento -e "INSERT INTO core_config_data
32-
( scope, scope_id, path, value ) VALUES
33-
( 'default', '0', 'system/full_page_cache/caching_application', '1' )
34-
ON DUPLICATE KEY UPDATE value = 1
35-
;"
26+
"${DEVBOX_ROOT}/scripts/guest/update_magento_config" 'system/full_page_cache/caching_application' '1'
3627
fi
3728

3829
decrementNestingLevel

tests/CeFromComposerNoNfsTest.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function testCeFromComposerNoNfs()
6464
assertRedisCacheIsEnabled
6565

6666
executeExtendedCommonAssertions
67+
68+
assertMainPageServedByBuiltInCache
6769
}
6870

6971
## Call and Run all Tests

tests/EeLinkingTest.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ See logs in ${logs_dir}"
5151

5252
## Tests
5353

54-
function testNoCustomConfigBasicTest()
54+
function testEeLinking()
5555
{
56-
current_config_name="no_custom_config"
56+
current_config_name="ce_shallow_clone_no_nfs"
5757
current_codebase="ee"
5858
installEnvironment
5959
# assertVarnishDisabled
@@ -70,6 +70,11 @@ function testNoCustomConfigBasicTest()
7070
assertMagentoSwitchToCeWorks
7171
assertMagentoFrontendAccessible
7272
assertMagentoEditionIsCE
73+
74+
assertMainPageServedByVarnish
75+
76+
assertVarnishDisablingWorks
77+
assertVarnishEnablingWorks
7378
}
7479

7580
## Call and Run all Tests

tests/NoCustomConfigBasicTest.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ See logs in ${logs_dir}"
5151

5252
## Tests
5353

54-
function testNoCustomConfigBasicTest()
54+
function testNoCustomConfigBasic()
5555
{
56-
current_config_name="no_custom_config"
56+
current_config_name="ce_shallow_clone_no_nfs"
5757
current_codebase="ce"
5858
installEnvironment
5959
# assertVarnishDisabled

tests/_files/ce23_with_sample_data_mysql_search_no_nfs_config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ repository_url:
2020
ee: ""
2121
additional_repositories:
2222
- "git@github.com:magento/magento2-sample-data.git::2.3"
23-
# - "git@github.com:magento/magento2-sample-data-ee.git"
24-
# - "git@github.com:magento/magento2b2b.git"
23+
# - "git@github.com:magento/magento2-sample-data-ee.git"
24+
# - "git@github.com:magento/magento2b2b.git"
25+
# If set to 1, shallow clone will be used to speed up the project initialization
26+
shallow_clone: 0
2527

2628
guest:
2729
# [To apply changes: init_project.sh -f] NFS will be used for folder synchronization on *nix and OSX hosts by default.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# [To apply changes: init_project.sh -fc] Possible values: git, composer
2+
checkout_source_from: "git"
3+
4+
composer_project:
5+
# Current section used only if 'checkout_source_from' is set to 'composer'
6+
7+
# [To apply changes: init_project.sh -fc]
8+
# Custom version can be provided by using '={version}' appended to repo name. E.g. name: "magento/project-community-edition=2.2.0". Otherwise, default version is used
9+
name: "magento/project-community-edition"
10+
# Make sure to specify valid keys for this repository in etc/composer/auth.json
11+
url: "https://repo.magento.com"
12+
13+
repository_url:
14+
# Current section used only if 'checkout_source_from' is set to 'git'
15+
16+
# [To apply changes: init_project.sh -fc]
17+
# git@github.com:magento/magento2ce.git OR custom one. Use '::' to specify a specific branch, e.g: git@github.com:magento/magento2.git::2.1
18+
ce: "git@github.com:magento/magento2.git"
19+
# git@github.com:magento/magento2ee.git OR custom one
20+
ee: ""
21+
additional_repositories:
22+
# [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f]
23+
# - "git@github.com:magento/magento2-sample-data.git"
24+
# - "git@github.com:magento/magento2-sample-data-ee.git"
25+
# - "git@github.com:magento/magento2b2b.git"
26+
# If set to 1, shallow clone will be used to speed up the project initialization
27+
shallow_clone: 1
28+
29+
guest:
30+
# [To apply changes: init_project.sh -f] NFS will be used for folder synchronization on *nix and OSX hosts by default.
31+
use_nfs: 0
32+
# [To apply changes: init_project.sh -f] The placeholder IP will be replaced with auto-detected value, unless modified manually before execution of "init_project.sh" script.
33+
nfs_server_ip: "0.0.0.0"
34+
# [To apply changes: devbox reload] Default is 2Gb, around 3Gb is necessary to run functional tests.
35+
memory: 2048
36+
# Recommended number of CPUs is 2
37+
cpus: 1
38+
ip_address: "192.168.10.2"
39+
forwarded_ssh_port: 3000
40+
41+
environment:
42+
# [To apply changes: devbox reload] Valid versions: 5.6, 7.0, 7.1, 7.2
43+
php_version: "7.0"
44+
composer_prefer_source: 0
45+
# [To apply changes: m-reinstall OR m-varnish enable/disable]
46+
use_varnish: 1
47+
# [To apply changes: m-reinstall] Possible values: mysql, elasticsearch
48+
search_engine: "elasticsearch"
49+
50+
magento:
51+
# [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f] Generate customer (customer@example.com:123123qQ), category, simple product, configurable product after successful Magento installation
52+
generate_basic_data: 1
53+
# [To apply changes: init_project.sh -f]
54+
host_name: "magento2.devbox2"
55+
# [To apply changes: m-reinstall]
56+
admin_frontname: "admin"
57+
language: "en_US"
58+
timezone: "America/Chicago"
59+
currency: "USD"
60+
admin_user: "admin"
61+
admin_password: "123123q"
62+
# [Changes applied on m-clear-cache] Available options: developer, production, default
63+
mode: "developer"
64+
65+
debug:
66+
# [Changes applied on m-clear-cache] Enable template path and block name hints on storefront
67+
magento_storefront: 0
68+
# [Changes applied on m-clear-cache] Enable template path hints in the admin panel
69+
magento_admin: 0
70+
# [Changes applied immediately] Enable detailed output from all scripts provided by current devbox project
71+
devbox_project: 0

tests/include/assertions.sh

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -197,34 +197,44 @@ function assertVarnishEnablingWorks()
197197

198198
cd "${devbox_dir}"
199199
bash m-varnish enable >>${current_log_file_path} 2>&1
200-
assertVarnishEnabled
201200
assertMagentoFrontendAccessible
201+
assertMainPageServedByVarnish
202202
}
203203

204-
function assertVarnishEnabled()
204+
function assertMainPageServedByVarnish()
205205
{
206-
echo "${blue}## assertVarnishEnabled${regular}"
207-
echo "## assertVarnishEnabled" >>${current_log_file_path}
208-
209-
listenerOnPort80="$(devbox ssh -c 'sudo netstat -tulnp | grep ':::80[^0-9]'')"
210-
assertTrue 'Varnish is not listening on port 80' '[[ ${listenerOnPort80} =~ varnishd ]]'
211-
212-
listenerOnPort8080="$(devbox ssh -c 'sudo netstat -tulnp | grep ':::8080[^0-9]'')"
213-
assertTrue 'Apache is not listening on port 8080' '[[ ${listenerOnPort8080} =~ apache2 ]]'
206+
echo "${blue}## assertMainPageServedByVarnish${regular}"
207+
echo "## assertMainPageServedByVarnish" >>${current_log_file_path}
214208

215-
varnish_version="$(devbox ssh -c 'varnishd -V')"
216-
version_pattern="4\.[0-9]+\.[0-9]+"
217-
assertTrue 'Varnish version should be 4.x.x' '[[ ${varnish_version} =~ ${version_pattern} ]]'
209+
curl "${current_magento_base_url}" > /dev/null 2>&1
210+
is_cache_hit="$(curl "${current_magento_base_url}" -v 2>&1 | grep "X-Magento-Cache-Debug: HIT")"
211+
if [[ ${is_cache_hit} == '' ]]; then
212+
fail 'Main page is not served from cache (or Magento is not in Developer mode)'
213+
else
214+
# "Age:" header is available when Varnish is on, however it is not available when built-cache is enabled
215+
cache_tags_available="$(curl "${current_magento_base_url}" -v 2>&1 | grep "Age:")"
216+
if [[ ${cache_tags_available} == '' ]]; then
217+
fail 'Built-in cache seems to be enabled instead of Varnish'
218+
fi
219+
fi
218220
}
219221

220-
function assertMainPageServedByVarnish()
222+
function assertMainPageServedByBuiltInCache()
221223
{
222-
echo "${blue}## assertMainPageServedByVarnish${regular}"
223-
echo "## assertMainPageServedByVarnish" >>${current_log_file_path}
224+
echo "${blue}## assertMainPageServedByBuiltInCache${regular}"
225+
echo "## assertMainPageServedByBuiltInCache" >>${current_log_file_path}
224226

225227
curl "${current_magento_base_url}" > /dev/null 2>&1
226-
is_varnish_hit="$(curl "${current_magento_base_url}" -v 2>&1 | grep "X-Magento-Cache-Debug: HIT")"
227-
assertFalse 'Main page is not served by Varnish (or Magento is not in Developer mode)' '[[ ${is_varnish_hit} == '' ]]'
228+
is_cache_hit="$(curl "${current_magento_base_url}" -v 2>&1 | grep "X-Magento-Cache-Debug: HIT")"
229+
if [[ ${is_cache_hit} == '' ]]; then
230+
fail 'Main page is not served from cache (or Magento is not in Developer mode)'
231+
else
232+
# "Age:" header is available when Varnish is on, however it is not available when built-cache is enabled
233+
cache_tags_available="$(curl "${current_magento_base_url}" -v 2>&1 | grep "Age:")"
234+
if [[ ${cache_tags_available} != '' ]]; then
235+
fail 'Varnish cache seems to be enabled instead of built-in cache'
236+
fi
237+
fi
228238
}
229239

230240
function assertVarnishDisablingWorks()
@@ -235,21 +245,8 @@ function assertVarnishDisablingWorks()
235245
cd "${devbox_dir}"
236246
bash m-varnish disable >>${current_log_file_path} 2>&1
237247

238-
assertVarnishDisabled
239248
assertMagentoFrontendAccessible
240-
}
241-
242-
function assertVarnishDisabled()
243-
{
244-
echo "${blue}## assertVarnishDisabled${regular}"
245-
echo "## assertVarnishDisabled" >>${current_log_file_path}
246-
247-
cd "${devbox_dir}"
248-
listenerOnPort80="$(devbox ssh -c 'sudo netstat -tulnp | grep ':::80[^0-9]'')"
249-
assertTrue 'Apache is not listening on port 80' '[[ ${listenerOnPort80} =~ apache2 ]]'
250-
251-
listenerOnPort8080="$(devbox ssh -c 'sudo netstat -tulnp | grep ':::8080[^0-9]'')"
252-
assertFalse 'Varnish shout not listen on port 8080' '[[ ${listenerOnPort8080} =~ varnishd ]]'
249+
assertMainPageServedByBuiltInCache
253250
}
254251

255252
function assertNoErrorsInLogs()

0 commit comments

Comments
 (0)