mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-04 10:20:13 +00:00
fix before put concurrency - should fix builds loss
This commit is contained in:
parent
001469509f
commit
66bab3949e
21
db.js
21
db.js
@ -198,22 +198,23 @@ nlevel.DocsSection.prototype._beforePut = function(docs, callback) {
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
Steppy(
|
|
||||||
function() {
|
|
||||||
if (self._beforePutInProgress) {
|
if (self._beforePutInProgress) {
|
||||||
return setTimeout(function() {
|
setTimeout(function() {
|
||||||
nlevel.DocsSection.prototype._beforePut.call(
|
nlevel.DocsSection.prototype._beforePut.call(
|
||||||
self, docs, callback
|
self, docs, callback
|
||||||
);
|
);
|
||||||
}, 5);
|
}, 1);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
self._beforePutInProgress = true;
|
self._beforePutInProgress = true;
|
||||||
|
|
||||||
self.beforePut(docs, this.slot());
|
// update createDate before put to provide latest date for last id
|
||||||
},
|
// it's rquired for correct generateIds function
|
||||||
callback
|
_(docs).each(function(doc) {
|
||||||
);
|
doc.createDate = Date.now();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.beforePut(docs, callback);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
nlevel.DocsSection.prototype._afterPut = function(docs, callback) {
|
nlevel.DocsSection.prototype._afterPut = function(docs, callback) {
|
||||||
|
@ -19,13 +19,28 @@ describe('Db concurrency', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
db = helpers.initDb(done);
|
Steppy(
|
||||||
|
function() {
|
||||||
|
db = helpers.initDb(this.slot());
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
db.builds.find({}, this.slot());
|
||||||
|
},
|
||||||
|
function(err, builds) {
|
||||||
|
if (builds.length) {
|
||||||
|
db.builds.del(builds, this.slot());
|
||||||
|
} else {
|
||||||
|
this.pass(null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
done
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('prallel builds put should produce different ids', function() {
|
describe('prallel builds put should produce different ids', function() {
|
||||||
|
|
||||||
var expectedIds = [];
|
var expectedIds = [];
|
||||||
var builds = _(2).chain().range().map(function(number) {
|
var builds = _(100).chain().range().map(function(number) {
|
||||||
expectedIds.push(number + 1);
|
expectedIds.push(number + 1);
|
||||||
return makeBuild({project: {name: 'project' + number}});
|
return makeBuild({project: {name: 'project' + number}});
|
||||||
}).value();
|
}).value();
|
||||||
@ -42,7 +57,7 @@ describe('Db concurrency', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shoud have ids ' + expectedIds.join(', '), function() {
|
it('shoud have all ' + expectedIds.length +' ids ', function() {
|
||||||
expect(_(builds).chain().pluck('id').sortBy().value()).eql(
|
expect(_(builds).chain().pluck('id').sortBy().value()).eql(
|
||||||
expectedIds
|
expectedIds
|
||||||
);
|
);
|
||||||
@ -56,7 +71,7 @@ describe('Db concurrency', function() {
|
|||||||
describe('prallel builds put should produce different numbers', function() {
|
describe('prallel builds put should produce different numbers', function() {
|
||||||
|
|
||||||
var expectedIds = [];
|
var expectedIds = [];
|
||||||
var builds = _(3).chain().range().map(function(number) {
|
var builds = _(100).chain().range().map(function(number) {
|
||||||
expectedIds.push(number + 1);
|
expectedIds.push(number + 1);
|
||||||
return makeBuild({
|
return makeBuild({
|
||||||
project: {name: 'project1'},
|
project: {name: 'project1'},
|
||||||
@ -76,7 +91,7 @@ describe('Db concurrency', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shoud have ids ' + expectedIds.join(', '), function() {
|
it('shoud have all ' + expectedIds.length +' ids ', function() {
|
||||||
expect(_(builds).chain().pluck('id').sortBy().value()).eql(
|
expect(_(builds).chain().pluck('id').sortBy().value()).eql(
|
||||||
expectedIds
|
expectedIds
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user