build: run largetable benchmark tests with bazel (#28645)

PR Close #28645
This commit is contained in:
Paul Gschwendtner 2019-02-11 19:36:45 +01:00 committed by Miško Hevery
parent 1a326d5690
commit 13685131bc
13 changed files with 66 additions and 232 deletions

View File

@ -1,99 +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 {$} from 'protractor';
interface Worker {
id: string;
prepare?(): void;
work(): void;
}
const CreateOnlyWorker: Worker = {
id: 'createOnly',
prepare: () => $('#destroyDom').click(),
work: () => $('#createDom').click()
};
const CreateAndDestroyWorker: Worker = {
id: 'createDestroy',
work: () => {
$('#createDom').click();
$('#destroyDom').click();
}
};
const UpdateWorker: Worker = {
id: 'update',
work: () => $('#createDom').click()
};
describe('largetable benchmark perf', () => {
afterEach(verifyNoBrowserErrors);
[CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => {
describe(worker.id, () => {
it('should run for ng2', done => {
runTableBenchmark({
id: `largeTable.ng2.${worker.id}`,
url: 'all/benchmarks/src/largetable/ng2/index.html',
worker: worker
}).then(done, done.fail);
});
it('should run for ng2 with ngSwitch', done => {
runTableBenchmark({
id: `largeTable.ng2_switch.${worker.id}`,
url: 'all/benchmarks/src/largetable/ng2_switch/index.html',
worker: worker
}).then(done, done.fail);
});
it('should run for iv', done => {
runTableBenchmark({
id: `largeTable.iv.${worker.id}`,
url: 'all/benchmarks/src/largetable/iv/index.html',
ignoreBrowserSynchronization: true,
worker: worker
}).then(done, done.fail);
});
it('should run for the baseline', done => {
runTableBenchmark({
id: `largeTable.baseline.${worker.id}`,
url: 'all/benchmarks/src/largetable/baseline/index.html',
ignoreBrowserSynchronization: true,
worker: worker
}).then(done, done.fail);
});
it('should run for incremental-dom', done => {
runTableBenchmark({
id: `largeTable.incremental_dom.${worker.id}`,
url: 'all/benchmarks/src/largetable/incremental_dom/index.html',
ignoreBrowserSynchronization: true,
worker: worker
}).then(done, done.fail);
});
});
});
function runTableBenchmark(
config: {id: string, url: string, ignoreBrowserSynchronization?: boolean, worker: Worker}) {
return runBenchmark({
id: config.id,
url: config.url,
ignoreBrowserSynchronization: config.ignoreBrowserSynchronization,
params: [{name: 'cols', value: 40}, {name: 'rows', value: 200}],
prepare: config.worker.prepare,
work: config.worker.work
});
}
});

View File

@ -1,62 +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 {$} from 'protractor';
describe('largetable benchmark spec', () => {
afterEach(verifyNoBrowserErrors);
it('should work for ng2', () => {
testTableBenchmark({
url: 'all/benchmarks/src/largetable/ng2/index.html',
});
});
it('should work for ng2 switch', () => {
testTableBenchmark({
url: 'all/benchmarks/src/largetable/ng2_switch/index.html',
});
});
it('should work for iv', () => {
testTableBenchmark({
url: 'all/benchmarks/src/largetable/iv/index.html',
ignoreBrowserSynchronization: true,
});
});
it('should work for the baseline', () => {
testTableBenchmark({
url: 'all/benchmarks/src/largetable/baseline/index.html',
ignoreBrowserSynchronization: true,
});
});
it('should work for the incremental-dom', () => {
testTableBenchmark({
url: 'all/benchmarks/src/largetable/incremental_dom/index.html',
ignoreBrowserSynchronization: true,
});
});
function testTableBenchmark(openConfig: {url: string, ignoreBrowserSynchronization?: boolean}) {
openBrowser({
url: openConfig.url,
ignoreBrowserSynchronization: openConfig.ignoreBrowserSynchronization,
params: [{name: 'cols', value: 5}, {name: 'rows', value: 5}],
});
$('#createDom').click();
expect($('#root').getText()).toContain('0/0');
$('#createDom').click();
expect($('#root').getText()).toContain('A/A');
$('#destroyDom').click();
expect($('#root').getText()).toEqual('');
}
});

View File

@ -11,12 +11,9 @@ ts_library(
ts_library(
name = "perf_lib",
testonly = 1,
srcs = [
"largetable_perf.spec.ts",
],
srcs = ["largetable_perf.spec.ts"],
deps = [
"//modules/e2e_util",
"//packages:types",
"@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/largetable: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,9 @@ ts_devserver(
],
deps = [":incremental_dom"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/largetable: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__"])
@ -9,3 +10,9 @@ ts_devserver(
port = 4200,
static_files = ["largetable.js"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/largetable:perf_lib"],
)

View File

@ -36,11 +36,19 @@ const UpdateWorker: Worker = {
work: () => $('#createDom').click()
};
// In order to make sure that we don't change the ids of the benchmarks, we need to
// determine the current test package name from the Bazel target. This is necessary
// because previous to the Bazel conversion, the benchmark test ids contained the test
// name. e.g. "largeTable.ng2_switch.createDestroy". We determine the name of the
// Bazel package where this test runs from the current test target. The Bazel target
// looks like: "//modules/benchmarks/src/largetable/{pkg_name}:{target_name}".
const testPackageName = process.env['BAZEL_TARGET'] !.split(':')[0].split('/').pop();
describe('largetable benchmark perf', () => {
afterEach(verifyNoBrowserErrors);
it('should render the table for render3', () => {
it(`should render the table for ${testPackageName}`, () => {
openBrowser({
url: '',
ignoreBrowserSynchronization: true,
@ -56,26 +64,26 @@ describe('largetable benchmark perf', () => {
[CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => {
describe(worker.id, () => {
it('should run benchmark for render3', done => {
it(`should run benchmark for ${testPackageName}`, done => {
runTableBenchmark({
id: `largeTable.render3.${worker.id}`,
url: 'index.html',
id: `largeTable.${testPackageName}.${worker.id}`,
url: '/',
ignoreBrowserSynchronization: true,
worker: worker
}).then(done, done.fail);
});
});
});
function runTableBenchmark(
config: {id: string, url: string, ignoreBrowserSynchronization?: boolean, worker: Worker}) {
return runBenchmark({
id: config.id,
url: config.url,
ignoreBrowserSynchronization: config.ignoreBrowserSynchronization,
params: [{name: 'cols', value: 40}, {name: 'rows', value: 200}],
prepare: config.worker.prepare,
work: config.worker.work
});
}
});
function runTableBenchmark(
config: {id: string, url: string, ignoreBrowserSynchronization?: boolean, worker: Worker}) {
return runBenchmark({
id: config.id,
url: config.url,
ignoreBrowserSynchronization: config.ignoreBrowserSynchronization,
params: [{name: 'cols', value: 40}, {name: 'rows', value: 200}],
prepare: config.worker.prepare,
work: config.worker.work
});
}

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__"])
@ -33,3 +34,9 @@ ts_devserver(
],
deps = [":ng2"],
)
benchmark_test(
name = "perf",
server = ":devserver",
deps = ["//modules/benchmarks/src/largetable: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/largetable:perf_lib"],
)

View File

@ -1,17 +1,12 @@
package(default_visibility = ["//visibility:public"])
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 = "largetable_lib",
srcs = glob(
[
"**/*.ts",
],
exclude = ["protractor.on-prepare.ts"],
),
srcs = glob(["**/*.ts"]),
tags = ["ivy-only"],
deps = [
"//modules/benchmarks/src:util_lib",
@ -42,23 +37,9 @@ 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",
"@ngdeps//node-uuid",
"@ngdeps//protractor",
"@ngdeps//reflect-metadata",
"@ngdeps//yargs",
],
on_prepare = ":protractor.on_prepare.js",
server = ":devserver",
tags = [
"ivy-only",
],
deps = [
"//modules/benchmarks/src/largetable:perf_lib",
],
tags = ["ivy-only"],
deps = ["//modules/benchmarks/src/largetable:perf_lib"],
)

View File

@ -1,22 +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
*/
const protractorUtils = require('@angular/bazel/protractor-utils');
const protractor = require('protractor');
module.exports = async function(config) {
const serverSpec = await protractorUtils.runServer(config.workspace, config.server, '-port', []);
const serverUrl = `http://localhost:${serverSpec.port}`;
// Since the browser restarts in this benchmark we need to set both the browser.baseUrl
// for the first test and the protractor config.baseUrl for the subsequent tests
protractor.browser.baseUrl = serverUrl;
const processedConfig = await protractor.browser.getProcessedConfig();
return processedConfig.baseUrl = serverUrl;
};

View File

@ -1,5 +0,0 @@
{
"compilerOptions": {
"lib": ["es2015"]
}
}

View File

@ -31,6 +31,7 @@
"payload_tests",
// Tests which are already migrated to Bazel:
"playground/",
"benchmarks/src/largetable",
"benchmarks/src/tree"
],
"angularCompilerOptions": {