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