From 13685131bc449ac260654329c59d84a6f2715c51 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 11 Feb 2019 19:36:45 +0100 Subject: [PATCH] build: run largetable benchmark tests with bazel (#28645) PR Close #28645 --- .../benchmarks/e2e_test/largetable_perf.ts | 99 ------------------- .../benchmarks/e2e_test/largetable_spec.ts | 62 ------------ modules/benchmarks/src/largetable/BUILD.bazel | 5 +- .../src/largetable/baseline/BUILD.bazel | 7 ++ .../largetable/incremental_dom/BUILD.bazel | 7 ++ .../benchmarks/src/largetable/iv/BUILD.bazel | 7 ++ .../src/largetable/largetable_perf.spec.ts | 40 +++++--- .../benchmarks/src/largetable/ng2/BUILD.bazel | 7 ++ .../src/largetable/ng2_switch/BUILD.bazel | 7 ++ .../src/largetable/render3/BUILD.bazel | 29 +----- .../render3/protractor.on_prepare.js | 22 ----- .../src/largetable/render3/tsconfig.json | 5 - modules/tsconfig.json | 1 + 13 files changed, 66 insertions(+), 232 deletions(-) delete mode 100644 modules/benchmarks/e2e_test/largetable_perf.ts delete mode 100644 modules/benchmarks/e2e_test/largetable_spec.ts delete mode 100644 modules/benchmarks/src/largetable/render3/protractor.on_prepare.js delete mode 100644 modules/benchmarks/src/largetable/render3/tsconfig.json diff --git a/modules/benchmarks/e2e_test/largetable_perf.ts b/modules/benchmarks/e2e_test/largetable_perf.ts deleted file mode 100644 index 95448da26a..0000000000 --- a/modules/benchmarks/e2e_test/largetable_perf.ts +++ /dev/null @@ -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 - }); - } -}); diff --git a/modules/benchmarks/e2e_test/largetable_spec.ts b/modules/benchmarks/e2e_test/largetable_spec.ts deleted file mode 100644 index 52f0395b74..0000000000 --- a/modules/benchmarks/e2e_test/largetable_spec.ts +++ /dev/null @@ -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(''); - } -}); diff --git a/modules/benchmarks/src/largetable/BUILD.bazel b/modules/benchmarks/src/largetable/BUILD.bazel index 02986f6b9f..85706c9c97 100644 --- a/modules/benchmarks/src/largetable/BUILD.bazel +++ b/modules/benchmarks/src/largetable/BUILD.bazel @@ -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", ], ) diff --git a/modules/benchmarks/src/largetable/baseline/BUILD.bazel b/modules/benchmarks/src/largetable/baseline/BUILD.bazel index 960c5a8eb7..bcdbc22a1f 100644 --- a/modules/benchmarks/src/largetable/baseline/BUILD.bazel +++ b/modules/benchmarks/src/largetable/baseline/BUILD.bazel @@ -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"], +) diff --git a/modules/benchmarks/src/largetable/incremental_dom/BUILD.bazel b/modules/benchmarks/src/largetable/incremental_dom/BUILD.bazel index 5fbafea849..fc94da3175 100644 --- a/modules/benchmarks/src/largetable/incremental_dom/BUILD.bazel +++ b/modules/benchmarks/src/largetable/incremental_dom/BUILD.bazel @@ -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"], +) diff --git a/modules/benchmarks/src/largetable/iv/BUILD.bazel b/modules/benchmarks/src/largetable/iv/BUILD.bazel index 0391a8d064..a58fcd7a59 100644 --- a/modules/benchmarks/src/largetable/iv/BUILD.bazel +++ b/modules/benchmarks/src/largetable/iv/BUILD.bazel @@ -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"], +) diff --git a/modules/benchmarks/src/largetable/largetable_perf.spec.ts b/modules/benchmarks/src/largetable/largetable_perf.spec.ts index 71552f688b..6e9bdfe788 100644 --- a/modules/benchmarks/src/largetable/largetable_perf.spec.ts +++ b/modules/benchmarks/src/largetable/largetable_perf.spec.ts @@ -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 + }); +} diff --git a/modules/benchmarks/src/largetable/ng2/BUILD.bazel b/modules/benchmarks/src/largetable/ng2/BUILD.bazel index fced7aaa01..18ad59f723 100644 --- a/modules/benchmarks/src/largetable/ng2/BUILD.bazel +++ b/modules/benchmarks/src/largetable/ng2/BUILD.bazel @@ -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"], +) diff --git a/modules/benchmarks/src/largetable/ng2_switch/BUILD.bazel b/modules/benchmarks/src/largetable/ng2_switch/BUILD.bazel index c1e5ccace5..72a4c1bc2d 100644 --- a/modules/benchmarks/src/largetable/ng2_switch/BUILD.bazel +++ b/modules/benchmarks/src/largetable/ng2_switch/BUILD.bazel @@ -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"], +) diff --git a/modules/benchmarks/src/largetable/render3/BUILD.bazel b/modules/benchmarks/src/largetable/render3/BUILD.bazel index ba2aff5a3c..f8ae700c47 100644 --- a/modules/benchmarks/src/largetable/render3/BUILD.bazel +++ b/modules/benchmarks/src/largetable/render3/BUILD.bazel @@ -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"], ) diff --git a/modules/benchmarks/src/largetable/render3/protractor.on_prepare.js b/modules/benchmarks/src/largetable/render3/protractor.on_prepare.js deleted file mode 100644 index 509208c84e..0000000000 --- a/modules/benchmarks/src/largetable/render3/protractor.on_prepare.js +++ /dev/null @@ -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; -}; diff --git a/modules/benchmarks/src/largetable/render3/tsconfig.json b/modules/benchmarks/src/largetable/render3/tsconfig.json deleted file mode 100644 index 8f3c656796..0000000000 --- a/modules/benchmarks/src/largetable/render3/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "lib": ["es2015"] - } -} diff --git a/modules/tsconfig.json b/modules/tsconfig.json index 783949bb5e..3f9b7bc8bc 100644 --- a/modules/tsconfig.json +++ b/modules/tsconfig.json @@ -31,6 +31,7 @@ "payload_tests", // Tests which are already migrated to Bazel: "playground/", + "benchmarks/src/largetable", "benchmarks/src/tree" ], "angularCompilerOptions": {