| 'use strict'; |
| |
| const assert = require('assert'); |
| |
| require('../tools/js/v3-models.js'); |
| let MockModels = require('./resources/mock-v3-models.js').MockModels; |
| let MockRemoteAPI = require('./resources/mock-remote-api.js').MockRemoteAPI; |
| |
| function sampleAnalysisTask() |
| { |
| return { |
| 'analysisTasks': [ |
| { |
| 'author': null, |
| 'bugs': [], |
| 'buildRequestCount': '14', |
| 'finishedBuildRequestCount': '6', |
| 'category': 'identified', |
| 'causes': [ |
| '105975' |
| ], |
| 'createdAt': 1454594330000, |
| 'endRun': '37253448', |
| 'endRunTime': 1454515020303, |
| 'fixes': [], |
| 'id': '1082', |
| 'metric': '2884', |
| 'name': 'Potential 1.2% regression between 2016-02-02 20:20 and 02-03 15:57', |
| 'needed': null, |
| 'platform': '65', |
| 'result': 'regression', |
| 'segmentationStrategy': '1', |
| 'startRun': '37117949', |
| 'startRunTime': 1454444458791, |
| 'testRangeStragegy': '2' |
| } |
| ], |
| 'bugs': [], |
| 'commits': [ |
| { |
| 'authorEmail': 'commit-queue@webkit.org', |
| 'authorName': 'Commit Queue', |
| 'id': '105975', |
| 'message': 'Commit message', |
| 'order': null, |
| 'previousCommit': null, |
| 'repository': '11', |
| 'revision': '196051', |
| 'time': 1454481246108 |
| } |
| ], |
| 'status': 'OK' |
| }; |
| } |
| |
| function measurementCluster() |
| { |
| return { |
| 'clusterSize': 5184000000, |
| 'clusterStart': 946684800000, |
| 'configurations': { |
| 'current': [ |
| [ |
| 37188161, |
| 124.15015662116, |
| 25, |
| 3103.7539155291, |
| 385398.06003414, |
| false, |
| [ |
| [ |
| 105978, |
| 10, |
| '791451', |
| null, |
| 1454481204649 |
| ], |
| [ |
| 105975, |
| 11, |
| '196051', |
| null, |
| 1454481246108 |
| ], |
| [ |
| 105502, |
| 9, |
| '10.11 15D21', |
| 1504021, |
| 0 |
| ] |
| ], |
| 1454481246108, |
| 227020, |
| 1454492139496, |
| '3151', |
| 179 |
| ], |
| ], |
| }, |
| 'endTime': 1454716800000, |
| 'formatMap': [ |
| 'id', |
| 'mean', |
| 'iterationCount', |
| 'sum', |
| 'squareSum', |
| 'markedOutlier', |
| 'revisions', |
| 'commitTime', |
| 'build', |
| 'buildTime', |
| 'buildNumber', |
| 'builder' |
| ], |
| 'lastModified': 1455236216153, |
| 'startTime': 1449532800000, |
| 'status': 'OK' |
| }; |
| } |
| |
| describe('AnalysisTask', () => { |
| MockModels.inject(); |
| function makeMockPoints(id, commitSet) { |
| return { |
| id, |
| commitSet: () => commitSet |
| } |
| } |
| |
| describe('fetchAll', () => { |
| const requests = MockRemoteAPI.inject(); |
| it('should request all analysis tasks', () => { |
| let callCount = 0; |
| AnalysisTask.fetchAll().then(() => { callCount++; }); |
| assert.equal(callCount, 0); |
| assert.equal(requests.length, 1); |
| assert.equal(requests[0].url, '/api/analysis-tasks'); |
| }); |
| |
| it('should not request all analysis tasks multiple times', () => { |
| let callCount = 0; |
| AnalysisTask.fetchAll().then(() => { callCount++; }); |
| assert.equal(callCount, 0); |
| assert.equal(requests.length, 1); |
| assert.equal(requests[0].url, '/api/analysis-tasks'); |
| |
| AnalysisTask.fetchAll().then(() => { callCount++; }); |
| assert.equal(callCount, 0); |
| assert.equal(requests.length, 1); |
| }); |
| |
| it('should resolve the promise when the request is fullfilled', () => { |
| let callCount = 0; |
| const promise = AnalysisTask.fetchAll().then(() => { callCount++; }); |
| assert.equal(callCount, 0); |
| assert.equal(requests.length, 1); |
| assert.equal(requests[0].url, '/api/analysis-tasks'); |
| |
| requests[0].resolve(sampleAnalysisTask()); |
| |
| let anotherCallCount = 0; |
| return promise.then(() => { |
| assert.equal(callCount, 1); |
| AnalysisTask.fetchAll().then(() => { anotherCallCount++; }); |
| }).then(() => { |
| assert.equal(callCount, 1); |
| assert.equal(anotherCallCount, 1); |
| assert.equal(requests.length, 1); |
| }); |
| }); |
| |
| it('should create AnalysisTask objects', () => { |
| const promise = AnalysisTask.fetchAll(); |
| requests[0].resolve(sampleAnalysisTask()); |
| |
| return promise.then(() => { |
| assert.equal(AnalysisTask.all().length, 1); |
| var task = AnalysisTask.all()[0]; |
| assert.equal(task.id(), 1082); |
| assert.equal(task.metric(), MockModels.someMetric); |
| assert.equal(task.platform(), MockModels.somePlatform); |
| assert.ok(task.hasResults()); |
| assert.ok(task.hasPendingRequests()); |
| assert.equal(task.requestLabel(), '6 of 14'); |
| assert.equal(task.category(), 'investigated'); |
| assert.equal(task.changeType(), 'regression'); |
| assert.equal(task.startMeasurementId(), 37117949); |
| assert.equal(task.startTime(), 1454444458791); |
| assert.equal(task.endMeasurementId(), 37253448); |
| assert.equal(task.endTime(), 1454515020303); |
| }); |
| }); |
| |
| it('should create CommitLog objects for `causes`', () => { |
| const promise = AnalysisTask.fetchAll(); |
| requests[0].resolve(sampleAnalysisTask()); |
| |
| return promise.then(() => { |
| assert.equal(AnalysisTask.all().length, 1); |
| var task = AnalysisTask.all()[0]; |
| |
| assert.equal(task.causes().length, 1); |
| var commit = task.causes()[0]; |
| |
| assert.equal(commit.revision(), '196051'); |
| assert.equal(commit.repository(), MockModels.webkit); |
| assert.equal(+commit.time(), 1454481246108); |
| }); |
| }); |
| |
| it('should find CommitLog objects for `causes` when MeasurementAdaptor created matching objects', () => { |
| const adaptor = new MeasurementAdaptor(measurementCluster().formatMap); |
| const adaptedMeasurement = adaptor.applyTo(measurementCluster().configurations.current[0]); |
| assert.equal(adaptedMeasurement.id, 37188161); |
| assert.equal(adaptedMeasurement.commitSet().commitForRepository(MockModels.webkit).revision(), '196051'); |
| |
| const promise = AnalysisTask.fetchAll(); |
| requests[0].resolve(sampleAnalysisTask()); |
| |
| return promise.then(() => { |
| assert.equal(AnalysisTask.all().length, 1); |
| var task = AnalysisTask.all()[0]; |
| |
| assert.equal(task.causes().length, 1); |
| var commit = task.causes()[0]; |
| assert.equal(commit.revision(), '196051'); |
| assert.equal(commit.repository(), MockModels.webkit); |
| assert.equal(+commit.time(), 1454481246108); |
| }); |
| }); |
| }); |
| |
| |
| function mockStartAndEndPoints() { |
| const startPoint = makeMockPoints(1, new MeasurementCommitSet(1, [ |
| [1, MockModels.ios.id(), 'ios-revision-1', null, 0], |
| [3, MockModels.webkit.id(), 'webkit-revision-1', null, 0] |
| ])); |
| const endPoint = makeMockPoints(2, new MeasurementCommitSet(2, [ |
| [2, MockModels.ios.id(), 'ios-revision-2', null, 0], |
| [4, MockModels.webkit.id(), 'webkit-revision-2', null, 0] |
| ])); |
| return [startPoint, endPoint]; |
| } |
| |
| describe('create with browser privilege api', () => { |
| const requests = MockRemoteAPI.inject(); |
| |
| it('should create analysis task with confirming repetition count zero as default with browser privilege api', async () => { |
| const [startPoint, endPoint] = mockStartAndEndPoints(); |
| AnalysisTask.create('confirm', startPoint, endPoint); |
| 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', startRun: 1, endRun: 2, token: 'abc'}); |
| }); |
| |
| it('should create analysis task with confirming repetition count specified', async () => { |
| const [startPoint, endPoint] = mockStartAndEndPoints(); |
| 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}}]} |
| ); |
| }); |
| }); |
| |
| describe('create with node privilege api', () => { |
| const requests = MockRemoteAPI.inject(null, 'node'); |
| beforeEach(() => { |
| PrivilegedAPI.configure('worker', 'password'); |
| }); |
| |
| it('should create analysis task with confirming repetition count zero as default with browser privilege api', () => { |
| const [startPoint, endPoint] = mockStartAndEndPoints(); |
| AnalysisTask.create('confirm', startPoint, endPoint); |
| assert.equal(requests[0].url, '/privileged-api/create-analysis-task'); |
| assert.equal(requests.length, 1); |
| assert.deepEqual(requests[0].data, {name: 'confirm', startRun: 1, endRun: 2, slaveName: 'worker', slavePassword: 'password'}); |
| }); |
| |
| it('should create analysis task with confirming repetition count specified', () => { |
| const [startPoint, endPoint] = mockStartAndEndPoints(); |
| AnalysisTask.create('confirm', startPoint, endPoint, 'Confirm', 4); |
| assert.equal(requests[0].url, '/privileged-api/create-analysis-task'); |
| assert.equal(requests.length, 1); |
| assert.deepEqual(requests[0].data, {name: 'confirm', repetitionCount: 4, |
| startRun: 1, endRun: 2, slaveName: 'worker', slavePassword: 'password', |
| testGroupName: 'Confirm', 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}}]} |
| ); |
| }); |
| }); |
| }); |