зеркало из https://github.com/mozilla/treeherder.git
resultset model fixes and passing unit tests
This commit is contained in:
Родитель
05f2189283
Коммит
c1ccab4b44
|
@ -8,7 +8,8 @@
|
|||
"karma-coverage": ">=0.2.0",
|
||||
"karma-jasmine": ">=0.1.5",
|
||||
"karma-ng-scenario": ">=0.1.0",
|
||||
"karma-firefox-launcher": ">=0.1.3"
|
||||
"karma-firefox-launcher": ">=0.1.3",
|
||||
"karma-spec-reporter": ">=0.0.12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./node_modules/.bin/karma start webapp/config/karma.conf.js --single-run --browsers Firefox"
|
||||
|
|
|
@ -31,6 +31,8 @@ module.exports = function (config) {
|
|||
autoWatch: false,
|
||||
singleRun: true,
|
||||
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
browsers: ['Firefox'],
|
||||
|
||||
junitReporter: {
|
||||
|
|
|
@ -1,21 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
describe('ThResultSetModel', function(){
|
||||
|
||||
var $httpBackend,
|
||||
rootScope,
|
||||
model;
|
||||
model,
|
||||
foregroundRepo = "foreground-repo",
|
||||
backgroundRepo = "background-repo",
|
||||
projectPrefix = 'http://local.treeherder.mozilla.org/api/project/',
|
||||
foregroundPrefix = projectPrefix + 'foreground-repo',
|
||||
backgroundPrefix = projectPrefix + 'background-repo';
|
||||
|
||||
beforeEach(module('treeherder'));
|
||||
|
||||
beforeEach(inject(function ($injector, $rootScope, $controller, ThResultSetModel) {
|
||||
|
||||
var projectPrefix = 'http://local.treeherder.mozilla.org/api/project/mozilla-inbound/';
|
||||
beforeEach(inject(function ($injector, $rootScope, $controller,
|
||||
ThResultSetModel) {
|
||||
|
||||
$httpBackend = $injector.get('$httpBackend');
|
||||
jasmine.getJSONFixtures().fixturesPath='base/test/mock';
|
||||
|
||||
$httpBackend.whenGET(projectPrefix + 'resultset/?count=10&format=json&full=false').respond(
|
||||
getResultSets()
|
||||
$httpBackend.whenGET(foregroundPrefix + '/resultset/?count=10&format=json&full=false').respond(
|
||||
getResultSet(1)
|
||||
);
|
||||
|
||||
|
||||
$httpBackend.whenGET(backgroundPrefix + '/resultset/?count=10&format=json&full=false').respond(
|
||||
getResultSet(10)
|
||||
);
|
||||
|
||||
$httpBackend.whenGET(projectPrefix + 'jobs/1235/').respond(
|
||||
|
@ -23,11 +33,14 @@ describe('ThResultSetModel', function(){
|
|||
);
|
||||
|
||||
rootScope = $rootScope.$new();
|
||||
rootScope.repoName = "mozilla-inbound";
|
||||
rootScope.repoName = foregroundRepo;
|
||||
|
||||
model = ThResultSetModel;
|
||||
model.load(rootScope.repoName);
|
||||
model.addRepository(rootScope.repoName);
|
||||
model.fetchResultSets(rootScope.repoName, 10);
|
||||
|
||||
model.addRepository(backgroundRepo);
|
||||
model.fetchResultSets(backgroundRepo, 10);
|
||||
|
||||
$httpBackend.flush();
|
||||
}));
|
||||
|
@ -36,138 +49,276 @@ describe('ThResultSetModel', function(){
|
|||
Tests ThResultSetModel
|
||||
*/
|
||||
it('should have 1 resultset', function() {
|
||||
expect(model.getResultSetsArray().length).toBe(1);
|
||||
});
|
||||
it('should have 1 resultset', function() {
|
||||
expect(model.getResultSetsArray().length).toBe(5);
|
||||
expect(model.getResultSetsArray(rootScope.repoName).length).toBe(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new jobs gets those job updates on the current repo
|
||||
*/
|
||||
it('should add new the current repo', function() {
|
||||
// expect(jobScope.result_sets.length).toBe(10);
|
||||
it('should have id of 1 in foreground (current) repo', function() {
|
||||
expect(model.getResultSetsArray(rootScope.repoName)[0].id).toBe(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new jobs gets those job updates on a cached repo (not current)
|
||||
*/
|
||||
|
||||
it('should add new to a cached repo', function() {
|
||||
// expect(jobScope.result_sets.length).toBe(10);
|
||||
it('should have id of 10 in background repo', function() {
|
||||
expect(model.getResultSetsArray(backgroundRepo)[0].id).toBe(10);
|
||||
});
|
||||
|
||||
|
||||
var getResultSets = function() {
|
||||
return [
|
||||
{
|
||||
"repository_id": 4,
|
||||
"job_counts": {
|
||||
"exception": 0,
|
||||
"retry": 0,
|
||||
"success": 2,
|
||||
"unknown": 0,
|
||||
"usercancel": 0,
|
||||
"running": 0,
|
||||
"busted": 0,
|
||||
"testfailed": 0,
|
||||
"total": 4,
|
||||
"pending": 0
|
||||
},
|
||||
"revision_hash": "05c298c5ae3bcc37fd00397511646135bf2416f6",
|
||||
"revision_count": 2,
|
||||
"author": "Brian Grinstead <test@mozilla.com>",
|
||||
"platforms": [
|
||||
{
|
||||
"name": "linux64",
|
||||
"groups": [
|
||||
{
|
||||
"symbol": "?",
|
||||
"jobs": [
|
||||
{
|
||||
"machine_name": "bld-centos6-hp-031",
|
||||
"job_group_symbol": "?",
|
||||
"job_type_name": "Build",
|
||||
"job_group_name": "unknown",
|
||||
"platform_option": "debug",
|
||||
"reason": "scheduler",
|
||||
"failure_classification_id": 1,
|
||||
"job_type_symbol": "B",
|
||||
"platform": "linux64",
|
||||
"state": "pending",
|
||||
"result_set_id": 4939,
|
||||
"result": "unknown",
|
||||
"job_coalesced_to_guid": null,
|
||||
"id": 590604,
|
||||
"resource_uri": "/api/project/try/jobs/590604/"
|
||||
},
|
||||
{
|
||||
"machine_name": "try-linux64-spot-129",
|
||||
"job_group_symbol": "?",
|
||||
"job_type_name": "Static Checking Build",
|
||||
"job_group_name": "unknown",
|
||||
"platform_option": "debug",
|
||||
"reason": "scheduler",
|
||||
"failure_classification_id": 1,
|
||||
"job_type_symbol": "S",
|
||||
"platform": "linux64",
|
||||
"state": "completed",
|
||||
"result_set_id": 4939,
|
||||
"result": "success",
|
||||
"job_coalesced_to_guid": null,
|
||||
"id": 590599,
|
||||
"resource_uri": "/api/project/try/jobs/590599/"
|
||||
}
|
||||
],
|
||||
"name": "unknown"
|
||||
}
|
||||
],
|
||||
"option": "debug"
|
||||
}
|
||||
],
|
||||
"revisions_uri": "/api/project/try/resultset/4939/revisions/",
|
||||
"push_timestamp": 1396899074,
|
||||
"id": 4939,
|
||||
"revision": "793611be6b26"
|
||||
}
|
||||
];
|
||||
var newSocketEvent = function(repoName, data) {
|
||||
model.processSocketData(repoName, data);
|
||||
model.processUpdateQueues(repoName);
|
||||
$httpBackend.flush();
|
||||
};
|
||||
|
||||
var getNewJobs = function() {
|
||||
/**
|
||||
* Test that events for new resultsets gets those job updates on the foreground repo
|
||||
*/
|
||||
it('should add new rs to the foreground repo', function() {
|
||||
var rsValues = {id: 2, push_timestamp: 1396899074+1},
|
||||
data = {branch: foregroundRepo, resultset: rsValues};
|
||||
|
||||
$httpBackend.whenGET(foregroundPrefix + '/resultset/?count=1&format=json&full=false&id__in=2&offset=0').respond(
|
||||
getResultSet(2, rsValues)
|
||||
);
|
||||
|
||||
newSocketEvent(foregroundRepo, data);
|
||||
|
||||
var resultsets = model.getResultSetsArray(foregroundRepo);
|
||||
expect(model.getResultSetsArray(backgroundRepo).length).toBe(1);
|
||||
expect(resultsets.length).toBe(2);
|
||||
expect(_.pluck(resultsets, "id")).toEqual([2, 1]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new resultsets gets those job updates on a cached repo (not foreground)
|
||||
*/
|
||||
it('should add new rs to a background repo', function() {
|
||||
var rsValues = {id: 12, push_timestamp: 1396899074+1},
|
||||
data = {branch: backgroundRepo, resultset: rsValues};
|
||||
|
||||
$httpBackend.whenGET(backgroundPrefix + '/resultset/?count=1&format=json&full=false&id__in=12&offset=0').respond(
|
||||
getResultSet(12, rsValues)
|
||||
);
|
||||
|
||||
newSocketEvent(backgroundRepo, data);
|
||||
|
||||
var resultsets = model.getResultSetsArray(backgroundRepo);
|
||||
expect(model.getResultSetsArray(foregroundRepo).length).toBe(1);
|
||||
expect(resultsets.length).toBe(2);
|
||||
expect(_.pluck(resultsets, "id")).toEqual([12, 10]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new job in existing resultset gets those job updates on the foreground repo
|
||||
*/
|
||||
it('should add new job to the foreground repo', function() {
|
||||
var data = {
|
||||
branch: foregroundRepo,
|
||||
id: 123,
|
||||
resultset: {id: 1, push_timestamp: 1396899074}
|
||||
};
|
||||
|
||||
$httpBackend.whenGET(foregroundPrefix + '/jobs/?id__in=123').respond(
|
||||
getJob(123, {result_set_id: 1})
|
||||
);
|
||||
|
||||
newSocketEvent(foregroundRepo, data);
|
||||
|
||||
var jobs = model.getResultSetsArray(foregroundRepo)[0].platforms[0].groups[0].jobs;
|
||||
expect(jobs.length).toBe(3);
|
||||
expect(_.pluck(jobs, "id")).toEqual([590604, 590599, 123]);
|
||||
expect(_.pluck(jobs, "state")).toEqual(["pending", "completed", "completed"]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new job in existing resultset gets those job updates on the foreground repo
|
||||
*/
|
||||
it('should update an existing job in the foreground repo to its new status', function() {
|
||||
var data = {
|
||||
branch: foregroundRepo,
|
||||
id: 590604,
|
||||
resultset: {id: 1, push_timestamp: 1396899074}
|
||||
};
|
||||
|
||||
$httpBackend.whenGET(foregroundPrefix + '/jobs/?id__in=590604').respond(
|
||||
getJob(590604, {result_set_id: 1})
|
||||
);
|
||||
|
||||
newSocketEvent(foregroundRepo, data);
|
||||
|
||||
var jobs = model.getResultSetsArray(foregroundRepo)[0].platforms[0].groups[0].jobs;
|
||||
expect(jobs.length).toBe(2);
|
||||
expect(_.pluck(jobs, "id")).toEqual([590604, 590599]);
|
||||
expect(_.pluck(jobs, "state")).toEqual(["completed", "completed"]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new job in existing resultset gets those job updates on the background repo
|
||||
*/
|
||||
it('should add new job to the background repo', function() {
|
||||
var data = {
|
||||
branch: backgroundRepo,
|
||||
id: 123,
|
||||
resultset: {id: 10, push_timestamp: 1396899074}
|
||||
};
|
||||
|
||||
$httpBackend.whenGET(backgroundPrefix + '/jobs/?id__in=123').respond(
|
||||
getJob(123, {result_set_id: 10})
|
||||
);
|
||||
|
||||
newSocketEvent(backgroundRepo, data);
|
||||
|
||||
var jobs = model.getResultSetsArray(backgroundRepo)[0].platforms[0].groups[0].jobs;
|
||||
expect(jobs.length).toBe(3);
|
||||
expect(_.pluck(jobs, "id")).toEqual([590604, 590599, 123]);
|
||||
expect(_.pluck(jobs, "state")).toEqual(["pending", "completed", "completed"]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that events for new job in existing resultset gets those job updates on the background repo
|
||||
*/
|
||||
it('should update an existing job in the background repo to its new status', function() {
|
||||
var data = {
|
||||
branch: backgroundRepo,
|
||||
id: 590604,
|
||||
resultset: {id: 10, push_timestamp: 1396899074}
|
||||
};
|
||||
|
||||
$httpBackend.whenGET(backgroundPrefix + '/jobs/?id__in=590604').respond(
|
||||
getJob(590604, {result_set_id: 10})
|
||||
);
|
||||
|
||||
newSocketEvent(backgroundRepo, data);
|
||||
|
||||
var jobs = model.getResultSetsArray(backgroundRepo)[0].platforms[0].groups[0].jobs;
|
||||
expect(jobs.length).toBe(2);
|
||||
expect(_.pluck(jobs, "id")).toEqual([590604, 590599]);
|
||||
expect(_.pluck(jobs, "state")).toEqual(["completed", "completed"]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
/********************************************
|
||||
* Data constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return a single length array of one resultset. Replace fields with
|
||||
* those contained in ``values``
|
||||
* @param values
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var getResultSet = function(id, values) {
|
||||
values = values || {};
|
||||
|
||||
var rs = {
|
||||
"repository_id": 4,
|
||||
"job_counts": {
|
||||
"exception": 0,
|
||||
"retry": 0,
|
||||
"success": 2,
|
||||
"unknown": 0,
|
||||
"usercancel": 0,
|
||||
"running": 0,
|
||||
"busted": 0,
|
||||
"testfailed": 0,
|
||||
"total": 4,
|
||||
"pending": 0
|
||||
},
|
||||
"revision_hash": "05c298c5ae3bcc37fd00397511646135bf2416f6",
|
||||
"revision_count": 2,
|
||||
"author": "Brian Grinstead <test@mozilla.com>",
|
||||
"platforms": [
|
||||
{
|
||||
"name": "linux64",
|
||||
"groups": [
|
||||
{
|
||||
"symbol": "?",
|
||||
"jobs": [
|
||||
{
|
||||
"machine_name": "bld-centos6-hp-031",
|
||||
"job_group_symbol": "?",
|
||||
"job_type_name": "Build",
|
||||
"job_group_name": "unknown",
|
||||
"platform_option": "debug",
|
||||
"reason": "scheduler",
|
||||
"failure_classification_id": 1,
|
||||
"job_type_symbol": "B",
|
||||
"platform": "linux64",
|
||||
"state": "pending",
|
||||
"result_set_id": id,
|
||||
"result": "unknown",
|
||||
"job_coalesced_to_guid": null,
|
||||
"id": 590604,
|
||||
"resource_uri": "/api/project/try/jobs/590604/"
|
||||
},
|
||||
{
|
||||
"machine_name": "try-linux64-spot-129",
|
||||
"job_group_symbol": "?",
|
||||
"job_type_name": "Static Checking Build",
|
||||
"job_group_name": "unknown",
|
||||
"platform_option": "debug",
|
||||
"reason": "scheduler",
|
||||
"failure_classification_id": 1,
|
||||
"job_type_symbol": "S",
|
||||
"platform": "linux64",
|
||||
"state": "completed",
|
||||
"result_set_id": id,
|
||||
"result": "success",
|
||||
"job_coalesced_to_guid": null,
|
||||
"id": 590599,
|
||||
"resource_uri": "/api/project/try/jobs/590599/"
|
||||
}
|
||||
],
|
||||
"name": "unknown"
|
||||
}
|
||||
],
|
||||
"option": "debug"
|
||||
}
|
||||
],
|
||||
"revisions_uri": "/api/project/try/resultset/4939/revisions/",
|
||||
push_timestamp: 1396899074,
|
||||
id: id,
|
||||
"revision": "793611be6b26"
|
||||
};
|
||||
_.extend(rs, values);
|
||||
return [rs];
|
||||
};
|
||||
|
||||
var getJob = function(id, values) {
|
||||
values = values || {};
|
||||
|
||||
var job = {
|
||||
"submit_timestamp": 1396899126,
|
||||
"machine_name": "bld-centos6-hp-031",
|
||||
"job_group_symbol": "?",
|
||||
"job_group_name": "unknown",
|
||||
"platform_option": "debug",
|
||||
"job_type_description": "fill me",
|
||||
"result_set_id": 4939,
|
||||
"result": "success",
|
||||
"id": id,
|
||||
"machine_platform_architecture": "x86_64",
|
||||
"end_timestamp": 1396901922,
|
||||
"build_platform": "linux64",
|
||||
"job_guid": "1cb281fce9b62d27423dfbe31d50a9744f4fc0d6",
|
||||
"job_type_name": "Build",
|
||||
"platform": "linux64",
|
||||
"state": "completed",
|
||||
"build_os": "linux",
|
||||
"option_collection_hash": "32faaecac742100f7753f0c1d0aa0add01b4046b",
|
||||
"who": "bgrinstead@mozilla.com",
|
||||
"failure_classification_id": 1,
|
||||
"job_type_symbol": "B",
|
||||
"reason": "scheduler",
|
||||
"job_group_description": "fill me",
|
||||
"job_coalesced_to_guid": null,
|
||||
"machine_platform_os": "linux",
|
||||
"start_timestamp": 1396899181,
|
||||
"build_architecture": "x86_64",
|
||||
"build_platform_id": 10,
|
||||
"machine_id": 346,
|
||||
"resource_uri": "/api/project/try/jobs/590604/"
|
||||
};
|
||||
|
||||
_.extend(job, values);
|
||||
return [job];
|
||||
|
||||
return [
|
||||
{
|
||||
"submit_timestamp": 1396899126,
|
||||
"machine_name": "bld-centos6-hp-031",
|
||||
"job_group_symbol": "?",
|
||||
"job_group_name": "unknown",
|
||||
"platform_option": "debug",
|
||||
"job_type_description": "fill me",
|
||||
"result_set_id": 4939,
|
||||
"result": "success",
|
||||
"id": 590604,
|
||||
"machine_platform_architecture": "x86_64",
|
||||
"end_timestamp": 1396901922,
|
||||
"build_platform": "linux64",
|
||||
"job_guid": "1cb281fce9b62d27423dfbe31d50a9744f4fc0d6",
|
||||
"job_type_name": "Build",
|
||||
"platform": "linux64",
|
||||
"state": "completed",
|
||||
"build_os": "linux",
|
||||
"option_collection_hash": "32faaecac742100f7753f0c1d0aa0add01b4046b",
|
||||
"who": "bgrinstead@mozilla.com",
|
||||
"failure_classification_id": 1,
|
||||
"job_type_symbol": "B",
|
||||
"reason": "scheduler",
|
||||
"job_group_description": "fill me",
|
||||
"job_coalesced_to_guid": null,
|
||||
"machine_platform_os": "linux",
|
||||
"start_timestamp": 1396899181,
|
||||
"build_architecture": "x86_64",
|
||||
"build_platform_id": 10,
|
||||
"machine_id": 346,
|
||||
"resource_uri": "/api/project/try/jobs/590604/"
|
||||
}
|
||||
];
|
||||
};
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ treeherder.controller('JobsCtrl',
|
|||
|
||||
if(ThResultSetModel.isNotLoaded($scope.repoName)){
|
||||
// get our first set of resultsets
|
||||
$scope.fetchResultSets($scope.repoName, 10);
|
||||
ThResultSetModel.fetchResultSets($scope.repoName, 10);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ treeherder.factory('ThJobModel', function($http, ThLog, thUrl) {
|
|||
ThJobModel.get_list = function(repoName, options) {
|
||||
// a static method to retrieve a list of ThJobModel
|
||||
var query_string = $.param(options);
|
||||
return $http.get(ThJobModel.get_uri()+"?"+query_string)
|
||||
return $http.get(ThJobModel.get_uri(repoName)+"?"+query_string)
|
||||
.then(function(response) {
|
||||
var item_list = [];
|
||||
angular.forEach(response.data, function(elem){
|
||||
|
|
|
@ -234,7 +234,7 @@ treeherder.factory('ThResultSetModel',
|
|||
*/
|
||||
var getOrCreatePlatform = function(repoName, newJob) {
|
||||
var rsMapElement = repositories[repoName].rsMap[newJob.result_set_id];
|
||||
var platformKey = getPlatformKey(newJob.platform, newJob.option);
|
||||
var platformKey = getPlatformKey(newJob.platform, newJob.platform_option);
|
||||
var plMapElement = rsMapElement.platforms[platformKey];
|
||||
if (!plMapElement) {
|
||||
// this platform wasn't in the resultset, so add it.
|
||||
|
@ -486,7 +486,6 @@ treeherder.factory('ThResultSetModel',
|
|||
// add the job to the datamodel
|
||||
grpMapElement.grp_obj.jobs.push(newJob);
|
||||
|
||||
|
||||
// add job to the jobmap
|
||||
repositories[repoName].jobMap[key] = {
|
||||
job_obj: newJob,
|
||||
|
@ -505,7 +504,7 @@ treeherder.factory('ThResultSetModel',
|
|||
|
||||
var added = [];
|
||||
for (var i = data.length - 1; i > -1; i--) {
|
||||
if (data[i].push_timestamp > repositories[repoName].rsMapOldestTimestamp) {
|
||||
if (data[i].push_timestamp >= repositories[repoName].rsMapOldestTimestamp) {
|
||||
$log.debug("prepending resultset: ", data[i].id);
|
||||
repositories[repoName].resultSets.push(data[i]);
|
||||
added.push(data[i]);
|
||||
|
@ -629,7 +628,11 @@ treeherder.factory('ThResultSetModel',
|
|||
|
||||
fetchJobs: fetchJobs,
|
||||
|
||||
aggregateJobPlatform: aggregateJobPlatform
|
||||
aggregateJobPlatform: aggregateJobPlatform,
|
||||
|
||||
processSocketData: processSocketData,
|
||||
|
||||
processUpdateQueues: processUpdateQueues
|
||||
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче