Create analysis task should sync analysis task status after creation.
authordewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2018 07:06:16 +0000 (07:06 +0000)
committerdewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2018 07:06:16 +0000 (07:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185222

Reviewed by Ryosuke Niwa.

* public/v3/models/analysis-task.js:
(AnalysisTask.async.create): Fetch newly-created analysis task right about its creation.
(AnalysisTask):
* tools/js/measurement-set-analyzer.js:
(MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): Adjust as 'AnalysisTask.create' now
returns an anlysis task instance.
(MeasurementSetAnalyzer):
* unit-tests/analysis-task-tests.js: Added a unit test for this change.
(async):
* unit-tests/measurement-set-analyzer-tests.js: Update unit tests accordingly.
Fix a typo in one previous unit test.
(async):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231296 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/v3/models/analysis-task.js
Websites/perf.webkit.org/tools/js/measurement-set-analyzer.js
Websites/perf.webkit.org/unit-tests/analysis-task-tests.js
Websites/perf.webkit.org/unit-tests/measurement-set-analyzer-tests.js

index 81b237e..f88ea15 100644 (file)
@@ -1,3 +1,23 @@
+2018-05-02  Dewei Zhu  <dewei_zhu@apple.com>
+
+        Create analysis task should sync analysis task status after creation.
+        https://bugs.webkit.org/show_bug.cgi?id=185222
+
+        Reviewed by Ryosuke Niwa.
+
+        * public/v3/models/analysis-task.js:
+        (AnalysisTask.async.create): Fetch newly-created analysis task right about its creation.
+        (AnalysisTask):
+        * tools/js/measurement-set-analyzer.js:
+        (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): Adjust as 'AnalysisTask.create' now
+        returns an anlysis task instance.
+        (MeasurementSetAnalyzer):
+        * unit-tests/analysis-task-tests.js: Added a unit test for this change.
+        (async):
+        * unit-tests/measurement-set-analyzer-tests.js: Update unit tests accordingly.
+        Fix a typo in one previous unit test.
+        (async):
+
 2018-05-01  Dewei Zhu  <dewei_zhu@apple.com>
 
         Write a script that detects chart changes by using v3 API.
index 159a25e..5db4524 100644 (file)
@@ -303,7 +303,7 @@ class AnalysisTask extends LabeledObject {
         return results;
     }
 
-    static create(name, startPoint, endPoint, testGroupName=null, repetitionCount=0)
+    static async create(name, startPoint, endPoint, testGroupName=null, repetitionCount=0)
     {
         const parameters = {name, startRun: startPoint.id, endRun: endPoint.id};
         if (testGroupName) {
@@ -312,7 +312,8 @@ class AnalysisTask extends LabeledObject {
             parameters['repetitionCount'] = repetitionCount;
             parameters['testGroupName'] = testGroupName;
         }
-        return PrivilegedAPI.sendRequest('create-analysis-task', parameters);
+        const response = await PrivilegedAPI.sendRequest('create-analysis-task', parameters);
+        return AnalysisTask.fetchById(response.taskId, true);
     }
 }
 
index b329aa7..2db047a 100644 (file)
@@ -103,9 +103,10 @@ class MeasurementSetAnalyzer {
         const summary = `Potential ${rangeWithMostSignificantChange.valueChangeSummary.changeLabel} on ${platform.name()} between ${CommitSet.diff(startCommitSet, endCommitSet)}`;
 
         // FIXME: The iteration count should be smarter than hard-coding.
-        const response = await AnalysisTask.create(summary, rangeWithMostSignificantChange.startPoint,
+        const analysisTask = await AnalysisTask.create(summary, rangeWithMostSignificantChange.startPoint,
             rangeWithMostSignificantChange.endPoint, 'Confirm', 4);
-        this._logger.info(`Created analysis task with id "${response.taskId}" to confirm: "${summary}".`);
+
+        this._logger.info(`Created analysis task with id "${analysisTask.id()}" to confirm: "${summary}".`);
     }
 }
 
index 109aee8..008df3f 100644 (file)
@@ -323,6 +323,97 @@ describe('AnalysisTask', () => {
                         '22': { revision: 'ios-revision-2', ownerRevision: null, patch: null}}]}
             );
         });
+
+        it('should sync the new analysis task status once it is created', async () => {
+            const [startPoint, endPoint] = mockStartAndEndPoints();
+            const creatingPromise = AnalysisTask.create('confirm', startPoint, endPoint, 'Confirm', 4);
+            assert.equal(requests.length, 1);
+            assert.equal(requests[0].url, '/privileged-api/generate-csrf-token');
+            requests[0].resolve({
+                token: 'abc',
+                expiration: Date.now() + 3600 * 1000,
+            });
+
+            await MockRemoteAPI.waitForRequest();
+            assert.equal(requests[1].url, '/privileged-api/create-analysis-task');
+            assert.equal(requests.length, 2);
+            assert.deepEqual(requests[1].data, {name: 'confirm', repetitionCount: 4,
+                startRun: 1, endRun: 2, testGroupName: 'Confirm', token: 'abc', revisionSets: [
+                    {'11': {revision: 'webkit-revision-1', ownerRevision: null, patch: null},
+                        '22': {revision: 'ios-revision-1', ownerRevision: null, patch: null}},
+                    {'11': {revision: 'webkit-revision-2', ownerRevision: null, patch: null},
+                        '22': { revision: 'ios-revision-2', ownerRevision: null, patch: null}}]}
+            );
+
+            requests[1].resolve({taskId: '5255', status: 'OK'});
+
+            await MockRemoteAPI.waitForRequest();
+            assert.equal(requests.length, 3);
+            assert.equal(requests[2].url, '/api/analysis-tasks?id=5255');
+            requests[2].resolve({
+                analysisTasks: [{
+                    author: null,
+                    bugs: [],
+                    buildRequestCount: 8,
+                    finishedBuildRequestCount: 0,
+                    category: 'identified',
+                    causes: [],
+                    createdAt: 4500,
+                    endRun: 2,
+                    endRunTime:  5000,
+                    fixes: [],
+                    id: 5255,
+                    metric: MockModels.someMetric.id(),
+                    name: 'confirm',
+                    needed: null,
+                    platform: MockModels.somePlatform.id(),
+                    result: 'progression',
+                    segmentationStrategy: 1,
+                    startRun: 1,
+                    startRunTime: 4000,
+                    testRangeStrategy: 2
+                }],
+                bugs: [],
+                commits: [],
+                status: 'OK'
+            });
+            const analysisTask = await creatingPromise;
+            assert.equal(analysisTask.id(), 5255);
+            assert.deepEqual(analysisTask.bugs(), []);
+            assert.equal(analysisTask.author(), '');
+            assert.equal(analysisTask.platform(), MockModels.somePlatform);
+            assert.equal(analysisTask.metric(), MockModels.someMetric);
+        });
+
+        it('should return an rejected promise when analysis task creation failed', async () => {
+            const [startPoint, endPoint] = mockStartAndEndPoints();
+            const creatingPromise = AnalysisTask.create('confirm', startPoint, endPoint, 'Confirm', 4);
+            assert.equal(requests.length, 1);
+            assert.equal(requests[0].url, '/privileged-api/generate-csrf-token');
+            requests[0].resolve({
+                token: 'abc',
+                expiration: Date.now() + 3600 * 1000,
+            });
+
+            await MockRemoteAPI.waitForRequest();
+            assert.equal(requests[1].url, '/privileged-api/create-analysis-task');
+            assert.equal(requests.length, 2);
+            assert.deepEqual(requests[1].data, {name: 'confirm', repetitionCount: 4,
+                startRun: 1, endRun: 2, testGroupName: 'Confirm', token: 'abc', revisionSets: [
+                    {'11': {revision: 'webkit-revision-1', ownerRevision: null, patch: null},
+                        '22': {revision: 'ios-revision-1', ownerRevision: null, patch: null}},
+                    {'11': {revision: 'webkit-revision-2', ownerRevision: null, patch: null},
+                        '22': { revision: 'ios-revision-2', ownerRevision: null, patch: null}}]}
+            );
+
+            requests[1].reject('401');
+            return creatingPromise.then(() => {
+                assert.ok(false, 'should not be reached');
+            }, (error) => {
+                assert.ok(true);
+                assert.equal(error, '401');
+            });
+        });
     });
 
     describe('create with node privilege api', () => {
index 1eb9e41..6a89f35 100644 (file)
@@ -247,6 +247,38 @@ describe('MeasurementSetAnalyzer', () => {
             });
             requests[2].resolve({taskId: '5255', status: 'OK'});
 
+            await MockRemoteAPI.waitForRequest();
+            assert.equal(requests.length, 4);
+            assert.equal(requests[3].url, '/api/analysis-tasks?id=5255');
+
+            requests[3].resolve({
+                analysisTasks: [{
+                    author: null,
+                    bugs: [],
+                    buildRequestCount: 8,
+                    finishedBuildRequestCount: 0,
+                    category: 'identified',
+                    causes: [],
+                    createdAt: 4500,
+                    endRun: 6448,
+                    endRunTime:  5000,
+                    fixes: [],
+                    id: 5255,
+                    metric: MockModels.someMetric.id(),
+                    name: 'Potential 2.38% regression on Some platform between WebKit: r40-r49',
+                    needed: null,
+                    platform: MockModels.somePlatform.id(),
+                    result: 'regression',
+                    segmentationStrategy: 1,
+                    startRun: 6439,
+                    startRunTime: 4000,
+                    testRangeStrategy: 2
+                }],
+                bugs: [],
+                commits: [],
+                status: 'OK'
+            });
+
             await analysisPromise;
             assert.deepEqual(logger.info_logs, ['==== "Some test : Some metric" on "Some platform" ====',
                 'Created analysis task with id "5255" to confirm: "Potential 2.38% regression on Some platform between WebKit: r35-r44".']);
@@ -297,7 +329,7 @@ describe('MeasurementSetAnalyzer', () => {
                     result: 'regression',
                     segmentationStrategy: 1,
                     startRun: 6434,
-                    statrRunTime: 4000,
+                    startRunTime: 4000,
                     testRangeStrategy: 2
                 }],
                 bugs: [],
@@ -359,6 +391,38 @@ describe('MeasurementSetAnalyzer', () => {
             });
             requests[2].resolve({taskId: '5255', status: 'OK'});
 
+            await MockRemoteAPI.waitForRequest();
+            assert.equal(requests.length, 4);
+            assert.equal(requests[3].url, '/api/analysis-tasks?id=5255');
+
+            requests[3].resolve({
+                analysisTasks: [{
+                    author: null,
+                    bugs: [],
+                    buildRequestCount: 8,
+                    finishedBuildRequestCount: 0,
+                    category: 'identified',
+                    causes: [],
+                    createdAt: 4500,
+                    endRun: 6448,
+                    endRunTime:  5000,
+                    fixes: [],
+                    id: 5255,
+                    metric: MockModels.someMetric.id(),
+                    name: 'Potential 2.38% regression on Some platform between WebKit: r40-r49',
+                    needed: null,
+                    platform: MockModels.somePlatform.id(),
+                    result: 'regression',
+                    segmentationStrategy: 1,
+                    startRun: 6439,
+                    startRunTime: 4000,
+                    testRangeStrategy: 2
+                }],
+                bugs: [],
+                commits: [],
+                status: 'OK'
+            });
+
             await analysisPromise;
             assert.deepEqual(logger.info_logs, ['==== "Some test : Some metric" on "Some platform" ====',
                 'Created analysis task with id "5255" to confirm: "Potential 2.38% regression on Some platform between WebKit: r40-r49".']);
@@ -413,6 +477,38 @@ describe('MeasurementSetAnalyzer', () => {
             });
             requests[2].resolve({taskId: '5255', status: 'OK'});
 
+            await MockRemoteAPI.waitForRequest();
+            assert.equal(requests.length, 4);
+            assert.equal(requests[3].url, '/api/analysis-tasks?id=5255');
+
+            requests[3].resolve({
+                analysisTasks: [{
+                    author: null,
+                    bugs: [],
+                    buildRequestCount: 8,
+                    finishedBuildRequestCount: 0,
+                    category: 'identified',
+                    causes: [],
+                    createdAt: 4500,
+                    endRun: 6407,
+                    endRunTime:  5000,
+                    fixes: [],
+                    id: 5255,
+                    metric: MockModels.someMetric.id(),
+                    name: 'Potential 9.15% progression on Some platform between WebKit: r3-r8',
+                    needed: null,
+                    platform: MockModels.somePlatform.id(),
+                    result: 'progression',
+                    segmentationStrategy: 1,
+                    startRun: 6402,
+                    startRunTime: 4000,
+                    testRangeStrategy: 2
+                }],
+                bugs: [],
+                commits: [],
+                status: 'OK'
+            });
+
             await analysisPromise;
             assert.deepEqual(logger.info_logs, ['==== "Some test : Some metric" on "Some platform" ====',
                 'Created analysis task with id "5255" to confirm: "Potential 9.15% progression on Some platform between WebKit: r3-r8".']);