diff --git a/test/db/concurrent.js b/test/db/concurrent.js index 4c2376f..475b001 100644 --- a/test/db/concurrent.js +++ b/test/db/concurrent.js @@ -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); + }); }); });