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

Commit d996aa92 by Ruben Bridgewater

Fix racy tests

1 parent 1f17bece
'use strict'; 'use strict';
var Support = require('../support');
before(function() { var Support = require('../support')
var dialect = Support.getTestDialect(); , dialect = Support.getTestDialect();
if (dialect !== 'postgres' && dialect !== 'postgres-native') {
return;
}
return Support.sequelize.query('CREATE EXTENSION IF NOT EXISTS hstore', {raw: true});
});
before(function() { before(function() {
var dialect = Support.getTestDialect();
if (dialect !== 'postgres' && dialect !== 'postgres-native') { if (dialect !== 'postgres' && dialect !== 'postgres-native') {
return; return;
} }
return Support.sequelize.query('CREATE EXTENSION IF NOT EXISTS btree_gist', {raw: true}); return Support.sequelize.Promise.all([
Support.sequelize.query('CREATE EXTENSION IF NOT EXISTS hstore', {raw: true}),
Support.sequelize.query('CREATE EXTENSION IF NOT EXISTS btree_gist', {raw: true})
]);
}); });
beforeEach(function() { beforeEach(function() {
......
...@@ -33,7 +33,7 @@ if (dialect !== 'sqlite') { ...@@ -33,7 +33,7 @@ if (dialect !== 'sqlite') {
this.sequelize.query(query, { type: this.sequelize.QueryTypes.SELECT }), this.sequelize.query(query, { type: this.sequelize.QueryTypes.SELECT }),
this.sequelizeWithTimezone.query(query, { type: this.sequelize.QueryTypes.SELECT }) this.sequelizeWithTimezone.query(query, { type: this.sequelize.QueryTypes.SELECT })
]).spread(function(now1, now2) { ]).spread(function(now1, now2) {
var elapsedQueryTime = (Date.now() - startQueryTime) + 20; var elapsedQueryTime = (Date.now() - startQueryTime) + 1001;
expect(now1[0].now.getTime()).to.be.closeTo(now2[0].now.getTime(), elapsedQueryTime); expect(now1[0].now.getTime()).to.be.closeTo(now2[0].now.getTime(), elapsedQueryTime);
}); });
}); });
......
...@@ -13,7 +13,7 @@ var chai = require('chai') ...@@ -13,7 +13,7 @@ var chai = require('chai')
if (current.dialect.supports.transactions) { if (current.dialect.supports.transactions) {
describe(Support.getTestDialectTeaser('Transaction'), function() { describe(Support.getTestDialectTeaser('Transaction'), function() {
this.timeout(4000); this.timeout(5000);
describe('constructor', function() { describe('constructor', function() {
it('stores options', function() { it('stores options', function() {
var transaction = new Transaction(this.sequelize); var transaction = new Transaction(this.sequelize);
...@@ -90,9 +90,18 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -90,9 +90,18 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
}); });
} }
, self = this; , self = this;
// Attention: this test is a bit racy. If you find a nicer way to test this: go ahead
return SumSumSum.sync({force: true}).then(function () { return SumSumSum.sync({force: true}).then(function () {
return (expect(Promise.join(transTest(80), transTest(80))).to.eventually.be.rejectedWith('could not serialize access due to read/write dependencies among transactions')); return (expect(Promise.join(transTest(80), transTest(80), transTest(80))).to.eventually.be.rejectedWith('could not serialize access due to read/write dependencies among transactions'));
}).delay(100).then(function() {
if (self.sequelize.test.$runningQueries !== 0) {
return self.sequelize.Promise.delay(200);
}
return void 0;
}).then(function() {
if (self.sequelize.test.$runningQueries !== 0) {
return self.sequelize.Promise.delay(500);
}
}); });
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!