mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-14 20:39:17 +00:00
safe id and build numbers generation
This commit is contained in:
parent
cec79bdc75
commit
dc51811eda
@ -18,7 +18,7 @@ work in progress...
|
|||||||
* ~~Rename notification strategies according to statuses~~
|
* ~~Rename notification strategies according to statuses~~
|
||||||
* Work with git
|
* Work with git
|
||||||
* ~~Build every commit, commit with tag, etc~~
|
* ~~Build every commit, commit with tag, etc~~
|
||||||
* Safe id and build numbers generation
|
* ~~Safe id and build numbers generation~~
|
||||||
* Scheduler
|
* Scheduler
|
||||||
* ~~Better tests coverage~~
|
* ~~Better tests coverage~~
|
||||||
* Semantic versioning and plugins
|
* Semantic versioning and plugins
|
||||||
|
10
db.js
10
db.js
@ -32,6 +32,14 @@ exports.init = function(dbPath, params, callback) {
|
|||||||
|
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
|
if (self._beforePutInProgress) {
|
||||||
|
return setTimeout(function() {
|
||||||
|
exports.builds._beforePut.call(self, builds, callback);
|
||||||
|
}, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
self._beforePutInProgress = true;
|
||||||
|
|
||||||
if (builds.length > 1) {
|
if (builds.length > 1) {
|
||||||
throw new Error('Build put hooks work only with single build');
|
throw new Error('Build put hooks work only with single build');
|
||||||
}
|
}
|
||||||
@ -60,6 +68,8 @@ exports.init = function(dbPath, params, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.pass(null);
|
this.pass(null);
|
||||||
|
|
||||||
|
self._beforePutInProgress = false;
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,79 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var expect = require('expect.js'),
|
||||||
|
helpers = require('../helpers'),
|
||||||
|
Steppy = require('twostep').Steppy,
|
||||||
|
_ = require('underscore');
|
||||||
|
|
||||||
describe('Db concurrency', function() {
|
describe('Db concurrency', function() {
|
||||||
|
|
||||||
|
var db;
|
||||||
|
|
||||||
|
var madeBuildIndex = 0;
|
||||||
|
var makeBuild = function(build) {
|
||||||
|
return _({
|
||||||
|
// to increase build numbers
|
||||||
|
createDate: Date.now() + madeBuildIndex++,
|
||||||
|
project: _({}).extend(build && build.project)
|
||||||
|
}).extend(build);
|
||||||
|
};
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
|
db = helpers.initDb(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('prallel builds put should produce different ids', function() {
|
||||||
|
|
||||||
|
var firstBuild = makeBuild({project: {name: 'project1'}}),
|
||||||
|
secondBuild = makeBuild({project: {name: 'project2'}});
|
||||||
|
|
||||||
|
it('put two builds in parallel without errors', function(done) {
|
||||||
|
Steppy(
|
||||||
|
function() {
|
||||||
|
db.builds.put(firstBuild, this.slot());
|
||||||
|
db.builds.put(secondBuild, this.slot());
|
||||||
|
},
|
||||||
|
done
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('first build should have id 1', function() {
|
||||||
|
expect(firstBuild.id).equal(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('secondBuild build should have id 2', function() {
|
||||||
|
expect(secondBuild.id).equal(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('prallel builds put should produce different numbers', function() {
|
||||||
|
|
||||||
|
var builds = _(3).chain().range().map(function() {
|
||||||
|
return makeBuild({
|
||||||
|
project: {name: 'project1'},
|
||||||
|
status: 'in-progress'
|
||||||
|
});
|
||||||
|
}).value();
|
||||||
|
|
||||||
|
it('put three builds in parallel without errors', function(done) {
|
||||||
|
Steppy(
|
||||||
|
function() {
|
||||||
|
var step = this;
|
||||||
|
_(builds).each(function(build) {
|
||||||
|
db.builds.put(build, step.slot());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
done
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(builds).each(function(build, index) {
|
||||||
|
var number = (index + 1);
|
||||||
|
it('build ' + number + ' should have number ' + number, function() {
|
||||||
|
expect(build.number).equal(number);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var SpawnCommand = require('../lib/command/spawn').Command,
|
var SpawnCommand = require('../lib/command/spawn').Command,
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
db = require('../db');
|
||||||
|
|
||||||
|
|
||||||
exports.removeDir = function(dir, callback) {
|
exports.removeDir = function(dir, callback) {
|
||||||
@ -42,3 +43,11 @@ exports.mercurialRevs = [{
|
|||||||
date: new Date('Sun Jun 28 10:54:22 2015 +0300').getTime(),
|
date: new Date('Sun Jun 28 10:54:22 2015 +0300').getTime(),
|
||||||
comment: 'add tags'
|
comment: 'add tags'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
exports.initDb = function(callback) {
|
||||||
|
db.init('path/to/db/ignored/for/memdown', {
|
||||||
|
db: require('memdown'),
|
||||||
|
valueEncoding: 'json'
|
||||||
|
}, callback);
|
||||||
|
return db;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user