build: run tree benchmark tests with bazel (#28568)

PR Close #28568
This commit is contained in:
Paul Gschwendtner 2019-02-06 18:03:58 +01:00 committed by Miško Hevery
parent c916b360bf
commit aadc332be2
22 changed files with 221 additions and 313 deletions

View File

@ -0,0 +1,24 @@
load("//packages/bazel:index.bzl", "protractor_web_test_suite")
"""
Macro that can be used to define a benchmark test. This differentiates from
a normal Protractor test suite because we specify a custom "perf" configuration
that sets up "@angular/benchpress".
"""
def benchmark_test(name, server, deps, tags = []):
protractor_web_test_suite(
name = name,
configuration = "//:protractor-perf.conf.js",
data = [
"//packages/bazel/src/protractor/utils",
"//packages/benchpress",
],
on_prepare = "//modules/benchmarks:start-server.js",
server = server,
tags = tags,
deps = [
"@ngdeps//protractor",
"@ngdeps//yargs",
] + deps,
)

View File

@ -1,79 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {$} from 'protractor';
export const CreateBtn = '#createDom';
export const DestroyBtn = '#destroyDom';
export const DetectChangesBtn = '#detectChanges';
export const RootEl = '#root';
export const NumberOfChecksEl = '#numberOfChecks';
export interface Benchmark {
id: string;
url: string;
buttons: string[];
ignoreBrowserSynchronization?: boolean;
extraParams?: {name: string, value: any}[];
}
const CreateDestroyButtons: string[] = [CreateBtn, DestroyBtn];
const CreateDestroyDetectChangesButtons: string[] = [...CreateDestroyButtons, DetectChangesBtn];
export const Benchmarks: Benchmark[] = [
{
id: `deepTree.ng2`,
url: 'all/benchmarks/src/tree/ng2/index.html',
buttons: CreateDestroyDetectChangesButtons,
},
{
id: `deepTree.ng2.next`,
url: 'all/benchmarks/src/tree/ng2_next/index.html',
buttons: CreateDestroyDetectChangesButtons,
ignoreBrowserSynchronization: true,
},
{
id: `deepTree.ng2.static`,
url: 'all/benchmarks/src/tree/ng2_static/index.html',
buttons: CreateDestroyButtons,
},
{
id: `deepTree.ng2_switch`,
url: 'all/benchmarks/src/tree/ng2_switch/index.html',
buttons: CreateDestroyButtons,
},
{
id: `deepTree.ng2.render3_function`,
url: 'all/benchmarks/src/tree/render3_function/index.html',
buttons: CreateDestroyDetectChangesButtons,
ignoreBrowserSynchronization: true,
},
{
id: `deepTree.iv`,
url: 'all/benchmarks/src/tree/iv/index.html',
buttons: CreateDestroyDetectChangesButtons,
ignoreBrowserSynchronization: true,
},
{
id: `deepTree.baseline`,
url: 'all/benchmarks/src/tree/baseline/index.html',
buttons: CreateDestroyButtons,
ignoreBrowserSynchronization: true,
},
{
id: `deepTree.incremental_dom`,
url: 'all/benchmarks/src/tree/incremental_dom/index.html',
buttons: CreateDestroyButtons,
ignoreBrowserSynchronization: true,
},
{
id: `deepTree.ng1`,
url: 'all/benchmarks/src/tree/ng1/index.html',
buttons: CreateDestroyDetectChangesButtons,
}
];

View File

@ -1,93 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {runBenchmark, verifyNoBrowserErrors} from 'e2e_util/perf_util';
import {$, browser} from 'protractor';
import {Benchmark, Benchmarks, CreateBtn, DestroyBtn, DetectChangesBtn, RootEl} from './tree_data';
describe('tree benchmark perf', () => {
let _oldRootEl: any;
beforeEach(() => _oldRootEl = browser.rootEl);
afterEach(() => {
browser.rootEl = _oldRootEl;
verifyNoBrowserErrors();
});
Benchmarks.forEach(benchmark => {
describe(benchmark.id, () => {
// This is actually a destroyOnly benchmark
it('should work for createOnly', done => {
runTreeBenchmark({
id: 'createOnly',
benchmark,
prepare: () => $(CreateBtn).click(),
work: () => $(DestroyBtn).click()
}).then(done, done.fail);
});
it('should work for createOnlyForReal', done => {
runTreeBenchmark({
id: 'createOnlyForReal',
benchmark,
prepare: () => $(DestroyBtn).click(),
work: () => $(CreateBtn).click()
}).then(done, done.fail);
});
it('should work for createDestroy', done => {
runTreeBenchmark({
id: 'createDestroy',
benchmark,
work: () => {
$(DestroyBtn).click();
$(CreateBtn).click();
}
}).then(done, done.fail);
});
it('should work for update', done => {
runTreeBenchmark({id: 'update', benchmark, work: () => $(CreateBtn).click()})
.then(done, done.fail);
});
if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) {
it('should work for detectChanges', done => {
runTreeBenchmark({
id: 'detectChanges',
benchmark,
work: () => $(DetectChangesBtn).click(),
setup: () => $(DestroyBtn).click()
}).then(done, done.fail);
});
}
});
});
});
function runTreeBenchmark({id, benchmark, prepare, setup, work}: {
id: string; benchmark: Benchmark, prepare ? () : void; setup ? () : void; work(): void;
}) {
let params = [{name: 'depth', value: 11}];
if (benchmark.extraParams) {
params = params.concat(benchmark.extraParams);
}
browser.rootEl = RootEl;
return runBenchmark({
id: `${benchmark.id}.${id}`,
url: benchmark.url,
ignoreBrowserSynchronization: benchmark.ignoreBrowserSynchronization,
params: params,
work: work,
prepare: prepare,
setup: setup
});
}

View File

@ -1,63 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {openBrowser, verifyNoBrowserErrors} from 'e2e_util/e2e_util';
import {$, browser} from 'protractor';
import {Benchmark, Benchmarks, CreateBtn, DestroyBtn, DetectChangesBtn, NumberOfChecksEl, RootEl} from './tree_data';
describe('tree benchmark spec', () => {
let _oldRootEl: any;
beforeEach(() => _oldRootEl = browser.rootEl);
afterEach(() => {
browser.rootEl = _oldRootEl;
verifyNoBrowserErrors();
});
Benchmarks.forEach(benchmark => {
describe(benchmark.id, () => {
it('should work for createDestroy', () => {
openTreeBenchmark(benchmark);
$(CreateBtn).click();
expect($(RootEl).getText()).toContain('0');
$(DestroyBtn).click();
expect($(RootEl).getText()).toEqual('');
});
it('should work for update', () => {
openTreeBenchmark(benchmark);
$(CreateBtn).click();
$(CreateBtn).click();
expect($(RootEl).getText()).toContain('A');
});
if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) {
it('should work for detectChanges', () => {
openTreeBenchmark(benchmark);
$(DetectChangesBtn).click();
expect($(NumberOfChecksEl).getText()).toContain('10');
});
}
});
});
function openTreeBenchmark(benchmark: Benchmark) {
let params = [{name: 'depth', value: 4}];
if (benchmark.extraParams) {
params = params.concat(benchmark.extraParams);
}
browser.rootEl = RootEl;
openBrowser({
url: benchmark.url,
ignoreBrowserSynchronization: benchmark.ignoreBrowserSynchronization,
params: params,
});
}
});

View File

@ -4,13 +4,7 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "util_lib",
srcs = [
"util.ts",
],
deps = [
"//packages:types",
"//packages/core",
],
srcs = ["util.ts"],
)
ts_library(

View File

@ -4,25 +4,36 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "util_lib",
srcs = [
"util.ts",
],
srcs = ["util.ts"],
deps = ["//modules/benchmarks/src:util_lib"],
)
ts_library(
name = "test_utils_lib",
testonly = 1,
srcs = ["tree_perf_test_utils.ts"],
deps = [
"//modules/benchmarks/src:util_lib",
"//packages:types",
"//packages/core",
"//modules/e2e_util",
"@ngdeps//protractor",
],
)
ts_library(
name = "perf_lib",
testonly = 1,
srcs = [
"tree_perf.spec.ts",
],
srcs = ["tree_perf.spec.ts"],
deps = [
"//modules/e2e_util",
"//packages:types",
":test_utils_lib",
"@ngdeps//protractor",
],
)
ts_library(
name = "perf_detect_changes_lib",
testonly = 1,
srcs = ["tree_perf_detect_changes.spec.ts"],
deps = [
":test_utils_lib",
"@ngdeps//protractor",
],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -20,3 +21,9 @@ ts_devserver(
port = 4200,
deps = [":baseline"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/tree:perf_lib"],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -24,3 +25,9 @@ ts_devserver(
],
deps = [":incremental_dom"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/tree:perf_lib"],
)

View File

@ -1,4 +1,5 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -8,3 +9,12 @@ ts_devserver(
port = 4200,
static_files = ["tree.js"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = [
"//modules/benchmarks/src/tree:perf_detect_changes_lib",
"//modules/benchmarks/src/tree:perf_lib",
],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -23,3 +24,12 @@ ts_devserver(
],
deps = [":ng1"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = [
"//modules/benchmarks/src/tree:perf_detect_changes_lib",
"//modules/benchmarks/src/tree:perf_lib",
],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -30,3 +31,12 @@ ts_devserver(
],
deps = [":ng2"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = [
"//modules/benchmarks/src/tree:perf_detect_changes_lib",
"//modules/benchmarks/src/tree:perf_lib",
],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -24,3 +25,12 @@ ts_devserver(
scripts = ["@ngdeps//node_modules/tslib:tslib.js"],
deps = [":ng2_next"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = [
"//modules/benchmarks/src/tree:perf_detect_changes_lib",
"//modules/benchmarks/src/tree:perf_lib",
],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -28,3 +29,9 @@ ts_devserver(
],
deps = [":ng2_static"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/tree:perf_lib"],
)

View File

@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -30,3 +31,9 @@ ts_devserver(
],
deps = [":ng2_switch"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/tree:perf_lib"],
)

View File

@ -1,8 +1,8 @@
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
load("//tools:defaults.bzl", "ng_module", "ng_rollup_bundle")
load("//packages/bazel:index.bzl", "protractor_web_test_suite")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
ng_module(
name = "tree_lib",
@ -36,22 +36,12 @@ ts_devserver(
tags = ["ivy-only"],
)
protractor_web_test_suite(
benchmark_test(
name = "perf",
configuration = "//:protractor-perf.conf.js",
data = [
"//packages/bazel/src/protractor/utils",
"//packages/benchpress",
],
on_prepare = ":protractor.on_prepare.js",
server = ":devserver",
tags = [
"ivy-only",
],
tags = ["ivy-only"],
deps = [
"//modules/benchmarks/src/tree:perf_detect_changes_lib",
"//modules/benchmarks/src/tree:perf_lib",
"@ngdeps//node-uuid",
"@ngdeps//protractor",
"@ngdeps//yargs",
],
)

View File

@ -1,5 +1,6 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
load("//tools:defaults.bzl", "ts_library")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
@ -22,5 +23,12 @@ ts_devserver(
scripts = ["@ngdeps//node_modules/tslib:tslib.js"],
deps = [":render3_function_lib"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = [
"//modules/benchmarks/src/tree:perf_detect_changes_lib",
"//modules/benchmarks/src/tree:perf_lib",
],
)

View File

@ -6,10 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {$, browser} from 'protractor';
import {openBrowser} from '../../../e2e_util/e2e_util';
import {runBenchmark} from '../../../e2e_util/perf_util';
import {$} from 'protractor';
import {openTreeBenchmark, runTreeBenchmark} from './tree_perf_test_utils';
describe('benchmark render', () => {
it('should work for createDestroy', () => {
@ -26,20 +24,15 @@ describe('benchmark render', () => {
$('#createDom').click();
expect($('#root').getText()).toContain('A');
});
it('should work for detectChanges', () => {
openTreeBenchmark();
$('#detectChanges').click();
expect($('#numberOfChecks').getText()).toContain('10');
});
});
describe('benchmarks', () => {
it('should work for createOnly', done => {
runTreeBenchmark({
id: 'createOnly',
// This cannot be called "createOnly" because the actual destroy benchmark
// has the "createOnly" id already. See: https://github.com/angular/angular/pull/21503
id: 'createOnlyForReal',
prepare: () => $('#destroyDom').click(),
work: () => $('#createDom').click()
}).then(done, done.fail);
@ -47,6 +40,8 @@ describe('benchmarks', () => {
it('should work for destroy', done => {
runTreeBenchmark({
// This is actually a benchmark for destroying the dom, but it has been accidentally
// named "createOnly". See https://github.com/angular/angular/pull/21503.
id: 'createOnly',
prepare: () => $('#createDom').click(),
work: () => $('#destroyDom').click()
@ -66,36 +61,4 @@ describe('benchmarks', () => {
it('should work for update', done => {
runTreeBenchmark({id: 'update', work: () => $('#createDom').click()}).then(done, done.fail);
});
it('should work for detectChanges', done => {
runTreeBenchmark({
id: 'detectChanges',
work: () => $('#detectChanges').click(),
setup: () => $('#destroyDom').click()
}).then(done, done.fail);
});
});
function runTreeBenchmark({id, prepare, setup, work}:
{id: string; prepare ? () : void; setup ? () : void; work(): void;}) {
browser.rootEl = '#root';
return runBenchmark({
id: id,
url: '',
ignoreBrowserSynchronization: true,
params: [{name: 'depth', value: 11}],
work: work,
prepare: prepare,
setup: setup
});
}
function openTreeBenchmark() {
browser.rootEl = '#root';
openBrowser({
url: '',
ignoreBrowserSynchronization: true,
params: [{name: 'depth', value: 4}],
});
}

View File

@ -0,0 +1,28 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {$} from 'protractor';
import {openTreeBenchmark, runTreeBenchmark} from './tree_perf_test_utils';
describe('benchmark render', () => {
it('should work for detectChanges', () => {
openTreeBenchmark();
$('#detectChanges').click();
expect($('#numberOfChecks').getText()).toContain('10');
});
});
describe('benchmarks', () => {
it('should work for detectChanges', async() => {
await runTreeBenchmark({
id: 'detectChanges',
work: () => $('#detectChanges').click(),
setup: () => $('#destroyDom').click()
});
});
});

View File

@ -0,0 +1,36 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {browser} from 'protractor';
import {openBrowser} from '../../../e2e_util/e2e_util';
import {runBenchmark} from '../../../e2e_util/perf_util';
export function runTreeBenchmark({id, prepare, setup, work}: {
id: string; prepare ? () : void; setup ? () : void; work(): void;
}) {
browser.rootEl = '#root';
return runBenchmark({
id: id,
url: '',
ignoreBrowserSynchronization: true,
params: [{name: 'depth', value: 11}],
work: work,
prepare: prepare,
setup: setup
});
}
export function openTreeBenchmark() {
browser.rootEl = '#root';
openBrowser({
url: '',
ignoreBrowserSynchronization: true,
params: [{name: 'depth', value: 4}],
});
}

View File

@ -0,0 +1,18 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const protractorUtils = require('@angular/bazel/protractor-utils');
const protractor = require('protractor');
module.exports = async function(config) {
const {port} = await protractorUtils.runServer(config.workspace, config.server, '-port', []);
const processedConfig = await protractor.browser.getProcessedConfig();
const serverUrl = `http://localhost:${port}`;
return processedConfig.baseUrl = protractor.browser.baseUrl = serverUrl;
};

View File

@ -12,6 +12,7 @@ ts_library(
"@ngdeps//@types/fs-extra",
"@ngdeps//@types/selenium-webdriver",
"@ngdeps//fs-extra",
"@ngdeps//node-uuid",
"@ngdeps//protractor",
"@ngdeps//selenium-webdriver",
],

View File

@ -28,8 +28,10 @@
"benchmarks/src/old",
"benchmarks/src/**/index_aot.ts",
"benchmarks_external",
"playground",
"payload_tests"
"payload_tests",
// Tests which are already migrated to Bazel:
"playground/",
"benchmarks/src/tree"
],
"angularCompilerOptions": {
"skipTemplateCodegen": true