Skip to content

Commit e38b2b5

Browse files
gregmagolanvicb
authored andcommitted
build(bazel): //modules/benchmarks/src/largetable/render3:perf bazel protractor test (angular#24788)
PR Close angular#24788
1 parent 445b9a5 commit e38b2b5

15 files changed

+243
-19
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "node_modules_filegroup")
55
exports_files([
66
"tsconfig.json",
77
"LICENSE",
8+
"protractor-perf.conf.js",
89
])
910

1011
# Developers should always run `bazel run :install`

modules/benchmarks/BUILD.bazel

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
filegroup(
4+
name = "favicon",
5+
srcs = [
6+
"favicon.ico",
7+
],
8+
)

modules/benchmarks/src/BUILD.bazel

+11
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ ts_library(
1212
"//packages/core",
1313
],
1414
)
15+
16+
ts_library(
17+
name = "bootstrap",
18+
srcs = [
19+
"bootstrap_ng2.ts",
20+
"bootstrap_plain.ts",
21+
],
22+
deps = [
23+
"//packages:types",
24+
],
25+
)

modules/benchmarks/src/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Benchmark Directory Layout
2+
3+
## Bazel
4+
5+
Under bazel the rules for laying out test files are slightly different. Use `largetable/render3` as an example.
6+
7+
Put the perf file in current subdirectory (ie `largetable`) such that the same perf file can be used for each of the sub-subdirectories. (ie `largetable/*` should all be testable with the same perf file `largetable/largetable_perf.spec.ts`). Under bazel, typescript protractor spec files must end with `.spec.ts` or `.test.ts`.

modules/benchmarks/src/largetable/BUILD.bazel

+12
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ ts_library(
1313
"//packages/core",
1414
],
1515
)
16+
17+
ts_library(
18+
name = "perf_lib",
19+
testonly = 1,
20+
srcs = [
21+
"largetable_perf.spec.ts",
22+
],
23+
deps = [
24+
"//modules/e2e_util:lib",
25+
"//packages:types",
26+
],
27+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {$} from 'protractor';
10+
11+
import {runBenchmark, verifyNoBrowserErrors} from '../../../e2e_util/perf_util';
12+
13+
interface Worker {
14+
id: string;
15+
prepare?(): void;
16+
work(): void;
17+
}
18+
19+
const CreateOnlyWorker: Worker = {
20+
id: 'createOnly',
21+
prepare: () => $('#destroyDom').click(),
22+
work: () => $('#createDom').click()
23+
};
24+
25+
const CreateAndDestroyWorker: Worker = {
26+
id: 'createDestroy',
27+
work: () => {
28+
$('#createDom').click();
29+
$('#destroyDom').click();
30+
}
31+
};
32+
33+
const UpdateWorker: Worker = {
34+
id: 'update',
35+
work: () => $('#createDom').click()
36+
};
37+
38+
describe('largetable benchmark perf', () => {
39+
40+
afterEach(verifyNoBrowserErrors);
41+
42+
[CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => {
43+
describe(worker.id, () => {
44+
it('should run for render3', (done) => {
45+
runTableBenchmark({
46+
id: `largeTable.render3.${worker.id}`,
47+
url: 'index.html',
48+
ignoreBrowserSynchronization: true,
49+
worker: worker
50+
}).then(done, done.fail);
51+
});
52+
});
53+
});
54+
55+
function runTableBenchmark(
56+
config: {id: string, url: string, ignoreBrowserSynchronization?: boolean, worker: Worker}) {
57+
return runBenchmark({
58+
id: config.id,
59+
url: config.url,
60+
ignoreBrowserSynchronization: config.ignoreBrowserSynchronization,
61+
params: [{name: 'cols', value: 40}, {name: 'rows', value: 200}],
62+
prepare: config.worker.prepare,
63+
work: config.worker.work
64+
});
65+
}
66+
});
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,63 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module")
3+
load("//tools:defaults.bzl", "ts_library")
4+
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
5+
load("//packages/bazel:index.bzl", "protractor_web_test")
6+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
47

5-
ng_module(
8+
ts_library(
69
name = "largetable_lib",
710
srcs = glob(
811
[
912
"**/*.ts",
1013
],
14+
exclude = ["protractor.on-prepare.ts"],
1115
),
1216
deps = [
17+
"//modules/benchmarks/src:util_lib",
1318
"//modules/benchmarks/src/largetable:util_lib",
1419
"//packages:types",
1520
"//packages/core",
1621
"@rxjs",
1722
],
1823
)
24+
25+
ng_rollup_bundle(
26+
name = "bundle",
27+
entry_point = "modules/benchmarks/src/largetable/render3/index.js",
28+
deps = [
29+
":largetable_lib",
30+
],
31+
)
32+
33+
genrule(
34+
name = "favicon",
35+
srcs = ["//modules/benchmarks:favicon"],
36+
outs = ["favicon.ico"],
37+
cmd = "cp $< $@",
38+
)
39+
40+
ts_devserver(
41+
name = "devserver",
42+
static_files = [
43+
":bundle.min_debug.js",
44+
":bundle.min.js",
45+
"index.html",
46+
":favicon",
47+
],
48+
)
49+
50+
protractor_web_test(
51+
name = "perf",
52+
configuration = "//:protractor-perf.conf.js",
53+
data = [
54+
"//packages/bazel/src/protractor/utils",
55+
"//packages/benchpress",
56+
],
57+
on_prepare = ":protractor.on-prepare.js",
58+
server = ":devserver",
59+
tags = ["manual"],
60+
deps = [
61+
"//modules/benchmarks/src/largetable:perf_lib",
62+
],
63+
)

modules/benchmarks/src/largetable/render3/index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!doctype html>
22
<html>
3+
34
<body>
45

56
<h2>Params</h2>
67
<form>
78
Cols:
89
<input type="number" name="cols" placeholder="cols" value="40">
9-
<br>
10-
Rows:
10+
<br> Rows:
1111
<input type="number" name="rows" placeholder="rows" value="200">
1212
<br>
1313
<button>Apply</button>
@@ -28,9 +28,9 @@ <h2>Render3 Largetable Benchmark</h2>
2828
<script>
2929
// TODO(mlaval): remove once we have a proper solution
3030
ngDevMode = false;
31-
var mainUrl = window.location.search.split(/[?&]main=([^&]+)/)[1]
32-
|| '../../bootstrap_ng2.js';
33-
document.write('<script src="' + mainUrl + '">\u003c/script>');
31+
var bazelBundle = document.location.search.endsWith('debug') ? 'bundle.min_debug.js' : 'bundle.min.js';
32+
document.write('<script src="' + bazelBundle + '">\u003c/script>');
3433
</script>
3534
</body>
36-
</html>
35+
36+
</html>

modules/benchmarks/src/largetable/render3/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ export function main() {
2626
profile(() => createDom(component), () => destroyDom(component), 'create'));
2727
}
2828
}
29+
30+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
const protractorUtils = require('@angular/bazel/protractor-utils');
10+
const protractor = require('protractor');
11+
12+
module.exports = function(config) {
13+
return protractorUtils.runServer(config.workspace, config.server, '-port', [])
14+
.then(serverSpec => {
15+
const serverUrl = `http://localhost:${serverSpec.port}`;
16+
// Since the browser restarts in this benchmark we need to set both the browser.baseUrl
17+
// for the first test and the protractor config.baseUrl for the subsequent tests
18+
protractor.browser.baseUrl = serverUrl;
19+
return protractor.browser.getProcessedConfig().then((config) => config.baseUrl = serverUrl);
20+
});
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2015"]
4+
}
5+
}

modules/e2e_util/BUILD.bazel

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
ts_library(
6+
name = "lib",
7+
testonly = 1,
8+
srcs = glob(["*.ts"]),
9+
deps = [
10+
"//packages:types",
11+
"//packages/benchpress",
12+
],
13+
)

modules/e2e_util/e2e_util.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ export function readCommandLine(extraOptions?: {[key: string]: any}) {
2020
const options: {[key: string]: any} = {
2121
'bundles': {describe: 'Whether to use the angular bundles or not.', default: false}
2222
};
23-
for (const key in extraOptions) {
24-
options[key] = extraOptions[key];
23+
if (extraOptions) {
24+
for (const key in extraOptions) {
25+
options[key] = extraOptions[key];
26+
}
2527
}
2628

2729
cmdArgs = yargs.usage('Angular e2e test options.').options(options).help('ng-help').wrap(40).argv;

packages/benchpress/BUILD.bazel

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
ts_library(
6+
name = "benchpress",
7+
srcs = glob(
8+
[
9+
"*.ts",
10+
"src/**/*.ts",
11+
],
12+
),
13+
module_name = "@angular/benchpress",
14+
deps = [
15+
"//packages:types",
16+
"//packages/core",
17+
],
18+
)

protractor-perf.conf.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
// Determine if we run under bazel
10+
const isBazel = !!process.env.RUNFILES;
11+
912
// Make sure that the command line is read as the first thing
1013
// as this could exit node if the help script should be printed.
11-
require('./dist/all/e2e_util/perf_util').readCommandLine();
14+
const BASE = isBazel ? 'angular/modules' : 'dist/all';
15+
require(`./${BASE}/e2e_util/perf_util`).readCommandLine();
1216

1317
var CHROME_OPTIONS = {
1418
'args': ['--js-flags=--expose-gc', '--no-sandbox'],
@@ -38,14 +42,19 @@ var BROWSER_CAPS = {
3842
}
3943
};
4044

41-
exports.config = {
45+
function mergeInto(src, target) {
46+
for (var prop in src) {
47+
target[prop] = src[prop];
48+
}
49+
return target;
50+
}
51+
52+
const config = {
4253
onPrepare: function() { beforeEach(function() { browser.ignoreSynchronization = false; }); },
4354
restartBrowserBetweenTests: true,
4455
allScriptsTimeout: 11000,
45-
specs: ['dist/all/**/e2e_test/**/*_perf.js'],
4656
capabilities: process.env.TRAVIS ? BROWSER_CAPS.ChromeOnTravis : BROWSER_CAPS.LocalChrome,
4757
directConnect: true,
48-
baseUrl: 'http://localhost:8000/',
4958
framework: 'jasmine2',
5059
jasmineNodeOpts: {
5160
showColors: true,
@@ -55,9 +64,13 @@ exports.config = {
5564
useAllAngular2AppRoots: true
5665
};
5766

58-
function mergeInto(src, target) {
59-
for (var prop in src) {
60-
target[prop] = src[prop];
61-
}
62-
return target;
67+
// Bazel has different strategy for how specs and baseUrl are specified
68+
if (!isBazel) {
69+
config.baseUrl = 'http://localhost:8000/';
70+
config.specs = [
71+
'dist/all/**/e2e_test/**/*_perf.spec.js',
72+
'dist/all/**/e2e_test/**/*_perf.js',
73+
]
6374
}
75+
76+
exports.config = config;

0 commit comments

Comments
 (0)