Skip to content

Commit e89fe49

Browse files
gurbirkalsiportante
authored andcommitted
Enhance puppeteer e2e tests to use request API for intercepting and
mocking network requests
1 parent 126b658 commit e89fe49

File tree

12 files changed

+481
-100
lines changed

12 files changed

+481
-100
lines changed

.travis.yml

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,64 @@
1-
dist: xenial
2-
language: perl
3-
perl:
4-
- "5.28"
5-
- "5.26"
6-
- "5.24"
7-
- "5.22"
8-
- "5.20"
9-
- "5.18"
10-
- "5.16"
11-
- "5.10"
12-
before_install:
13-
- sudo apt-get update
14-
install:
15-
- sudo apt-get install python python-pip bc libjson-perl libswitch-perl realpath
16-
- sudo pip install configtools elasticsearch
17-
- sudo apt-get install python-software-properties
18-
- sudo add-apt-repository ppa:fkrull/deadsnakes -y
19-
- sudo apt-get update
20-
- sudo apt-get install python3.6 --force-yes -y
21-
- sudo wget -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py
22-
- sudo python3.6 /tmp/get-pip.py
23-
- sudo pip install 'configtools<0.4.0' elasticsearch sh boto3
24-
- sudo ln -sf python3.6 /usr/bin/python3
25-
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
26-
- sudo echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
27-
- sudo apt-get update -qq
28-
- sudo apt-get install -y -qq yarn
29-
env:
30-
- PBENCH_UNITTEST_SERVER_MODE=serial
31-
script:
32-
- ./run-unittests
1+
jobs:
2+
include:
3+
- stage: "Unit Tests"
4+
name: "Unit Tests"
5+
dist: xenial
6+
language: perl
7+
perl:
8+
- "5.28"
9+
- "5.26"
10+
- "5.24"
11+
- "5.22"
12+
- "5.20"
13+
- "5.18"
14+
- "5.16"
15+
- "5.10"
16+
before_install:
17+
- sudo apt-get update
18+
install:
19+
- sudo apt-get install python python-pip bc libjson-perl libswitch-perl realpath
20+
- sudo pip install configtools elasticsearch
21+
- sudo apt-get install python-software-properties
22+
- sudo add-apt-repository ppa:fkrull/deadsnakes -y
23+
- sudo apt-get update
24+
- sudo apt-get install python3.6 --force-yes -y
25+
- sudo wget -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py
26+
- sudo python3.6 /tmp/get-pip.py
27+
- sudo pip install 'configtools<0.4.0' elasticsearch sh boto3
28+
- sudo ln -sf python3.6 /usr/bin/python3
29+
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
30+
- sudo echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
31+
- sudo apt-get update -qq
32+
- sudo apt-get install -y -qq yarn
33+
env:
34+
- PBENCH_UNITTEST_SERVER_MODE=serial
35+
script: ./run-unittests
36+
- stage: "E2E Tests"
37+
name: "E2E Tests"
38+
language: node_js
39+
node_js:
40+
- "12"
41+
dist: trusty
42+
sudo: required
43+
addons:
44+
chrome: stable
45+
hostname: localhost
46+
apt:
47+
packages:
48+
# This is required to run new chrome on old trusty
49+
- libnss3
50+
# allow headful tests
51+
before_install:
52+
# Enable user namespace cloning
53+
- "sysctl kernel.unprivileged_userns_clone=1"
54+
# Launch XVFB
55+
- "export DISPLAY=:99.0"
56+
- "sh -e /etc/init.d/xvfb start"
57+
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
58+
install:
59+
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
60+
- sudo echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
61+
- sudo apt-get update -qq
62+
- sudo apt-get install -y -qq yarn
63+
script: ./run-e2etests
64+

run-e2etests

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
dir=$(dirname $0)
4+
let sts=0
5+
6+
function tail_and_wait {
7+
pid=$1
8+
name=$2
9+
file=$3
10+
printf -- "+++ ${name} E2E Tests +++\n\n"
11+
12+
tail -n 9999999 -f ${file} --pid ${pid}
13+
if [[ $? -ne 0 ]]; then
14+
printf -- "tail -f ${file} --pid ${pid} failed\n" >&2
15+
return 1
16+
fi
17+
wait ${pid}
18+
let tw_sts=$?
19+
if [[ $tw_sts -ne 0 ]]; then
20+
status="FAILED"
21+
else
22+
status="SUCCEEDED"
23+
fi
24+
rm -f ${file}
25+
26+
printf -- "\n--- ${name} E2E Tests ($status) ---\n"
27+
return $tw_sts
28+
}
29+
30+
trap "kill -KILL -$$ > /dev/null 2>&1" INT TERM QUIT
31+
32+
> /var/tmp/dashboard.out
33+
$dir/web-server/v0.4/e2etests > /var/tmp/dashboard.out 2>&1 < /dev/null &
34+
dpid=$!
35+
36+
tail_and_wait $dpid 'Dashboard' /var/tmp/dashboard.out
37+
let sts=sts+$?
38+
39+
if [ $sts -gt 0 ]; then
40+
echo "E2E tests FAILED"
41+
fi
42+
exit $sts

web-server/v0.4/e2etests

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
cd $(dirname $0)
4+
cat > mock/datastoreConfig.js <<EOF
5+
export default {
6+
'/dev/datastoreConfig': {
7+
elasticsearch: 'http://test_domain.com',
8+
results: 'http://test_domain.com',
9+
graphql: 'http://test_domain.com',
10+
prefix: 'test_prefix.',
11+
run_index: 'test_index.',
12+
},
13+
};
14+
EOF
15+
yarn --network-timeout 1000000
16+
if [[ $? -ne 0 ]]; then
17+
echo "yarn failed!" >&2
18+
exit 1
19+
fi
20+
yarn start &
21+
if [[ $? -ne 0 ]]; then
22+
echo "yarn failed!" >&2
23+
exit 1
24+
fi
25+
sleep 60
26+
if [[ $? -ne 0 ]]; then
27+
echo "sleep failed!" >&2
28+
exit 1
29+
fi
30+
yarn test:e2e
31+
if [[ $? -ne 0 ]]; then
32+
echo "yarn e2e tests failed!" >&2
33+
exit 1
34+
fi
35+
exit 0

web-server/v0.4/mock/api.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import config from './datastoreConfig';
2+
3+
export const mockControllerAggregation = {
4+
aggregations: {
5+
controllers: {
6+
buckets: [
7+
{
8+
key: 'a_test_controller',
9+
doc_count: 1,
10+
runs_preV1: { value: null },
11+
runs: { value: 1, value_as_string: '1111-11-11' },
12+
},
13+
{
14+
key: 'b_test_controller',
15+
doc_count: 2,
16+
runs_preV1: { value: null },
17+
runs: { value: 2, value_as_string: '2222-22-22' },
18+
},
19+
],
20+
},
21+
},
22+
};
23+
24+
const datastoreConfig = config['/dev/datastoreConfig'];
25+
const prefix = datastoreConfig.prefix + datastoreConfig.run_index.slice(0, -1);
26+
export const mockIndices = [
27+
{
28+
index: `${prefix}.0000-00-00`,
29+
},
30+
{
31+
index: `${prefix}.0000-00-01`,
32+
},
33+
];
34+
35+
export const mockResults = {
36+
hits: {
37+
hits: [
38+
{
39+
fields: {
40+
'run.name': ['a_test_run'],
41+
'@metadata.controller_dir': ['test_run.test_domain.com'],
42+
'run.start': ['1111-11-11T11:11:11+00:00'],
43+
'run.id': ['1111'],
44+
'run.end': ['1111-11-11T11:11:12+00:00'],
45+
'run.controller': ['test_run.test_domain.com'],
46+
'run.config': ['test_size_1'],
47+
},
48+
},
49+
{
50+
fields: {
51+
'run.name': ['b_test_run'],
52+
'@metadata.controller_dir': ['b_test_run.test_domain.com'],
53+
'run.start': ['1111-11-11T11:11:13+00:00'],
54+
'run.id': ['2222'],
55+
'run.end': ['1111-11-11T11:11:14+00:00'],
56+
'run.controller': ['b_test_run.test_domain.com'],
57+
'run.config': ['test_size_2'],
58+
},
59+
},
60+
],
61+
},
62+
};
63+
64+
export const mockMappings = {
65+
[`${prefix}.0000-00-00`]: {
66+
mappings: {
67+
'pbench-run': {
68+
properties: {
69+
run: {
70+
properties: {
71+
config: { type: 'string', index: 'not_analyzed' },
72+
name: { type: 'string', index: 'not_analyzed' },
73+
script: { type: 'string', index: 'not_analyzed' },
74+
user: { type: 'string', index: 'not_analyzed' },
75+
},
76+
},
77+
},
78+
},
79+
},
80+
},
81+
};
82+
83+
export const mockSearch = {
84+
hits: {
85+
total: 1,
86+
hits: [
87+
{
88+
_source: {
89+
run: {
90+
config: 'test-size-1',
91+
name: 'test_run',
92+
script: 'test',
93+
user: 'test_user',
94+
},
95+
},
96+
},
97+
],
98+
},
99+
};

web-server/v0.4/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@
9898
},
9999
"husky": {
100100
"hooks": {
101-
"pre-commit": "npm run lint-staged",
102-
"pre-push": "npm run test:e2e"
101+
"pre-commit": "npm run lint-staged"
103102
}
104103
},
105104
"lint-staged": {

0 commit comments

Comments
 (0)