update db concurrent test

This commit is contained in:
oleg 2015-12-11 14:13:22 +03:00
parent 486d2006c0
commit 001469509f

View File

@ -24,28 +24,40 @@ describe('Db concurrency', function() {
describe('prallel builds put should produce different ids', function() {
var firstBuild = makeBuild({project: {name: 'project1'}}),
secondBuild = makeBuild({project: {name: 'project2'}});
var expectedIds = [];
var builds = _(2).chain().range().map(function(number) {
expectedIds.push(number + 1);
return makeBuild({project: {name: 'project' + number}});
}).value();
it('put two builds in parallel without errors', function(done) {
Steppy(
function() {
db.builds.put(firstBuild, this.slot());
db.builds.put(secondBuild, this.slot());
var putGroup = this.makeGroup();
_(builds).each(function(build) {
db.builds.put(build, putGroup.slot());
});
},
done
);
});
it('shoud have ids 1, 2', function() {
expect(_([firstBuild.id, secondBuild.id]).sortBy()).eql([1, 2]);
it('shoud have ids ' + expectedIds.join(', '), 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 builds = _(3).chain().range().map(function() {
var expectedIds = [];
var builds = _(3).chain().range().map(function(number) {
expectedIds.push(number + 1);
return makeBuild({
project: {name: 'project1'},
status: 'in-progress'
@ -55,20 +67,23 @@ describe('Db concurrency', function() {
it('put three builds in parallel without errors', function(done) {
Steppy(
function() {
var step = this;
var putGroup = this.makeGroup();
_(builds).each(function(build) {
db.builds.put(build, step.slot());
db.builds.put(build, putGroup.slot());
});
},
done
);
});
it('shoud have ids 3, 4, 5', function() {
it('shoud have ids ' + expectedIds.join(', '), function() {
expect(_(builds).chain().pluck('id').sortBy().value()).eql(
[3, 4, 5]
expectedIds
);
});
after(function(done) {
db.builds.del(expectedIds, done);
});
});
});