不要怂,就是干,撸起袖子干!

Commit cf5b2f54 by Andy Edwards Committed by GitHub

refactor: replace misc bluebird API usage (#12072)

1 parent 869fdae8
...@@ -8,6 +8,7 @@ const DataTypes = require('../../data-types').mysql; ...@@ -8,6 +8,7 @@ const DataTypes = require('../../data-types').mysql;
const momentTz = require('moment-timezone'); const momentTz = require('moment-timezone');
const debug = logger.debugContext('connection:mysql'); const debug = logger.debugContext('connection:mysql');
const parserStore = require('../parserStore')('mysql'); const parserStore = require('../parserStore')('mysql');
const { promisify } = require('util');
/** /**
* MySQL Connection Manager * MySQL Connection Manager
...@@ -144,7 +145,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -144,7 +145,7 @@ class ConnectionManager extends AbstractConnectionManager {
return Promise.resolve(); return Promise.resolve();
} }
return Promise.fromCallback(callback => connection.end(callback)); return promisify(callback => connection.end(callback))();
} }
validate(connection) { validate(connection) {
......
...@@ -9,6 +9,7 @@ const sequelizeErrors = require('../../errors'); ...@@ -9,6 +9,7 @@ const sequelizeErrors = require('../../errors');
const semver = require('semver'); const semver = require('semver');
const dataTypes = require('../../data-types'); const dataTypes = require('../../data-types');
const moment = require('moment-timezone'); const moment = require('moment-timezone');
const { promisify } = require('util');
class ConnectionManager extends AbstractConnectionManager { class ConnectionManager extends AbstractConnectionManager {
constructor(dialect, sequelize) { constructor(dialect, sequelize) {
...@@ -244,7 +245,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -244,7 +245,7 @@ class ConnectionManager extends AbstractConnectionManager {
return Promise.resolve(); return Promise.resolve();
} }
return Promise.fromCallback(callback => connection.end(callback)); return promisify(callback => connection.end(callback))();
} }
validate(connection) { validate(connection) {
......
...@@ -9,6 +9,7 @@ const debug = logger.debugContext('connection:sqlite'); ...@@ -9,6 +9,7 @@ const debug = logger.debugContext('connection:sqlite');
const dataTypes = require('../../data-types').sqlite; const dataTypes = require('../../data-types').sqlite;
const sequelizeErrors = require('../../errors'); const sequelizeErrors = require('../../errors');
const parserStore = require('../parserStore')('sqlite'); const parserStore = require('../parserStore')('sqlite');
const { promisify } = require('util');
class ConnectionManager extends AbstractConnectionManager { class ConnectionManager extends AbstractConnectionManager {
constructor(dialect, sequelize) { constructor(dialect, sequelize) {
...@@ -27,7 +28,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -27,7 +28,7 @@ class ConnectionManager extends AbstractConnectionManager {
_onProcessExit() { _onProcessExit() {
const promises = Object.getOwnPropertyNames(this.connections) const promises = Object.getOwnPropertyNames(this.connections)
.map(connection => Promise.fromCallback(callback => this.connections[connection].close(callback))); .map(connection => promisify(callback => this.connections[connection].close(callback))());
return Promise return Promise
.all(promises) .all(promises)
......
...@@ -7,6 +7,7 @@ const Promise = require('./promise'); ...@@ -7,6 +7,7 @@ const Promise = require('./promise');
const DataTypes = require('./data-types'); const DataTypes = require('./data-types');
const BelongsTo = require('./associations/belongs-to'); const BelongsTo = require('./associations/belongs-to');
const validator = require('./utils/validator-extras').validator; const validator = require('./utils/validator-extras').validator;
const { promisify } = require('util');
/** /**
* Instance Validator. * Instance Validator.
...@@ -259,9 +260,9 @@ class InstanceValidator { ...@@ -259,9 +260,9 @@ class InstanceValidator {
if (isAsync) { if (isAsync) {
if (optAttrDefined) { if (optAttrDefined) {
validatorFunction = Promise.promisify(validator.bind(this.modelInstance, invokeArgs)); validatorFunction = promisify(validator.bind(this.modelInstance, invokeArgs));
} else { } else {
validatorFunction = Promise.promisify(validator.bind(this.modelInstance)); validatorFunction = promisify(validator.bind(this.modelInstance));
} }
return validatorFunction() return validatorFunction()
.catch(e => this._pushError(false, errorKey, e, optValue, validatorType)); .catch(e => this._pushError(false, errorKey, e, optValue, validatorType));
......
...@@ -1113,7 +1113,7 @@ class Sequelize { ...@@ -1113,7 +1113,7 @@ class Sequelize {
// and reject with original error (ignore any error in rollback) // and reject with original error (ignore any error in rollback)
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
if (!transaction.finished) return transaction.rollback().catch(() => {}); if (!transaction.finished) return transaction.rollback().catch(() => {});
}).throw(err); }).then(() => { throw err; });
}); });
}); });
} }
......
This diff could not be displayed because it is too large.
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
"chai-spies": "^1.x", "chai-spies": "^1.x",
"cls-hooked": "^4.2.2", "cls-hooked": "^4.2.2",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"delay": "^4.3.0",
"dtslint": "^2.0.5", "dtslint": "^2.0.5",
"env-cmd": "^10.1.0", "env-cmd": "^10.1.0",
"esdoc": "^1.1.0", "esdoc": "^1.1.0",
...@@ -79,6 +80,8 @@ ...@@ -79,6 +80,8 @@
"mysql2": "^1.6.5", "mysql2": "^1.6.5",
"nyc": "^15.0.0", "nyc": "^15.0.0",
"p-map": "^4.0.0", "p-map": "^4.0.0",
"p-props": "^3.1.0",
"p-timeout": "^3.2.0",
"pg": "^7.8.1", "pg": "^7.8.1",
"pg-hstore": "^2.x", "pg-hstore": "^2.x",
"pg-types": "^2.0.0", "pg-types": "^2.0.0",
......
...@@ -6,7 +6,8 @@ const chai = require('chai'), ...@@ -6,7 +6,8 @@ const chai = require('chai'),
Sequelize = Support.Sequelize, Sequelize = Support.Sequelize,
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
cls = require('cls-hooked'), cls = require('cls-hooked'),
current = Support.sequelize; current = Support.sequelize,
delay = require('delay');
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
describe(Support.getTestDialectTeaser('CLS (Async hooks)'), () => { describe(Support.getTestDialectTeaser('CLS (Async hooks)'), () => {
...@@ -73,7 +74,7 @@ if (current.dialect.supports.transactions) { ...@@ -73,7 +74,7 @@ if (current.dialect.supports.transactions) {
this.sequelize.transaction(() => { this.sequelize.transaction(() => {
transactionSetup = true; transactionSetup = true;
return Promise.delay(500).then(() => { return delay(500).then(() => {
expect(this.ns.get('transaction')).to.be.ok; expect(this.ns.get('transaction')).to.be.ok;
transactionEnded = true; transactionEnded = true;
}); });
......
...@@ -7,7 +7,8 @@ const chai = require('chai'), ...@@ -7,7 +7,8 @@ const chai = require('chai'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
Sequelize = Support.Sequelize, Sequelize = Support.Sequelize,
fs = require('fs'), fs = require('fs'),
path = require('path'); path = require('path'),
{ promisify } = require('util');
let sqlite3; let sqlite3;
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
...@@ -74,11 +75,11 @@ describe(Support.getTestDialectTeaser('Configuration'), () => { ...@@ -74,11 +75,11 @@ describe(Support.getTestDialectTeaser('Configuration'), () => {
const createTableFoo = 'CREATE TABLE foo (faz TEXT);'; const createTableFoo = 'CREATE TABLE foo (faz TEXT);';
const createTableBar = 'CREATE TABLE bar (baz TEXT);'; const createTableBar = 'CREATE TABLE bar (baz TEXT);';
const testAccess = Sequelize.Promise.method(() => { const testAccess = () => {
return Sequelize.Promise.promisify(fs.access)(p, fs.R_OK | fs.W_OK); return promisify(fs.access)(p, fs.R_OK | fs.W_OK);
}); };
return Sequelize.Promise.promisify(fs.unlink)(p) return promisify(fs.unlink)(p)
.catch(err => { .catch(err => {
expect(err.code).to.equal('ENOENT'); expect(err.code).to.equal('ENOENT');
}) })
...@@ -135,7 +136,7 @@ describe(Support.getTestDialectTeaser('Configuration'), () => { ...@@ -135,7 +136,7 @@ describe(Support.getTestDialectTeaser('Configuration'), () => {
); );
}) })
.finally(() => { .finally(() => {
return Sequelize.Promise.promisify(fs.unlink)(p); return promisify(fs.unlink)(p);
}); });
}); });
} }
......
...@@ -8,7 +8,8 @@ const chai = require('chai'), ...@@ -8,7 +8,8 @@ const chai = require('chai'),
DataTypes = require('../../lib/data-types'), DataTypes = require('../../lib/data-types'),
_ = require('lodash'), _ = require('lodash'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
current = Support.sequelize; current = Support.sequelize,
promiseProps = require('p-props');
const sortById = function(a, b) { const sortById = function(a, b) {
return a.id < b.id ? -1 : 1; return a.id < b.id ? -1 : 1;
...@@ -265,7 +266,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -265,7 +266,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.belongsTo(Group); User.belongsTo(Group);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
task: Task.create(), task: Task.create(),
user: User.create(), user: User.create(),
group: Group.create() group: Group.create()
......
...@@ -7,7 +7,8 @@ const chai = require('chai'), ...@@ -7,7 +7,8 @@ const chai = require('chai'),
expect = chai.expect, expect = chai.expect,
Support = require('../support'), Support = require('../support'),
DataTypes = require('../../../lib/data-types'), DataTypes = require('../../../lib/data-types'),
_ = require('lodash'); _ = require('lodash'),
promiseProps = require('p-props');
const sortById = function(a, b) { const sortById = function(a, b) {
return a.id < b.id ? -1 : 1; return a.id < b.id ? -1 : 1;
...@@ -631,7 +632,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -631,7 +632,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.belongsTo(Order); User.belongsTo(Order);
return this.sequelize.sync().then(() => { return this.sequelize.sync().then(() => {
return Promise.props({ return promiseProps({
users: User.bulkCreate([{}, {}, {}]).then(() => { users: User.bulkCreate([{}, {}, {}]).then(() => {
return User.findAll(); return User.findAll();
}), }),
...@@ -712,7 +713,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -712,7 +713,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Tag.belongsToMany(Product, { through: ProductTag }); Tag.belongsToMany(Product, { through: ProductTag });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
products: Product.bulkCreate([ products: Product.bulkCreate([
{ title: 'Chair' }, { title: 'Chair' },
{ title: 'Desk' }, { title: 'Desk' },
...@@ -766,7 +767,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -766,7 +767,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.belongsTo(Group); User.belongsTo(Group);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([{}, {}]).then(() => { groups: Group.bulkCreate([{}, {}]).then(() => {
return Group.findAll(); return Group.findAll();
}), }),
...@@ -797,7 +798,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -797,7 +798,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.belongsTo(Group); User.belongsTo(Group);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
...@@ -835,7 +836,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -835,7 +836,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.belongsTo(Group); User.belongsTo(Group);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
...@@ -916,7 +917,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -916,7 +917,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Group.hasMany(Category); Group.hasMany(Category);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
...@@ -969,7 +970,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -969,7 +970,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Group.hasMany(Category, { as: 'Tags' }); Group.hasMany(Category, { as: 'Tags' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
...@@ -1022,7 +1023,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1022,7 +1023,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Group.hasMany(Category); Group.hasMany(Category);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
...@@ -1071,7 +1072,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1071,7 +1072,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.hasOne(Project, { as: 'LeaderOf' }); User.hasOne(Project, { as: 'LeaderOf' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
projects: Project.bulkCreate([ projects: Project.bulkCreate([
{ title: 'Alpha' }, { title: 'Alpha' },
{ title: 'Beta' } { title: 'Beta' }
...@@ -1115,7 +1116,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1115,7 +1116,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
Tag.belongsToMany(Product, { through: ProductTag }); Tag.belongsToMany(Product, { through: ProductTag });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
products: Product.bulkCreate([ products: Product.bulkCreate([
{ title: 'Chair' }, { title: 'Chair' },
{ title: 'Desk' }, { title: 'Desk' },
...@@ -1285,7 +1286,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -1285,7 +1286,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
User.belongsTo(Group); User.belongsTo(Group);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
......
...@@ -8,7 +8,8 @@ const chai = require('chai'), ...@@ -8,7 +8,8 @@ const chai = require('chai'),
DataTypes = require('../../../lib/data-types'), DataTypes = require('../../../lib/data-types'),
Promise = Sequelize.Promise, Promise = Sequelize.Promise,
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
_ = require('lodash'); _ = require('lodash'),
promiseProps = require('p-props');
const sortById = function(a, b) { const sortById = function(a, b) {
return a.id < b.id ? -1 : 1; return a.id < b.id ? -1 : 1;
...@@ -1002,7 +1003,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ...@@ -1002,7 +1003,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => {
User.belongsTo(Group); User.belongsTo(Group);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Promise.props({ return promiseProps({
groups: Group.bulkCreate([ groups: Group.bulkCreate([
{ name: 'A' }, { name: 'A' },
{ name: 'B' } { name: 'B' }
......
...@@ -11,7 +11,8 @@ const chai = require('chai'), ...@@ -11,7 +11,8 @@ const chai = require('chai'),
Op = Sequelize.Op, Op = Sequelize.Op,
_ = require('lodash'), _ = require('lodash'),
assert = require('assert'), assert = require('assert'),
current = Support.sequelize; current = Support.sequelize,
pTimeout = require('p-timeout');
describe(Support.getTestDialectTeaser('Model'), () => { describe(Support.getTestDialectTeaser('Model'), () => {
beforeEach(function() { beforeEach(function() {
...@@ -411,19 +412,15 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -411,19 +412,15 @@ describe(Support.getTestDialectTeaser('Model'), () => {
if (times > 10) { if (times > 10) {
return true; return true;
} }
return this.Student.findOrCreate({ return pTimeout(this.Student.findOrCreate({
where: { where: {
no: 1 no: 1
} }
}) }), 1000)
.timeout(1000)
.catch(e => { .catch(e => {
if (!(e instanceof Promise.TimeoutError)) throw e; if (e instanceof Sequelize.ValidationError) return test(times + 1);
throw new Error(e); if (e instanceof pTimeout.TimeoutError) throw new Error(e);
}) throw e;
.catch(err => {
if (!(err instanceof Sequelize.ValidationError)) throw err;
return test(times + 1);
}); });
}; };
......
...@@ -11,7 +11,8 @@ const chai = require('chai'), ...@@ -11,7 +11,8 @@ const chai = require('chai'),
config = require('../../config/config'), config = require('../../config/config'),
_ = require('lodash'), _ = require('lodash'),
moment = require('moment'), moment = require('moment'),
current = Support.sequelize; current = Support.sequelize,
promiseProps = require('p-props');
describe(Support.getTestDialectTeaser('Model'), () => { describe(Support.getTestDialectTeaser('Model'), () => {
beforeEach(function() { beforeEach(function() {
...@@ -953,7 +954,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -953,7 +954,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Person.belongsTo(this.Country, { as: 'CountryResident', foreignKey: 'CountryResidentId' }); this.Person.belongsTo(this.Country, { as: 'CountryResident', foreignKey: 'CountryResidentId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Sequelize.Promise.props({ return promiseProps({
europe: this.Continent.create({ name: 'Europe' }), europe: this.Continent.create({ name: 'Europe' }),
england: this.Country.create({ name: 'England' }), england: this.Country.create({ name: 'England' }),
coal: this.Industry.create({ name: 'Coal' }), coal: this.Industry.create({ name: 'Coal' }),
...@@ -1138,7 +1139,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1138,7 +1139,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Person.belongsTo(this.Country, { as: 'CountryResident', foreignKey: 'CountryResidentId' }); this.Person.belongsTo(this.Country, { as: 'CountryResident', foreignKey: 'CountryResidentId' });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Sequelize.Promise.props({ return promiseProps({
europe: this.Continent.create({ name: 'Europe' }), europe: this.Continent.create({ name: 'Europe' }),
asia: this.Continent.create({ name: 'Asia' }), asia: this.Continent.create({ name: 'Asia' }),
england: this.Country.create({ name: 'England' }), england: this.Country.create({ name: 'England' }),
...@@ -1297,7 +1298,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1297,7 +1298,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.Industry.belongsToMany(this.Country, { through: this.IndustryCountry }); this.Industry.belongsToMany(this.Country, { through: this.IndustryCountry });
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Sequelize.Promise.props({ return promiseProps({
england: this.Country.create({ name: 'England' }), england: this.Country.create({ name: 'England' }),
france: this.Country.create({ name: 'France' }), france: this.Country.create({ name: 'France' }),
korea: this.Country.create({ name: 'Korea' }), korea: this.Country.create({ name: 'Korea' }),
......
...@@ -6,6 +6,7 @@ const Support = require('./support'); ...@@ -6,6 +6,7 @@ const Support = require('./support');
const dialect = Support.getTestDialect(); const dialect = Support.getTestDialect();
const sinon = require('sinon'); const sinon = require('sinon');
const Sequelize = Support.Sequelize; const Sequelize = Support.Sequelize;
const delay = require('delay');
function assertSameConnection(newConnection, oldConnection) { function assertSameConnection(newConnection, oldConnection) {
switch (dialect) { switch (dialect) {
...@@ -143,7 +144,7 @@ describe(Support.getTestDialectTeaser('Pooling'), () => { ...@@ -143,7 +144,7 @@ describe(Support.getTestDialectTeaser('Pooling'), () => {
await cm.releaseConnection(firstConnection); await cm.releaseConnection(firstConnection);
// Wait a little and then get next available connection // Wait a little and then get next available connection
await Sequelize.Promise.delay(90); await delay(90);
const secondConnection = await cm.getConnection(); const secondConnection = await cm.getConnection();
assertSameConnection(secondConnection, firstConnection); assertSameConnection(secondConnection, firstConnection);
...@@ -168,7 +169,7 @@ describe(Support.getTestDialectTeaser('Pooling'), () => { ...@@ -168,7 +169,7 @@ describe(Support.getTestDialectTeaser('Pooling'), () => {
await cm.releaseConnection(firstConnection); await cm.releaseConnection(firstConnection);
// Wait a little and then get next available connection // Wait a little and then get next available connection
await Sequelize.Promise.delay(110); await delay(110);
const secondConnection = await cm.getConnection(); const secondConnection = await cm.getConnection();
......
...@@ -5,7 +5,8 @@ const chai = require('chai'), ...@@ -5,7 +5,8 @@ const chai = require('chai'),
Support = require('./support'), Support = require('./support'),
Promise = require('../../lib/promise'), Promise = require('../../lib/promise'),
Transaction = require('../../lib/transaction'), Transaction = require('../../lib/transaction'),
current = Support.sequelize; current = Support.sequelize,
delay = require('delay');
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
...@@ -101,7 +102,7 @@ if (current.dialect.supports.transactions) { ...@@ -101,7 +102,7 @@ if (current.dialect.supports.transactions) {
return Test return Test
.create({ name: 'Peter' }, { transaction }) .create({ name: 'Peter' }, { transaction })
.then(() => { .then(() => {
return Promise.delay(1000).then(() => { return delay(1000).then(() => {
return transaction return transaction
.commit() .commit()
.then(() => { return Test.count(); }) .then(() => { return Test.count(); })
...@@ -141,7 +142,7 @@ if (current.dialect.supports.transactions) { ...@@ -141,7 +142,7 @@ if (current.dialect.supports.transactions) {
expect(err).to.be.ok; expect(err).to.be.ok;
return t2.rollback(); return t2.rollback();
}), }),
Promise.delay(100).then(() => { delay(100).then(() => {
return t1.commit(); return t1.commit();
}) })
]); ]);
......
...@@ -9,7 +9,8 @@ const chai = require('chai'), ...@@ -9,7 +9,8 @@ const chai = require('chai'),
QueryTypes = require('../../lib/query-types'), QueryTypes = require('../../lib/query-types'),
Transaction = require('../../lib/transaction'), Transaction = require('../../lib/transaction'),
sinon = require('sinon'), sinon = require('sinon'),
current = Support.sequelize; current = Support.sequelize,
delay = require('delay');
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
...@@ -393,7 +394,7 @@ if (current.dialect.supports.transactions) { ...@@ -393,7 +394,7 @@ if (current.dialect.supports.transactions) {
lock: 'UPDATE', lock: 'UPDATE',
transaction transaction
}) })
.then(() => Promise.delay(10)) .then(() => delay(10))
.then(() => { .then(() => {
return Task.update({ id: to }, { return Task.update({ id: to }, {
where: { where: {
...@@ -513,7 +514,7 @@ if (current.dialect.supports.transactions) { ...@@ -513,7 +514,7 @@ if (current.dialect.supports.transactions) {
const newTransactionFunc = function() { const newTransactionFunc = function() {
return sequelize.transaction({ type: Support.Sequelize.Transaction.TYPES.EXCLUSIVE, retry: { match: ['NO_MATCH'] } }).then(t => { return sequelize.transaction({ type: Support.Sequelize.Transaction.TYPES.EXCLUSIVE, retry: { match: ['NO_MATCH'] } }).then(t => {
// introduce delay to force the busy state race condition to fail // introduce delay to force the busy state race condition to fail
return Promise.delay(1000).then(() => { return delay(1000).then(() => {
return User.create({ id: null, username: `test ${t.id}` }, { transaction: t }).then(() => { return User.create({ id: null, username: `test ${t.id}` }, { transaction: t }).then(() => {
return t.commit(); return t.commit();
}); });
...@@ -586,7 +587,7 @@ if (current.dialect.supports.transactions) { ...@@ -586,7 +587,7 @@ if (current.dialect.supports.transactions) {
username: 'jan' username: 'jan'
} }
}).then(() => expect(transactionSpy).to.have.been.called ), // Update should not succeed before transaction has committed }).then(() => expect(transactionSpy).to.have.been.called ), // Update should not succeed before transaction has committed
Promise.delay(2000) delay(2000)
.then(() => transaction.commit()) .then(() => transaction.commit())
.then(transactionSpy) .then(transactionSpy)
)); ));
...@@ -642,7 +643,7 @@ if (current.dialect.supports.transactions) { ...@@ -642,7 +643,7 @@ if (current.dialect.supports.transactions) {
transaction: t1 transaction: t1
}).then(() => { }).then(() => {
t1Spy(); t1Spy();
return Promise.delay(2000).then(() => { return delay(2000).then(() => {
return t1.commit(); return t1.commit();
}); });
}) })
...@@ -827,7 +828,7 @@ if (current.dialect.supports.transactions) { ...@@ -827,7 +828,7 @@ if (current.dialect.supports.transactions) {
}, { }, {
transaction: t1 transaction: t1
}).then(() => { }).then(() => {
return Promise.delay(2000).then(() => { return delay(2000).then(() => {
t1Spy(); t1Spy();
expect(t1Spy).to.have.been.calledAfter(t2Spy); expect(t1Spy).to.have.been.calledAfter(t2Spy);
return t1.commit(); return t1.commit();
...@@ -890,7 +891,7 @@ if (current.dialect.supports.transactions) { ...@@ -890,7 +891,7 @@ if (current.dialect.supports.transactions) {
}, { }, {
transaction: t1 transaction: t1
}).then(() => { }).then(() => {
return Promise.delay(2000).then(() => { return delay(2000).then(() => {
t1Spy(); t1Spy();
return t1.commit(); return t1.commit();
}); });
......
...@@ -4,7 +4,8 @@ const ResourceLock = require('../../../../lib/dialects/mssql/resource-lock'), ...@@ -4,7 +4,8 @@ const ResourceLock = require('../../../../lib/dialects/mssql/resource-lock'),
Promise = require('../../../../lib/promise'), Promise = require('../../../../lib/promise'),
assert = require('assert'), assert = require('assert'),
Support = require('../../support'), Support = require('../../support'),
dialect = Support.getTestDialect(); dialect = Support.getTestDialect(),
delay = require('delay');
if (dialect === 'mssql') { if (dialect === 'mssql') {
describe('[MSSQL Specific] ResourceLock', () => { describe('[MSSQL Specific] ResourceLock', () => {
...@@ -23,7 +24,7 @@ if (dialect === 'mssql') { ...@@ -23,7 +24,7 @@ if (dialect === 'mssql') {
assert.equal(last, 0); assert.equal(last, 0);
last = 1; last = 1;
return Promise.delay(15); return delay(15);
}), }),
Promise.using(lock.lock(), resource => { Promise.using(lock.lock(), resource => {
validateResource(resource); validateResource(resource);
...@@ -35,7 +36,7 @@ if (dialect === 'mssql') { ...@@ -35,7 +36,7 @@ if (dialect === 'mssql') {
assert.equal(last, 2); assert.equal(last, 2);
last = 3; last = 3;
return Promise.delay(5); return delay(5);
}) })
]); ]);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!