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

Commit 5e794684 by Jan Aagaard Meier

Slight rewrite of cls tests

1 parent 7e06e0c9
Showing with 23 additions and 7 deletions
...@@ -7,20 +7,22 @@ var chai = require('chai') ...@@ -7,20 +7,22 @@ var chai = require('chai')
, Support = require(__dirname + '/support') , Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize , Sequelize = Support.Sequelize
, Promise = Sequelize.Promise , Promise = Sequelize.Promise
, cls = require('continuation-local-storage'); , cls = require('continuation-local-storage')
, current = Support.sequelize;
chai.config.includeStack = true; chai.config.includeStack = true;
describe(Support.getTestDialectTeaser("Continuation local storage"), function () { describe(Support.getTestDialectTeaser("Continuation local storage"), function () {
before(function () { before(function () {
return Support.prepareTransactionTest(Support.createSequelizeInstance({ this.sequelize = Support.createSequelizeInstance({
namespace: cls.createNamespace('sequelize') namespace: cls.createNamespace('sequelize')
})).bind(this).then(function (sequelize) {
this.sequelize = sequelize;
}); });
}); });
beforeEach(function () { beforeEach(function () {
return Support.prepareTransactionTest(this.sequelize).bind(this).then(function (sequelize) {
this.sequelize = sequelize;
this.ns = cls.getNamespace('sequelize'); this.ns = cls.getNamespace('sequelize');
this.User = this.sequelize.define('user', { this.User = this.sequelize.define('user', {
...@@ -28,6 +30,7 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function () ...@@ -28,6 +30,7 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function ()
}); });
return this.sequelize.sync({ force: true }); return this.sequelize.sync({ force: true });
}); });
});
var autoCallback = function autoCallback(sequelize, cb) { var autoCallback = function autoCallback(sequelize, cb) {
return sequelize.transaction(cb); return sequelize.transaction(cb);
...@@ -40,6 +43,7 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function () ...@@ -40,6 +43,7 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function ()
}); });
}; };
if (current.dialect.supports.transactions) {
[autoCallback, thenCallback].forEach(function (cb) { [autoCallback, thenCallback].forEach(function (cb) {
describe(cb.name, function () { describe(cb.name, function () {
describe('context', function () { describe('context', function () {
...@@ -58,6 +62,8 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function () ...@@ -58,6 +62,8 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function ()
return Promise.resolve(); return Promise.resolve();
}), }),
function () { function () {
expect(t1id).to.be.ok;
expect(t2id).to.be.ok;
expect(t1id).not.to.equal(t2id); expect(t1id).not.to.equal(t2id);
} }
); );
...@@ -93,12 +99,21 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function () ...@@ -93,12 +99,21 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function ()
}); });
}); });
// Wait for 400 ms - should be enough time to get everything set up return new Promise(function (resolve) {
return Promise.delay(400).bind(this).then(function () { // Wait for the transaction to be setup
expect(transactionSetup).to.be.ok; var interval = setInterval(function () {
if (transactionSetup) {
clearInterval(interval);
resolve();
}
}, 200);
}).bind(this).then(function () {
expect(transactionEnded).not.to.be.ok; expect(transactionEnded).not.to.be.ok;
expect(this.ns.get('transaction')).not.to.be.ok; expect(this.ns.get('transaction')).not.to.be.ok;
// Just to make sure it didn't change between our last check and the assertion
expect(transactionEnded).not.to.be.ok;
}); });
}); });
...@@ -126,4 +141,5 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function () ...@@ -126,4 +141,5 @@ describe(Support.getTestDialectTeaser("Continuation local storage"), function ()
}); });
}); });
}); });
}
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!