mirror of
https://github.com/knex/knex.git
synced 2025-12-27 23:18:41 +00:00
* Fix for concurrent child transactions failing (#2213) * Skip new sibling transaction test for mssql * Update test to ensure Promise resolve order
This commit is contained in:
parent
eb8f0c0b2d
commit
5417cacdb1
@ -210,6 +210,7 @@ class Transaction extends EventEmitter {
|
||||
// the original promise is marked completed.
|
||||
acquireConnection(client, config, txid) {
|
||||
const configConnection = config && config.connection;
|
||||
const trx = this;
|
||||
return new Bluebird((resolve, reject) => {
|
||||
try {
|
||||
resolve(configConnection || client.acquireConnection());
|
||||
@ -220,7 +221,10 @@ class Transaction extends EventEmitter {
|
||||
.then(function(connection) {
|
||||
connection.__knexTxId = txid;
|
||||
|
||||
return connection;
|
||||
return (trx._previousSibling ? trx._previousSibling.reflect() : Promise.resolve())
|
||||
.then(function () {
|
||||
return connection;
|
||||
});
|
||||
})
|
||||
.disposer(function(connection) {
|
||||
if (!configConnection) {
|
||||
|
||||
@ -399,6 +399,27 @@ module.exports = function(knex) {
|
||||
});
|
||||
});
|
||||
|
||||
it('#2213 - should wait for sibling transactions to finish', function() {
|
||||
if (/redshift/i.test(knex.client.driverName)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (/mssql/i.test(knex.client.driverName)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const first = Bluebird.delay(50);
|
||||
const second = first.then(() => Bluebird.delay(50));
|
||||
return knex.transaction(function(trx) {
|
||||
return Promise.all([
|
||||
trx.transaction(function(trx2) {
|
||||
return first;
|
||||
}),
|
||||
trx.transaction(function(trx3) {
|
||||
return second;
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('#855 - Query Event should trigger on Transaction Client AND main Client', function() {
|
||||
let queryEventTriggered = false;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user