Skip to content

Commit b618133

Browse files
committed
Add test for bulk transactions
1 parent 3d520e0 commit b618133

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/postgresql.transaction.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,41 @@ describe('transactions', function() {
5858
};
5959
}
6060

61+
describe('bulk', function() {
62+
it('should work with bulk transactions', function(done) {
63+
var completed = 0;
64+
var concurrent = 20;
65+
for (var i = 0; i <= concurrent; i++) {
66+
var post = {title: 'tb' + i, content: 'cb' + i};
67+
var create = createPostInTx(post);
68+
Transaction.begin(db.connector, Transaction.SERIALIZABLE,
69+
function(err, tx) {
70+
if (err) return done(err);
71+
Post.create(post, {transaction: tx},
72+
function(err, p) {
73+
if (err) {
74+
done(err);
75+
} else {
76+
tx.commit(function(err) {
77+
if (err) {
78+
done(err);
79+
}
80+
completed++;
81+
checkResults();
82+
});
83+
}
84+
});
85+
});
86+
}
87+
88+
function checkResults() {
89+
if (completed === concurrent) {
90+
done();
91+
}
92+
}
93+
});
94+
});
95+
6196
describe('commit', function() {
6297
var post = {title: 't1', content: 'c1'};
6398
before(createPostInTx(post));

0 commit comments

Comments
 (0)