]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Resolve TestBed performance issue
authorStephan Müller <smueller@suse.com>
Fri, 1 Jun 2018 15:11:35 +0000 (17:11 +0200)
committerStephan Müller <smueller@suse.com>
Fri, 8 Jun 2018 12:50:25 +0000 (14:50 +0200)
With this helper function you can easily resolve the TestBed resetting
performance issue. If more tests exists in a test suite, it makes sense
to configure TestBed only once if you are not doing a lot of TestBed
specific stuff (haven't hit the limitation). It will reduce the test
run time by around $tests * 50 %. In my case it was a test suite with
47 tests with a run time of over 30s after using the static test bed
method it ran in 1.2s. The run time was reduced to 0.04 %! This is
equivalent to a speed increase of 2500% (100/0.04)!

For our own security the normal way will be taken if you not
set the _DEV_ configuration variable to true. It will be false when
"run-frontend-unittests.sh" is run.

Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/HACKING.rst
src/pybind/mgr/dashboard/frontend/.gitignore
src/pybind/mgr/dashboard/frontend/src/app/shared/unit-test-helper.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/tsconfig.app.json
src/pybind/mgr/dashboard/frontend/src/unit-test-configuration.ts.sample [new file with mode: 0644]
src/pybind/mgr/dashboard/run-frontend-unittests.sh

index 79f34dc8b945fbc251ccbe5da01e5d844ffd609f..55841270da3017d287cd7e974f013d55e9802820 100644 (file)
@@ -66,6 +66,10 @@ production build. Navigate to ``https://localhost:8443``.
 Running Unit Tests
 ~~~~~~~~~~~~~~~~~~
 
+Create ``unit-test-configuration.ts`` file based on
+``unit-test-configuration.ts.sample`` in directory
+``src/pybind/mgr/dashboard/frontend/src``.
+
 Run ``npm run test`` to execute the unit tests via `Jest
 <https://facebook.github.io/jest/>`_.
 
index 2e55dc6354ddf00cb12477a637e32be9a6dbbdd5..8f33628cb880bf0d1fdef6877ce86daf56ea4d29 100644 (file)
@@ -32,6 +32,7 @@
 npm-debug.log
 testem.log
 /typings
+/src/unit-test-configuration.ts
 
 # e2e
 /e2e/*.js
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/unit-test-helper.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/unit-test-helper.ts
new file mode 100644 (file)
index 0000000..6348045
--- /dev/null
@@ -0,0 +1,25 @@
+import { async, TestBed } from '@angular/core/testing';
+
+import { _DEV_ } from '../../unit-test-configuration';
+
+export function configureTestBed(configuration, useOldMethod?) {
+  if (_DEV_ && !useOldMethod) {
+    const resetTestingModule = TestBed.resetTestingModule;
+    beforeAll((done) =>
+      (async () => {
+        TestBed.resetTestingModule();
+        TestBed.configureTestingModule(configuration);
+        // prevent Angular from resetting testing module
+        TestBed.resetTestingModule = () => TestBed;
+      })()
+        .then(done)
+        .catch(done.fail));
+    afterAll(() => {
+      TestBed.resetTestingModule = resetTestingModule;
+    });
+  } else {
+    beforeEach(async(() => {
+      TestBed.configureTestingModule(configuration);
+    }));
+  }
+}
index 39ba8dbacbbe051fdd02481b07af43219296a075..719f72b9f831470bc1fc435c84c7c0d3889b4514 100644 (file)
@@ -7,6 +7,7 @@
     "types": []
   },
   "exclude": [
+    "app/shared/unit-test-helper.ts",
     "test.ts",
     "**/*.spec.ts"
   ]
diff --git a/src/pybind/mgr/dashboard/frontend/src/unit-test-configuration.ts.sample b/src/pybind/mgr/dashboard/frontend/src/unit-test-configuration.ts.sample
new file mode 100644 (file)
index 0000000..74dbf2c
--- /dev/null
@@ -0,0 +1 @@
+export const _DEV_ = false;
index ea7522e4c733fbe6fb559fa00b415dd32526af4e..010dc83ab97aa4e8e690dba7e410096fde00898f 100755 (executable)
@@ -4,10 +4,21 @@ set -e
 
 cd $CEPH_ROOT/src/pybind/mgr/dashboard/frontend
 
+config='src/unit-test-configuration.ts'
+if [ -e $config ]; then
+  mv $config ${config}_old
+fi
+cp ${config}.sample $config
+
 .  $CEPH_ROOT/build/src/pybind/mgr/dashboard/node-env/bin/activate
 
 npm run build -- --prod
 npm run test:ci
 npm run lint
 
+rm $config
+if [ -e ${config}_old ]; then
+  mv ${config}_old $config
+fi
+
 deactivate