mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-10 22:05:07 +00:00
fix id generation on builds update - new hope to fix builds loss
This commit is contained in:
parent
28b2b15d66
commit
151228b404
4
db.js
4
db.js
@ -210,7 +210,9 @@ nlevel.DocsSection.prototype._beforePut = function(docs, callback) {
|
|||||||
// update createDate before put to provide latest date for last id
|
// update createDate before put to provide latest date for last id
|
||||||
// it's rquired for correct generateIds function
|
// it's rquired for correct generateIds function
|
||||||
_(docs).each(function(doc) {
|
_(docs).each(function(doc) {
|
||||||
doc.createDate = Date.now();
|
if (!doc.id) {
|
||||||
|
doc.createDate = Date.now();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.beforePut(docs, callback);
|
self.beforePut(docs, callback);
|
||||||
|
@ -37,7 +37,7 @@ describe('Db concurrency', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('prallel builds put should produce different ids', function() {
|
describe('prallel builds add should produce different ids', function() {
|
||||||
|
|
||||||
var expectedIds = [];
|
var expectedIds = [];
|
||||||
var builds = _(100).chain().range().map(function(number) {
|
var builds = _(100).chain().range().map(function(number) {
|
||||||
@ -45,7 +45,7 @@ describe('Db concurrency', function() {
|
|||||||
return makeBuild({project: {name: 'project' + number}});
|
return makeBuild({project: {name: 'project' + number}});
|
||||||
}).value();
|
}).value();
|
||||||
|
|
||||||
it('put two builds in parallel without errors', function(done) {
|
it('put builds in parallel without errors', function(done) {
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
var putGroup = this.makeGroup();
|
var putGroup = this.makeGroup();
|
||||||
@ -68,6 +68,43 @@ describe('Db concurrency', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('prallel builds add/update should produce different ids', function() {
|
||||||
|
|
||||||
|
var expectedIds = [];
|
||||||
|
var builds = _(200).chain().range().map(function(number) {
|
||||||
|
expectedIds.push(number + 1);
|
||||||
|
return makeBuild({project: {name: 'project' + number}});
|
||||||
|
}).value();
|
||||||
|
|
||||||
|
it('put builds in parallel without errors', function(done) {
|
||||||
|
Steppy(
|
||||||
|
function() {
|
||||||
|
var putGroup = this.makeGroup();
|
||||||
|
_(builds.slice(0, 190)).each(function(build) {
|
||||||
|
db.builds.put(build, putGroup.slot());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
var putGroup = this.makeGroup();
|
||||||
|
_(builds).each(function(build) {
|
||||||
|
db.builds.put(build, putGroup.slot());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
done
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shoud have all ' + expectedIds.length +' ids ', function() {
|
||||||
|
expect(_(builds).chain().pluck('id').sortBy().value()).eql(
|
||||||
|
expectedIds
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
db.builds.del(expectedIds, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('prallel builds put should produce different numbers', function() {
|
describe('prallel builds put should produce different numbers', function() {
|
||||||
|
|
||||||
var expectedIds = [];
|
var expectedIds = [];
|
||||||
@ -79,7 +116,7 @@ describe('Db concurrency', function() {
|
|||||||
});
|
});
|
||||||
}).value();
|
}).value();
|
||||||
|
|
||||||
it('put three builds in parallel without errors', function(done) {
|
it('put builds in parallel without errors', function(done) {
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
var putGroup = this.makeGroup();
|
var putGroup = this.makeGroup();
|
||||||
|
Loading…
Reference in New Issue
Block a user