fix id generation on builds update - new hope to fix builds loss

This commit is contained in:
oleg 2015-12-15 23:26:59 +03:00
parent 28b2b15d66
commit 151228b404
2 changed files with 43 additions and 4 deletions

2
db.js
View File

@ -210,7 +210,9 @@ nlevel.DocsSection.prototype._beforePut = function(docs, callback) {
// update createDate before put to provide latest date for last id
// it's rquired for correct generateIds function
_(docs).each(function(doc) {
if (!doc.id) {
doc.createDate = Date.now();
}
});
self.beforePut(docs, callback);

View File

@ -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 builds = _(100).chain().range().map(function(number) {
@ -45,7 +45,7 @@ describe('Db concurrency', function() {
return makeBuild({project: {name: 'project' + number}});
}).value();
it('put two builds in parallel without errors', function(done) {
it('put builds in parallel without errors', function(done) {
Steppy(
function() {
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() {
var expectedIds = [];
@ -79,7 +116,7 @@ describe('Db concurrency', function() {
});
}).value();
it('put three builds in parallel without errors', function(done) {
it('put builds in parallel without errors', function(done) {
Steppy(
function() {
var putGroup = this.makeGroup();